fix(toggle_todo): fixes wrong visual range for ToggleTodo (closes #187)

* Added fix for visual toggle problems
* Updated docs
This commit is contained in:
Alexander Lay-Calvert
2022-11-23 16:28:24 -05:00
committed by GitHub
parent f4f836d4b4
commit 04deff8579
3 changed files with 9 additions and 4 deletions

View File

@@ -666,12 +666,12 @@ 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 also accepts `{v}` for visual mode. If `true`, then it will look for a visual range of text to
toggle. When setting this to a keymapping, use `:` instead of `<cr>` to create the command as seen below:
- example keymapping: `:lua require('telekasten').toggle_todo({ v = true })<cr>`
- this function has also a `{onlyTodo}` parameter. If `true`, this will - this function has also a `{onlyTodo}` parameter. If `true`, this will
avoid circling back to a regular list (`-`). avoid circling back to a regular list (`-`).
- this function can also be used in `visual` mode to toggle the status of multiple lines. - 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

@@ -677,6 +677,8 @@ telekasten.toggle_todo({opts})~
|telekasten.mappings|. |telekasten.mappings|.
Default: `nil` Default: `nil`
v:~
If `true`, it will look for a visual range to toggle.
onlyTodo: onlyTodo:
If true, it will avoid circling back to a regular list - when toggle_todo If true, it will avoid circling back to a regular list - when toggle_todo
@@ -1003,6 +1005,8 @@ However, here are some suggestions:
nnoremap <leader>zC :CalendarT<CR> nnoremap <leader>zC :CalendarT<CR>
nnoremap <leader>zi :lua require('telekasten').paste_img_and_link()<CR> nnoremap <leader>zi :lua require('telekasten').paste_img_and_link()<CR>
nnoremap <leader>zt :lua require('telekasten').toggle_todo()<CR> nnoremap <leader>zt :lua require('telekasten').toggle_todo()<CR>
" Toggling todos in visual mode
vnoremap <leader>zt :lua require('telekasten').toggle_todo({ v = true })<CR>
nnoremap <leader>zb :lua require('telekasten').show_backlinks()<CR> nnoremap <leader>zb :lua require('telekasten').show_backlinks()<CR>
nnoremap <leader>zF :lua require('telekasten').find_friends()<CR> nnoremap <leader>zF :lua require('telekasten').find_friends()<CR>
nnoremap <leader>zI :lua require('telekasten').insert_img_link({ i=true })<CR> nnoremap <leader>zI :lua require('telekasten').insert_img_link({ i=true })<CR>

View File

@@ -2723,6 +2723,7 @@ local function ToggleTodo(opts)
-- - [ ] by - [x] -- - [ ] by - [x]
-- - [x] by - -- - [x] by -
-- enter insert mode if opts.i == true -- enter insert mode if opts.i == true
-- if opts.v = true, then look for marks to toggle
opts = opts or {} opts = opts or {}
local startline = vim.api.nvim_buf_get_mark(0, "<")[1] local startline = vim.api.nvim_buf_get_mark(0, "<")[1]
local endline = vim.api.nvim_buf_get_mark(0, ">")[1] local endline = vim.api.nvim_buf_get_mark(0, ">")[1]
@@ -2731,7 +2732,7 @@ local function ToggleTodo(opts)
-- command from normal mode -- command from normal mode
vim.api.nvim_buf_set_mark(0, "<", 0, 0, {}) vim.api.nvim_buf_set_mark(0, "<", 0, 0, {})
vim.api.nvim_buf_set_mark(0, ">", 0, 0, {}) vim.api.nvim_buf_set_mark(0, ">", 0, 0, {})
if startline <= 0 or endline <= 0 then if startline <= 0 or endline <= 0 or opts.v ~= true then
startline = cursorlinenr startline = cursorlinenr
endline = cursorlinenr endline = cursorlinenr
end end