feat: Blend cursor color with cursorline

This commit is contained in:
hedy
2023-11-11 11:20:14 +08:00
parent 09b51fa5d5
commit e9d83e472e
3 changed files with 87 additions and 15 deletions

View File

@@ -163,7 +163,9 @@ Features/Changes:
lineno are now fully customizable using `outline_window.winhl`. See
[highlights](#outline-window).
Screen recordings of some of the features is shown at the [bottom of the readme](#recipes).
- Option to blend cursor with cursorline (`outline_window.hide_cursor`)
Screen recordings/shots of some of the features is shown at the [bottom of the readme](#recipes).
## PRs
@@ -272,18 +274,23 @@ Key:
Key:
```
- : Idea
- [ ] : Planned
- [/] : WIP
- : Idea
- : Was idea, found usable workaround
- ✅ : Implemented
```
- Folds
- `[ ]` Org-like <kbd>shift+tab</kbd> behavior: Open folds level-by-level
- `[ ]` Optionally not opening all child nodes when opening parent node
- Fold siblings and siblings of parent on startup
- Navigation
- Go to parent
- Cycle siblings
- Go to parent (as of now you can press `hl` to achieve the same
effect)
- ❌ Cycle siblings (as of now when reached the last sibling, you can use `hlj`
to go back to first sibling)
- `[ ]` simrat39/symbols-outline.nvim#75: Handling of the outline window when attached
buffer is closed.
@@ -299,7 +306,7 @@ Key:
- View
- ✅ Outline window customizations (simrat39/symbols-outline.nvim#137)
- ✅ Option to show line number next to symbols (simrat39/symbols-outline.nvim#212)
- `[/]` Option to hide cursor in outline window if cursorline enabled
- Option to hide cursor in outline window if cursorline enabled
## Related plugins
@@ -326,7 +333,7 @@ Supports all your favourite languages.**
<!-- panvimdoc-ignore-start -->
Table of contents
<!-- mtoc start -->
<!-- mtoc-start -->
* [Prerequisites](#prerequisites)
* [Installation](#installation)
@@ -343,7 +350,7 @@ Table of contents
* [Tips](#tips)
* [Recipes](#recipes)
<!-- mtoc end -->
<!-- mtoc-end -->
<!-- panvimdoc-ignore-end -->
## Prerequisites
@@ -454,7 +461,18 @@ Default values are shown:
-- Vim options for the outline window
show_numbers = false,
show_relative_numbers = false,
show_cursorline = true, -- Only in this fork
-- Only in this fork (this and the one below)
show_cursorline = true,
-- Enable this when you enabled cursorline so your cursor color can
-- blend with the cursorline, in effect, as if your cursor is hidden
-- in the outline window.
-- This is useful because with cursorline, there isn't really a need
-- to know the vertical column position of the cursor and it may even
-- be distracting, rendering lineno/guides/icons unreadable.
-- This makes your line of cursor look the same as if the cursor wasn't
-- focused on the outline window.
hide_cursor = false,
-- Whether to wrap long lines, or let them flow off the window
wrap = false,
@@ -816,7 +834,7 @@ symbol_folding = {
auto_unfold_hover = true,
},
```
<img width="900" alt="image" src="https://github.com/hedyhli/symbols-outline.nvim/assets/50042066/2e0c5f91-a979-4e64-a100-256ad062dce3">
<img width="900" alt="outline window showing auto fold depth" src="https://github.com/hedyhli/symbols-outline.nvim/assets/50042066/2e0c5f91-a979-4e64-a100-256ad062dce3">
- **Use outline window as a quick-jump window**
@@ -871,8 +889,25 @@ outline_items = {
The default highlight group for the line numbers is `LineNr`, you can customize
it using `outline_window.winhl`: please see [highlights](#outline-window).
<img width="900" alt="image" src="https://github.com/hedyhli/symbols-outline.nvim/assets/50042066/2bbb5833-f40b-4c53-8338-407252d61443">
<img width="900" alt="outline window showing lineno" src="https://github.com/hedyhli/symbols-outline.nvim/assets/50042066/2bbb5833-f40b-4c53-8338-407252d61443">
- **Single cursorline**
```lua
outline_window = {
show_cursorline = true,
hide_cursor = true,
}
```
This will be how the outline window look like when focused.
<img width="300" alt="outline window showing hide_cursor" src="https://github.com/hedyhli/symbols-outline.nvim/assets/50042066/1e13c4db-ae51-4e1f-a388-2758871df36a">
Note that in the screenshot, `outline_items.show_symbol_lineno` is also enabled.
Some may find this unhelpful, but one may argue that elements in each row of the
outline becomes more readable this way, hence this is an option.
<!-- panvimdoc-ignore-start -->

View File

@@ -28,6 +28,7 @@ M.defaults = {
show_numbers = false,
show_relative_numbers = false,
show_cursorline = true,
hide_cursor = false,
winhl = "SymbolsOutlineDetails:Comment,SymbolsOutlineLineno:LineNr",
},
preview_window = {
@@ -184,6 +185,12 @@ function M.show_help()
print(vim.inspect(M.o.keymaps))
end
function M.check_config()
if M.o.outline_window.hide_cursor and not M.o.outline_window.show_cursorline then
vim.notify("[symbols-outline.config]: hide_cursor enabled WITHOUT cursorline enabled!", vim.log.levels.ERROR)
end
end
function M.setup(options)
vim.g.symbols_outline_loaded = 1
M.o = vim.tbl_deep_extend('force', {}, M.defaults, options or {})
@@ -191,6 +198,7 @@ function M.setup(options)
if type(guides) == 'boolean' and guides then
M.o.guides = M.defaults.guides
end
M.check_config()
end
return M

View File

@@ -46,6 +46,9 @@ M.state = {
outline_items = {},
flattened_outline_items = {},
code_win = 0,
-- In case unhide_cursor was called before hide_cursor for _some_ reason,
-- this can still be used as a fallback
original_cursor = vim.o.guicursor,
}
local function wipe_state()
@@ -129,6 +132,19 @@ function M._toggle_fold(move_cursor, node_index)
end
end
local function hide_cursor()
-- Set cursor color to CursorLine in normal mode
M.state.original_cursor = vim.o.guicursor
local cur = vim.o.guicursor:match("n.-:(.-)[-,]")
vim.opt.guicursor:append("n:"..cur.."-Cursorline")
end
local function unhide_cursor()
-- vim.opt doesn't seem to provide a way to remove last item, like a pop()
-- vim.o.guicursor = vim.o.guicursor:gsub(",n.-:.-$", "")
vim.o.guicursor = M.state.original_cursor
end
local function setup_buffer_autocmd()
if cfg.o.preview_window.auto_preview then
vim.api.nvim_create_autocmd('CursorMoved', {
@@ -150,6 +166,19 @@ local function setup_buffer_autocmd()
end
})
end
if cfg.o.outline_window.hide_cursor then
-- Unfortunately guicursor is a global option, so we have to make sure to
-- set and unset when cursor leaves the outline window.
hide_cursor()
vim.api.nvim_create_autocmd('BufEnter', {
buffer = 0,
callback = hide_cursor
})
vim.api.nvim_create_autocmd('BufLeave', {
buffer = 0,
callback = unhide_cursor
})
end
end
function M._set_folded(folded, move_cursor, node_index)