From 04deff857976fff8b39513f19b172f470c67486a Mon Sep 17 00:00:00 2001 From: Alexander Lay-Calvert <45835678+alex-laycalvert@users.noreply.github.com> Date: Wed, 23 Nov 2022 16:28:24 -0500 Subject: [PATCH] fix(toggle_todo): fixes wrong visual range for ToggleTodo (closes #187) * Added fix for visual toggle problems * Updated docs --- README.md | 6 +++--- doc/telekasten.txt | 4 ++++ lua/telekasten.lua | 3 ++- 3 files changed, 9 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index f7054bf..323d6e9 100644 --- a/README.md +++ b/README.md @@ -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 useful when being used in a simple `inoremap` key mapping like shown in [Bind it](#3-bind-it). - 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 `` to create the command as seen below: + - example keymapping: `:lua require('telekasten').toggle_todo({ v = true })` - this function has also a `{onlyTodo}` parameter. If `true`, this will avoid circling back to a regular list (`-`). - 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` - instead of `Telekasten toggle_todo` 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. - `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 diff --git a/doc/telekasten.txt b/doc/telekasten.txt index a87a462..06b24d5 100644 --- a/doc/telekasten.txt +++ b/doc/telekasten.txt @@ -677,6 +677,8 @@ telekasten.toggle_todo({opts})~ |telekasten.mappings|. Default: `nil` + v:~ + If `true`, it will look for a visual range to toggle. onlyTodo: If true, it will avoid circling back to a regular list - when toggle_todo @@ -1003,6 +1005,8 @@ However, here are some suggestions: nnoremap zC :CalendarT nnoremap zi :lua require('telekasten').paste_img_and_link() nnoremap zt :lua require('telekasten').toggle_todo() + " Toggling todos in visual mode + vnoremap zt :lua require('telekasten').toggle_todo({ v = true }) nnoremap zb :lua require('telekasten').show_backlinks() nnoremap zF :lua require('telekasten').find_friends() nnoremap zI :lua require('telekasten').insert_img_link({ i=true }) diff --git a/lua/telekasten.lua b/lua/telekasten.lua index 7bd3930..5dc1341 100644 --- a/lua/telekasten.lua +++ b/lua/telekasten.lua @@ -2723,6 +2723,7 @@ local function ToggleTodo(opts) -- - [ ] by - [x] -- - [x] by - -- enter insert mode if opts.i == true + -- if opts.v = true, then look for marks to toggle opts = opts or {} local startline = 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 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 endline = cursorlinenr end