clone of my dotfiles.ssp.sh
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

added toggle

sspaeti d67e31c8 3fb2b7eb

+28 -6
+28 -6
nvim/lua/sspaeti/plugins_custom/todo_float.lua
··· 3 3 4 4 local M = {} 5 5 6 + -- Track the current todo window 7 + local todo_win = nil 8 + 6 9 local function float_win_config() 7 - local width = math.min(math.floor(vim.o.columns * 0.8), 64) 10 + local width = math.min(math.floor(vim.o.columns * 0.9), 128) 8 11 local height = math.floor(vim.o.lines * 0.8) 9 12 10 13 return { ··· 17 20 } 18 21 end 19 22 20 - local function open_floating_file(filepath) 23 + local function toggle_floating_file(filepath) 24 + -- If window exists and is valid, close it 25 + if todo_win and vim.api.nvim_win_is_valid(todo_win) then 26 + vim.api.nvim_win_close(todo_win, true) 27 + todo_win = nil 28 + return 29 + end 30 + 21 31 local path = utils.expand_path(filepath) 22 32 23 33 -- Check if the file exists ··· 38 48 end) 39 49 end 40 50 41 - local win = vim.api.nvim_open_win(buf, true, float_win_config()) 51 + todo_win = vim.api.nvim_open_win(buf, true, float_win_config()) 42 52 vim.cmd("setlocal nospell") 43 53 44 54 vim.api.nvim_buf_set_keymap(buf, "n", "q", "", { ··· 50 60 vim.notify("Please save changes first", vim.log.levels.WARN) 51 61 else 52 62 vim.api.nvim_win_close(0, true) 63 + todo_win = nil 53 64 end 54 65 end, 55 66 }) 56 67 57 68 vim.api.nvim_create_autocmd("VimResized", { 58 69 callback = function() 59 - vim.api.nvim_win_set_config(win, float_win_config()) 70 + if todo_win and vim.api.nvim_win_is_valid(todo_win) then 71 + vim.api.nvim_win_set_config(todo_win, float_win_config()) 72 + end 60 73 end, 61 74 once = false, 62 75 }) 76 + 77 + -- Clear todo_win when window is closed 78 + vim.api.nvim_create_autocmd("WinClosed", { 79 + pattern = tostring(todo_win), 80 + callback = function() 81 + todo_win = nil 82 + end, 83 + once = true, 84 + }) 63 85 end 64 86 65 87 local function setup_user_commands(opts) ··· 72 94 opts.target_file = opts.global_file 73 95 end 74 96 vim.api.nvim_create_user_command("Td", function() 75 - open_floating_file(opts.target_file) 97 + toggle_floating_file(opts.target_file) 76 98 end, {}) 77 99 end 78 100 79 101 local function setup_keymaps() 80 - vim.keymap.set("n", "<leader>mt", ":Td<CR>", { desc = "open my todo file", silent = true }) 81 102 vim.keymap.set("n", "<leader>tt", ":Td<CR>", { desc = "open my todo file", silent = true }) 103 + vim.keymap.set("n", "<leader><leader>", ":Td<CR>", { desc = "open my todo file", silent = true }) 82 104 end 83 105 84 106 M.setup = function(opts)