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

feature request: highlight parent container #376

Open
1 task done
notEvil opened this issue Jun 12, 2024 · 0 comments
Open
1 task done

feature request: highlight parent container #376

notEvil opened this issue Jun 12, 2024 · 0 comments
Labels
enhancement New feature or request P2 Not a priority. PRs welcome

Comments

@notEvil
Copy link

notEvil commented Jun 12, 2024

Did you check existing requests?

  • I have searched the existing issues

Describe the feature

It would be great if the highlight would be on the parent container
Screenshot from 2024-06-12 15-09-34

Provide background

Currently the highlight is on the closest container
Screenshot from 2024-06-12 15-09-03

What is the significance of this feature?

nice to have

Additional details

"nice to have" since I don't expect this to hit release anytime soon and I use the following patch which works so far

diff --git a/lua/aerial/render.lua b/lua/aerial/render.lua
index 0661915..1ab0b87 100644
--- a/lua/aerial/render.lua
+++ b/lua/aerial/render.lua
@@ -231,7 +231,7 @@ M.update_highlights = function(buf)
   if hl_mode == "last" then
     local pos = bufdata.positions[bufdata.last_win]
     if pos and (config.highlight_closest or pos.exact_symbol) then
-      M.highlight_line(aer_bufnr, ns, "AerialLine", pos.lnum - 1, 0, -1)
+      M.highlight_line(aer_bufnr, ns, "AerialLine", ((config.highlight_closest or not pos.exact_lnum) and pos.lnum or pos.exact_lnum) - 1, 0, -1)
     end
     return
   end
@@ -247,7 +247,7 @@ M.update_highlights = function(buf)
     local pos = bufdata.positions[winid]
     if config.highlight_closest or pos.exact_symbol then
       local hl_group = winid == bufdata.last_win and "AerialLine" or "AerialLineNC"
-      M.highlight_line(aer_bufnr, ns, hl_group, pos.lnum - 1, start_hl, end_hl)
+      M.highlight_line(aer_bufnr, ns, hl_group, ((config.highlight_closest or not pos.exact_lnum) and pos.lnum or pos.exact_lnum) - 1, start_hl, end_hl)
     end
     if hl_mode ~= "full_width" then
       start_hl = end_hl
diff --git a/lua/aerial/window.lua b/lua/aerial/window.lua
index 414b407..9e6e592 100644
--- a/lua/aerial/window.lua
+++ b/lua/aerial/window.lua
@@ -424,12 +424,14 @@ M.get_symbol_position = function(bufdata, lnum, col, include_hidden)
   local relative = "above"
   local prev = nil
   local exact_symbol
+  local exact_lnum
 
   local symbol
   for _, item in bufdata:iter({ skip_hidden = not include_hidden }) do
     local cmp, inside = compare(item, lnum, col)
     if inside then
       exact_symbol = item
+      exact_lnum = selected + 1
       if item.selection_range then
         cmp = compare(item.selection_range, lnum, col)
       end
@@ -456,6 +458,7 @@ M.get_symbol_position = function(bufdata, lnum, col, include_hidden)
     lnum = math.max(1, selected),
     closest_symbol = symbol,
     exact_symbol = exact_symbol,
+    exact_lnum = exact_lnum,
     relative = relative,
   }
 end
@@ -519,8 +522,11 @@ M.update_position = function(winids, last_focused_win)
       -- When aerial window is global, the items can change and cursor will move
       -- before the symbols are published, which causes the line number to be
       -- invalid.
-      if last_position and num_lines >= last_position.lnum then
-        vim.api.nvim_win_set_cursor(aer_winid, { last_position.lnum, 0 })
+      if last_position then
+        local lnum = (config.highlight_closest or not last_position.exact_lnum) and last_position.lnum or last_position.exact_lnum
+        if lnum <= num_lines then
+          vim.api.nvim_win_set_cursor(aer_winid, { lnum, 0 })
+        end
       end
     end
   end
@notEvil notEvil added the enhancement New feature or request label Jun 12, 2024
@stevearc stevearc added the P2 Not a priority. PRs welcome label Jun 13, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request P2 Not a priority. PRs welcome
Projects
None yet
Development

No branches or pull requests

2 participants