From 6e8471673a7158a8820986f6aad770a912a66eed Mon Sep 17 00:00:00 2001 From: Folke Lemaitre Date: Thu, 22 Jun 2023 10:57:16 +0200 Subject: [PATCH 01/18] fix(treesitter): always disable incremental mode for treesitter. Fixes #27 --- lua/flash/plugins/treesitter.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lua/flash/plugins/treesitter.lua b/lua/flash/plugins/treesitter.lua index 4da67fe..47389f0 100644 --- a/lua/flash/plugins/treesitter.lua +++ b/lua/flash/plugins/treesitter.lua @@ -73,7 +73,7 @@ function M.jump(opts) Config.get({ mode = "treesitter" }, opts, { matcher = M.matcher, labeler = function() end, - search = { multi_window = false, wrap = true }, + search = { multi_window = false, wrap = true, incremental = false }, }) ) From 97c3a993e60ebdd42c7671af07620f705ee6378f Mon Sep 17 00:00:00 2001 From: Folke Lemaitre Date: Thu, 22 Jun 2023 11:14:48 +0200 Subject: [PATCH 02/18] feat(char): tfTF now behave like clever-f when repeating the motion. Fixes #26 --- README.md | 10 +++++++--- lua/flash/plugins/char.lua | 8 ++++++-- 2 files changed, 13 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index 5502de6..b66b70e 100644 --- a/README.md +++ b/README.md @@ -216,9 +216,13 @@ Install the plugin with your preferred package manager: - use a jump label, or use `;` and `,` to increase/decrease the selection - **regular search**: search as you normally do, but enhanced with jump labels - `f`, `t`, `F`, `T` motions: - - go to next match with `;` or repeat the motion character like `f` - - go to previous match with `,` - - highlights clear automatically when moving, changing buffers or pressing `` + - After typing `f{char}` or `F{char},` you can repeat the motion with `f` + or go to the previous match with `F` to undo a jump. + - Similarly, after typing `t{char}` or `T{char},` you can repeat the motion + with `t` or go to the previous match with `T`. + - You can also go to the next match with `;` or previous match with `,` + - Any highlights clear automatically when moving, changing buffers, + or pressing ``. - `require("flash").jump(opts?)` opens **flash** with the given options - type any number of characters before typing a jump label diff --git a/lua/flash/plugins/char.lua b/lua/flash/plugins/char.lua index 897fce8..c9a3cc2 100644 --- a/lua/flash/plugins/char.lua +++ b/lua/flash/plugins/char.lua @@ -91,8 +91,12 @@ end function M.parse(key) -- repeat last search when hitting the same key - if M.visible() and M.motion == key then - key = ";" + if M.visible() then + if M.motion:lower() == key then + key = ";" + elseif M.motion:upper() == key then + key = "," + end end -- different motion, clear the state if M.motions[key] and M.motion ~= key then From ef472fcf80b2041fcd066c24e0553c65aa332571 Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" Date: Thu, 22 Jun 2023 09:16:08 +0000 Subject: [PATCH 03/18] chore(build): auto-generate vimdoc --- doc/flash.nvim.txt | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/doc/flash.nvim.txt b/doc/flash.nvim.txt index 59672af..069bc3c 100644 --- a/doc/flash.nvim.txt +++ b/doc/flash.nvim.txt @@ -208,9 +208,13 @@ USAGE *flash.nvim-flash.nvim-usage* - use a jump label, or use `;` and `,` to increase/decrease the selection - **regular search**search as you normally do, but enhanced with jump labels - `f`, `t`, `F`, `T` motions: - - go to next match with `;` or repeat the motion character like `f` - - go to previous match with `,` - - highlights clear automatically when moving, changing buffers or pressing `` + - After typing `f{char}` or `F{char},` you can repeat the motion with `f` + or go to the previous match with `F` to undo a jump. + - Similarly, after typing `t{char}` or `T{char},` you can repeat the motion + with `t` or go to the previous match with `T`. + - You can also go to the next match with `;` or previous match with `,` + - Any highlights clear automatically when moving, changing buffers, + or pressing ``. - `require("flash").jump(opts?)` opens **flash** with the given options - type any number of characters before typing a jump label From 29c35dec5f81504ee63a39fec90597222620af0a Mon Sep 17 00:00:00 2001 From: Folke Lemaitre Date: Thu, 22 Jun 2023 20:20:01 +0200 Subject: [PATCH 04/18] fix(config): dont show flash in cmp_menu --- lua/flash/config.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lua/flash/config.lua b/lua/flash/config.lua index a412043..4e7d75d 100644 --- a/lua/flash/config.lua +++ b/lua/flash/config.lua @@ -28,7 +28,7 @@ local defaults = { mode = "exact", -- behave like `incsearch` incremental = false, - filetype_exclude = { "notify", "noice" }, + filetype_exclude = { "notify", "noice", "cmp_menu" }, -- Optional trigger character that needs to be typed before -- a jump label can be used. It's NOT recommended to set this, -- unless you know what you're doing From 73e7d6ba72868c63a03be0c28095b963a03ccd67 Mon Sep 17 00:00:00 2001 From: Folke Lemaitre Date: Thu, 22 Jun 2023 23:11:32 +0200 Subject: [PATCH 05/18] docs: typos --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index b66b70e..656b4ee 100644 --- a/README.md +++ b/README.md @@ -212,7 +212,7 @@ Install the plugin with your preferred package manager: ## 🚀 Usage -- **jump**: `require("flash").treesitter(opts?)` opens **flash** in **Treesitter** mode +- **Treesitter**: `require("flash").treesitter(opts?)` opens **flash** in **Treesitter** mode - use a jump label, or use `;` and `,` to increase/decrease the selection - **regular search**: search as you normally do, but enhanced with jump labels - `f`, `t`, `F`, `T` motions: @@ -223,7 +223,7 @@ Install the plugin with your preferred package manager: - You can also go to the next match with `;` or previous match with `,` - Any highlights clear automatically when moving, changing buffers, or pressing ``. -- `require("flash").jump(opts?)` opens **flash** with the given options +- **jump**: `require("flash").jump(opts?)` opens **flash** with the given options - type any number of characters before typing a jump label ### Examples From 37e50ef06549814b053238a48bc9d585dd0ed484 Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" Date: Thu, 22 Jun 2023 21:12:15 +0000 Subject: [PATCH 06/18] chore(build): auto-generate vimdoc --- doc/flash.nvim.txt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/doc/flash.nvim.txt b/doc/flash.nvim.txt index 069bc3c..f0ed9d1 100644 --- a/doc/flash.nvim.txt +++ b/doc/flash.nvim.txt @@ -204,7 +204,7 @@ Default Settings ~ USAGE *flash.nvim-flash.nvim-usage* -- **jump**`require("flash").treesitter(opts?)` opens **flash** in **Treesitter** mode +- **Treesitter**`require("flash").treesitter(opts?)` opens **flash** in **Treesitter** mode - use a jump label, or use `;` and `,` to increase/decrease the selection - **regular search**search as you normally do, but enhanced with jump labels - `f`, `t`, `F`, `T` motions: @@ -215,7 +215,7 @@ USAGE *flash.nvim-flash.nvim-usage* - You can also go to the next match with `;` or previous match with `,` - Any highlights clear automatically when moving, changing buffers, or pressing ``. -- `require("flash").jump(opts?)` opens **flash** with the given options +- **jump**`require("flash").jump(opts?)` opens **flash** with the given options - type any number of characters before typing a jump label From 2771c315a747a8cf97e0a8aa2dd8b486abcf2170 Mon Sep 17 00:00:00 2001 From: Folke Lemaitre Date: Thu, 22 Jun 2023 23:21:27 +0200 Subject: [PATCH 07/18] docs: icon for examples --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 656b4ee..3185371 100644 --- a/README.md +++ b/README.md @@ -226,7 +226,7 @@ Install the plugin with your preferred package manager: - **jump**: `require("flash").jump(opts?)` opens **flash** with the given options - type any number of characters before typing a jump label -### Examples +## 💡 Examples
Forward search only From 75b3ece50517f9a93dc77b1ac86b16d1474b8191 Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" Date: Thu, 22 Jun 2023 21:24:11 +0000 Subject: [PATCH 08/18] chore(build): auto-generate vimdoc --- doc/flash.nvim.txt | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/doc/flash.nvim.txt b/doc/flash.nvim.txt index f0ed9d1..52de60a 100644 --- a/doc/flash.nvim.txt +++ b/doc/flash.nvim.txt @@ -9,6 +9,7 @@ Table of Contents *flash.nvim-table-of-contents* - Installation |flash.nvim-flash.nvim-installation| - Configuration |flash.nvim-flash.nvim-configuration| - Usage |flash.nvim-flash.nvim-usage| + - Examples |flash.nvim-flash.nvim-examples| - Highlights |flash.nvim-flash.nvim-highlights| - Alternatives |flash.nvim-flash.nvim-alternatives| @@ -219,7 +220,7 @@ USAGE *flash.nvim-flash.nvim-usage* - type any number of characters before typing a jump label -EXAMPLES ~ +EXAMPLES *flash.nvim-flash.nvim-examples* Forward search only ~ From 465bbcea02d79092c916530225daccc5f6f34e16 Mon Sep 17 00:00:00 2001 From: Folke Lemaitre Date: Thu, 22 Jun 2023 23:58:43 +0200 Subject: [PATCH 09/18] refactor: removed example plugins. Check the example section in the readme instead --- lua/flash/plugins/diagnostics.lua | 25 ---------------- lua/flash/plugins/jumplist.lua | 50 ------------------------------- 2 files changed, 75 deletions(-) delete mode 100644 lua/flash/plugins/diagnostics.lua delete mode 100644 lua/flash/plugins/jumplist.lua diff --git a/lua/flash/plugins/diagnostics.lua b/lua/flash/plugins/diagnostics.lua deleted file mode 100644 index 07dd7b1..0000000 --- a/lua/flash/plugins/diagnostics.lua +++ /dev/null @@ -1,25 +0,0 @@ -local M = {} - --- Example plugin that shows labels at positions with diagnostics. -function M.show() - require("flash").jump({ - matcher = function(win) - ---@param diag Diagnostic - return vim.tbl_map(function(diag) - return { - pos = { diag.lnum + 1, diag.col }, - end_pos = { diag.end_lnum + 1, diag.end_col - 1 }, - } - end, vim.diagnostic.get(vim.api.nvim_win_get_buf(win))) - end, - action = function(match, state) - vim.api.nvim_win_call(match.win, function() - vim.api.nvim_win_set_cursor(match.win, match.pos) - vim.diagnostic.open_float() - vim.api.nvim_win_set_cursor(match.win, state.pos) - end) - end, - }) -end - -return M diff --git a/lua/flash/plugins/jumplist.lua b/lua/flash/plugins/jumplist.lua deleted file mode 100644 index 88bbe1b..0000000 --- a/lua/flash/plugins/jumplist.lua +++ /dev/null @@ -1,50 +0,0 @@ -local State = require("flash.state") -local Util = require("flash.util") - -local M = {} - -M.state = nil -function M.jump() - if M.state then - M.state:hide() - M.state = nil - end - - M.state = State.new({ - search = { multi_window = true, wrap = true }, - highlight = { backdrop = true }, - matcher = function(win) - return vim.tbl_map(function(jump) - local pos = { jump.lnum, jump.col } - return { pos = pos, end_pos = pos } - end, vim.fn.getjumplist(win)[1]) - end, - }) - - local pos = vim.api.nvim_win_get_cursor(0) - local current = M.state:jump("a") - - while true do - local char = Util.get_char() - if not char then - vim.cmd([[normal! v]]) - vim.api.nvim_win_set_cursor(0, pos) - break - elseif char == ";" then - current = M.state:jump({ match = current, forward = true }) - elseif char == "," then - current = M.state:jump({ forward = false, match = current }) - elseif char == Util.CR then - M.state:jump(current and current.label or nil) - break - else - if not M.state:jump(char) then - vim.api.nvim_input(char) - end - break - end - end - M.state:hide() -end - -return M From 80436ecc868b2299588e0bb76edbdb1f7c0d3d6c Mon Sep 17 00:00:00 2001 From: Folke Lemaitre Date: Fri, 23 Jun 2023 08:45:00 +0200 Subject: [PATCH 10/18] docs: added example to quickly select any word --- README.md | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/README.md b/README.md index 3185371..be95cc1 100644 --- a/README.md +++ b/README.md @@ -321,6 +321,28 @@ require("flash").jump({
+
Select any word + +```lua +require("flash").jump({ + pattern = ".", -- initialize pattern with any char + search = { + mode = function(pattern) + -- remove leading dot + if pattern:sub(1, 1) == "." then + pattern = pattern:sub(2) + end + -- return word pattern and proper skip pattern + return ([[\v<%s\w*>]]):format(pattern), ([[\v<%s]]):format(pattern) + end, + }, + -- select the range + jump = { pos = "range" }, +}) +``` + +
+ ## 🌈 Highlights | Group | Default | Description | From d2b32b3410928b6be8d2ef92bba5591d55cf1fed Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" Date: Fri, 23 Jun 2023 06:45:45 +0000 Subject: [PATCH 11/18] chore(build): auto-generate vimdoc --- doc/flash.nvim.txt | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/doc/flash.nvim.txt b/doc/flash.nvim.txt index 52de60a..9c846a8 100644 --- a/doc/flash.nvim.txt +++ b/doc/flash.nvim.txt @@ -1,4 +1,4 @@ -*flash.nvim.txt* For Neovim >= 0.8.0 Last change: 2023 June 22 +*flash.nvim.txt* For Neovim >= 0.8.0 Last change: 2023 June 23 ============================================================================== Table of Contents *flash.nvim-table-of-contents* @@ -302,6 +302,26 @@ Jump to a line ~ }) < +Select any word ~ + +>lua + require("flash").jump({ + pattern = ".", -- initialize pattern with any char + search = { + mode = function(pattern) + -- remove leading dot + if pattern:sub(1, 1) == "." then + pattern = pattern:sub(2) + end + -- return word pattern and proper skip pattern + return ([[\v<%s\w>]]):format(pattern), ([[\v<%s]]):format(pattern) + end, + }, + -- select the range + jump = { pos = "range" }, + }) +< + HIGHLIGHTS *flash.nvim-flash.nvim-highlights* From 234a50d9bea3ef0a2133129657064ee74a3c3e57 Mon Sep 17 00:00:00 2001 From: Folke Lemaitre Date: Fri, 23 Jun 2023 08:51:23 +0200 Subject: [PATCH 12/18] docs: added example for remote treesitter action --- README.md | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/README.md b/README.md index be95cc1..7090699 100644 --- a/README.md +++ b/README.md @@ -343,6 +343,25 @@ require("flash").jump({ +
Jump to a position, make a Treesitter selection and jump back + +This should be bound to a keymap like `t`. +Then you could do `yt` to remotely yank a Treesitter selection. + +```lua +require("flash").jump({ + action = function(match, state) + vim.api.nvim_win_call(match.win, function() + vim.api.nvim_win_set_cursor(match.win, match.pos) + require("flash").treesitter() + vim.api.nvim_win_set_cursor(match.win, state.pos) + end) + end, +}) +``` + +
+ ## 🌈 Highlights | Group | Default | Description | From e9e716a58079b1d5d0fc7554f131be43af59f85b Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" Date: Fri, 23 Jun 2023 06:52:06 +0000 Subject: [PATCH 13/18] chore(build): auto-generate vimdoc --- doc/flash.nvim.txt | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/doc/flash.nvim.txt b/doc/flash.nvim.txt index 9c846a8..0e5fa6b 100644 --- a/doc/flash.nvim.txt +++ b/doc/flash.nvim.txt @@ -322,6 +322,23 @@ Select any word ~ }) < +Jump to a position, make a Treesitter selection and jump back ~ + +This should be bound to a keymap like `t`. Then you could do +`yt` to remotely yank a Treesitter selection. + +>lua + require("flash").jump({ + action = function(match, state) + vim.api.nvim_win_call(match.win, function() + vim.api.nvim_win_set_cursor(match.win, match.pos) + require("flash").treesitter() + vim.api.nvim_win_set_cursor(match.win, state.pos) + end) + end, + }) +< + HIGHLIGHTS *flash.nvim-flash.nvim-highlights* From 7d19c149bec9e1bd3f8ef049775edfec9c98af5d Mon Sep 17 00:00:00 2001 From: Folke Lemaitre Date: Fri, 23 Jun 2023 08:57:37 +0200 Subject: [PATCH 14/18] docs: added example on performing any remote action --- README.md | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/README.md b/README.md index 7090699..967224d 100644 --- a/README.md +++ b/README.md @@ -362,6 +362,12 @@ require("flash").jump({ +
Perform any remote action + +See [here](https://github.com/folke/flash.nvim/discussions/24) + +
+ ## 🌈 Highlights | Group | Default | Description | From 010026fc922769c7879e261b05084cadd321bc29 Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" Date: Fri, 23 Jun 2023 06:58:25 +0000 Subject: [PATCH 15/18] chore(build): auto-generate vimdoc --- doc/flash.nvim.txt | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/doc/flash.nvim.txt b/doc/flash.nvim.txt index 0e5fa6b..1977848 100644 --- a/doc/flash.nvim.txt +++ b/doc/flash.nvim.txt @@ -339,6 +339,10 @@ This should be bound to a keymap like `t`. Then you could do }) < +Perform any remote action ~ + +See here + HIGHLIGHTS *flash.nvim-flash.nvim-highlights* From e6ee00d4e76edac8cbcabe0f442a5ec34450d1f6 Mon Sep 17 00:00:00 2001 From: Folke Lemaitre Date: Fri, 23 Jun 2023 09:13:39 +0200 Subject: [PATCH 16/18] feat(config): allow custom window filters. Added non-focusable windows by default --- README.md | 11 ++++++++++- lua/flash/cache.lua | 9 +++++++-- lua/flash/config.lua | 11 ++++++++++- 3 files changed, 27 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 967224d..9d88007 100644 --- a/README.md +++ b/README.md @@ -112,7 +112,16 @@ Install the plugin with your preferred package manager: mode = "exact", -- behave like `incsearch` incremental = false, - filetype_exclude = { "notify", "noice" }, + -- Excluded filetypes and custom window filters + ---@type (string|fun(win:window))[] + exclude = { + "notify", + "cmp_menu", + function(win) + -- exclude non-focusable windows + return not vim.api.nvim_win_get_config(win).focusable + end, + }, -- Optional trigger character that needs to be typed before -- a jump label can be used. It's NOT recommended to set this, -- unless you know what you're doing diff --git a/lua/flash/cache.lua b/lua/flash/cache.lua index ff4a0df..a981c0c 100644 --- a/lua/flash/cache.lua +++ b/lua/flash/cache.lua @@ -101,8 +101,13 @@ function M:_update_wins() wins = vim.tbl_filter(function(w) local buf = vim.api.nvim_win_get_buf(w) local ft = vim.bo[buf].filetype - if ft and vim.tbl_contains(self.state.opts.search.filetype_exclude, ft) then - return false + + for _, exclude in ipairs(self.state.opts.search.exclude) do + if type(exclude) == "string" and exclude == ft then + return false + elseif type(exclude) == "function" and exclude(w) then + return false + end end return w ~= self.state.win end, wins) diff --git a/lua/flash/config.lua b/lua/flash/config.lua index 4e7d75d..97ee1d7 100644 --- a/lua/flash/config.lua +++ b/lua/flash/config.lua @@ -28,7 +28,16 @@ local defaults = { mode = "exact", -- behave like `incsearch` incremental = false, - filetype_exclude = { "notify", "noice", "cmp_menu" }, + -- Excluded filetypes and custom window filters + ---@type (string|fun(win:window))[] + exclude = { + "notify", + "cmp_menu", + function(win) + -- exclude non-focusable windows + return not vim.api.nvim_win_get_config(win).focusable + end, + }, -- Optional trigger character that needs to be typed before -- a jump label can be used. It's NOT recommended to set this, -- unless you know what you're doing From 7ab110283f65eaf43c3343567e59c413620781f7 Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" Date: Fri, 23 Jun 2023 07:14:28 +0000 Subject: [PATCH 17/18] chore(build): auto-generate vimdoc --- doc/flash.nvim.txt | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/doc/flash.nvim.txt b/doc/flash.nvim.txt index 1977848..0f8886e 100644 --- a/doc/flash.nvim.txt +++ b/doc/flash.nvim.txt @@ -106,7 +106,16 @@ Default Settings ~ mode = "exact", -- behave like `incsearch` incremental = false, - filetype_exclude = { "notify", "noice" }, + -- Excluded filetypes and custom window filters + ---@type (string|fun(win:window))[] + exclude = { + "notify", + "cmp_menu", + function(win) + -- exclude non-focusable windows + return not vim.api.nvim_win_get_config(win).focusable + end, + }, -- Optional trigger character that needs to be typed before -- a jump label can be used. It's NOT recommended to set this, -- unless you know what you're doing From 5381ca6bca29084ab160b91b9174549c9530f60e Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" <41898282+github-actions[bot]@users.noreply.github.com> Date: Fri, 23 Jun 2023 09:15:34 +0200 Subject: [PATCH 18/18] chore(main): release 1.4.0 (#28) Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> --- CHANGELOG.md | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index b69207e..e624435 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,19 @@ # Changelog +## [1.4.0](https://github.com/folke/flash.nvim/compare/v1.3.0...v1.4.0) (2023-06-23) + + +### Features + +* **char:** tfTF now behave like clever-f when repeating the motion. Fixes [#26](https://github.com/folke/flash.nvim/issues/26) ([97c3a99](https://github.com/folke/flash.nvim/commit/97c3a993e60ebdd42c7671af07620f705ee6378f)) +* **config:** allow custom window filters. Added non-focusable windows by default ([e6ee00d](https://github.com/folke/flash.nvim/commit/e6ee00d4e76edac8cbcabe0f442a5ec34450d1f6)) + + +### Bug Fixes + +* **config:** dont show flash in cmp_menu ([29c35de](https://github.com/folke/flash.nvim/commit/29c35dec5f81504ee63a39fec90597222620af0a)) +* **treesitter:** always disable incremental mode for treesitter. Fixes [#27](https://github.com/folke/flash.nvim/issues/27) ([6e84716](https://github.com/folke/flash.nvim/commit/6e8471673a7158a8820986f6aad770a912a66eed)) + ## [1.3.0](https://github.com/folke/flash.nvim/compare/v1.2.0...v1.3.0) (2023-06-22)