Merge pull request #165 from alex-laycalvert/main

Added Toggling Todos in Visual Range
This commit is contained in:
lambtho
2022-09-28 15:01:51 +00:00
committed by GitHub
4 changed files with 41 additions and 21 deletions

View File

@@ -661,6 +661,10 @@ The plugin defines the following functions:
- this function accepts a parameter `{i}`. If `true`, it will enter input mode by pressing the 'A' key. This is - this function accepts a parameter `{i}`. If `true`, it will enter input mode by pressing the 'A' key. This is
useful when being used in a simple `inoremap` key mapping like shown in [Bind it](#3-bind-it). useful when being used in a simple `inoremap` key mapping like shown in [Bind it](#3-bind-it).
- example: `toggle_todo({ i=true })` - example: `toggle_todo({ i=true })`
- this function can also be used in `visual` mode to toggle the status of multiple lines.
- if using a keymapping to `toggle_todo` in visual mode, make sure to use `:Telekasten toggle_todo<CR>`
instead of `<cmd>Telekasten toggle_todo<CR>` to avoid neovim sending the wrong visual selection to
telekasten.
- `show_backlinks()` : opens a telescope search for notes that `[[link]]` back to the current note. - `show_backlinks()` : opens a telescope search for notes that `[[link]]` back to the current note.
- `find_friends()` : opens a telescope search for notes that also `[[link]]` to the link under the cursor. - `find_friends()` : opens a telescope search for notes that also `[[link]]` to the link under the cursor.
- `insert_img_link()` : opens a telescope search for all media (PDFs, images, videos (MP4, webm)) and places a markdown - `insert_img_link()` : opens a telescope search for all media (PDFs, images, videos (MP4, webm)) and places a markdown

View File

@@ -649,6 +649,11 @@ telekasten.toggle_todo({opts})~
Turns a line into a `- [ ] ` todo line, or toggle between `- [ ]`, `- [x]`, Turns a line into a `- [ ] ` todo line, or toggle between `- [ ]`, `- [x]`,
and `-` . and `-` .
This can also be used in visual mode to toggle the status of multiple lines.
If using a keymapping to `toggle_todo` in visual mode, make sure the `rhs` is
`:Telekasten` `toggle_todo<CR>` instead of `<cmd>Telekasten` `toggle_todo<CR>`
to avoid neovim sending the wrong visual selection.
Valid keys for {opts} Valid keys for {opts}
i:~ i:~

View File

@@ -1533,8 +1533,7 @@ local function PreviewImg(opts)
preview_type = "media", preview_type = "media",
attach_mappings = function(prompt_bufnr, map) attach_mappings = function(prompt_bufnr, map)
actions.select_default:replace(function() actions.select_default:replace(function() actions.close(prompt_bufnr)
actions.close(prompt_bufnr)
end) end)
map("i", "<c-y>", picker_actions.yank_img_link(opts)) map("i", "<c-y>", picker_actions.yank_img_link(opts))
map("i", "<c-i>", picker_actions.paste_img_link(opts)) map("i", "<c-i>", picker_actions.paste_img_link(opts))
@@ -2710,28 +2709,40 @@ local function ToggleTodo(opts)
-- - [x] by - -- - [x] by -
-- enter insert mode if opts.i == true -- enter insert mode if opts.i == true
opts = opts or {} opts = opts or {}
local linenr = vim.api.nvim_win_get_cursor(0)[1] local startline = vim.api.nvim_buf_get_mark(0, "<")[1]
local curline = vim.api.nvim_buf_get_lines(0, linenr - 1, linenr, false)[1] local endline = vim.api.nvim_buf_get_mark(0, ">")[1]
local stripped = vim.trim(curline) local cursorlinenr = vim.api.nvim_win_get_cursor(0)[1]
local repline -- to avoid the visual range marks not being reset when calling
if -- command from normal mode
vim.startswith(stripped, "- ") and not vim.startswith(stripped, "- [") vim.api.nvim_buf_set_mark(0, "<", 0, 0, {})
then vim.api.nvim_buf_set_mark(0, ">", 0, 0, {})
repline = curline:gsub("%- ", "- [ ] ", 1) if startline <= 0 or endline <= 0 then
else startline = cursorlinenr
if vim.startswith(stripped, "- [ ]") then endline = cursorlinenr
repline = curline:gsub("%- %[ %]", "- [x]", 1) end
for curlinenr = startline, endline do
local curline = vim.api.nvim_buf_get_lines(0, curlinenr - 1, curlinenr, false)[1]
local stripped = vim.trim(curline)
local repline
if
vim.startswith(stripped, "- ") and not vim.startswith(stripped, "- [")
then
repline = curline:gsub("%- ", "- [ ] ", 1)
else else
if vim.startswith(stripped, "- [x]") then if vim.startswith(stripped, "- [ ]") then
repline = curline:gsub("%- %[x%]", "-", 1) repline = curline:gsub("%- %[ %]", "- [x]", 1)
else else
repline = curline:gsub("(%S)", "- [ ] %1", 1) if vim.startswith(stripped, "- [x]") then
repline = curline:gsub("%- %[x%]", "-", 1)
else
repline = curline:gsub("(%S)", "- [ ] %1", 1)
end
end end
end end
end vim.api.nvim_buf_set_lines(0, curlinenr - 1, curlinenr, false, { repline })
vim.api.nvim_buf_set_lines(0, linenr - 1, linenr, false, { repline }) if opts.i then
if opts.i then vim.api.nvim_feedkeys("A", "m", false)
vim.api.nvim_feedkeys("A", "m", false) end
end end
end end

View File

@@ -8,7 +8,7 @@ function! s:telekasten_complete(arg,line,pos)
return join(l:candidates, "\n") return join(l:candidates, "\n")
endfunction endfunction
command! -nargs=? -complete=custom,s:telekasten_complete Telekasten lua require('telekasten').panel(<f-args>) command! -nargs=? -range -complete=custom,s:telekasten_complete Telekasten lua require('telekasten').panel(<f-args>)
" overriding does not work -- so this is done by the plugin now in post_open() " overriding does not work -- so this is done by the plugin now in post_open()
" au BufNewFile,BufRead *.markdown,*.mdown,*.mkd,*.mkdn,*.mdwn,*.md setf telekasten " au BufNewFile,BufRead *.markdown,*.mdown,*.mkd,*.mkdn,*.mdwn,*.md setf telekasten