Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

No highlight with forward leap on last line in buffer #248

Open
h3xOo opened this issue Sep 19, 2024 · 5 comments
Open

No highlight with forward leap on last line in buffer #248

h3xOo opened this issue Sep 19, 2024 · 5 comments
Labels
bug Something isn't working

Comments

@h3xOo
Copy link

h3xOo commented Sep 19, 2024

As in title, if I press "s" for forward leap while cursor is on last line in the file, no highlighting is applied (neither text becomes grey via link to Comment nor possible targets are purple/pink).

Same goes for f/t from flit (but S/F/T work in first and last line in buffer).

@h3xOo
Copy link
Author

h3xOo commented Sep 19, 2024

I think this can be the quickfix

diff --git a/lua/leap/highlight.lua b/lua/leap/highlight.lua
index 753d403..09040bf 100644
--- a/lua/leap/highlight.lua
+++ b/lua/leap/highlight.lua
@@ -58,8 +58,10 @@ M["apply-backdrop"] = function(self, backward_3f, _3ftarget_windows)
       local function _11_()
         if backward_3f then
           return {{win_top, 0}, {curline, curcol}}
-        else
+        elseif curline ~= win_bot then
           return {{curline, inc(curcol)}, {win_bot, -1}}
+        else
+          return {{curline, inc(curcol)}, {win_bot, vim.fn.col("$")}}
         end
       end
       local _let_12_ = _11_()

With debug prints, on last line we were highlight from f.e. from { 1, 1 } to { 1, -1 } and nvim doesn't handle that?
I used this debug print

print(string.format("start = (%d, %d), finish = (%d, %d)", start[1], start[2], finish[1], finish[2]))

before vim.highlight.range() call
@ggandor pinging for comments/thoughts

@h3xOo
Copy link
Author

h3xOo commented Sep 19, 2024

As it turns out, vim.highlight.range() calls vim.region(), which will swap start and finish (if I'm correct)
obraz

@h3xOo
Copy link
Author

h3xOo commented Sep 23, 2024

This also works

diff --git a/lua/leap/highlight.lua b/lua/leap/highlight.lua
index 753d403..403bb7c 100644
--- a/lua/leap/highlight.lua
+++ b/lua/leap/highlight.lua
@@ -59,7 +59,7 @@ M["apply-backdrop"] = function(self, backward_3f, _3ftarget_windows)
         if backward_3f then
           return {{win_top, 0}, {curline, curcol}}
         else
-          return {{curline, inc(curcol)}, {win_bot, -1}}
+          return {{curline, inc(curcol)}, {win_bot + 1, -1}}
         end
       end
       local _let_12_ = _11_()

But highlighting after last line feels a bit hacky

@ggandor
Copy link
Owner

ggandor commented Sep 23, 2024

Hi, thanks for the report! I can reproduce on 0.10.1 stable, but the problem seems to be fixed on 0.11.

@ggandor ggandor added the bug Something isn't working label Sep 23, 2024
@h3xOo
Copy link
Author

h3xOo commented Sep 24, 2024

Oh, I'm on 0.10.1.

Out of curiosity I checked that they added explicit check for -1 in vim.highlight.range().

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants