Thanks to visit codestin.com
Credit goes to github.com

Skip to content

[WIP] Implement a scrollbar highlighter#2597

Open
occivink wants to merge 3 commits intomawww:masterfrom
occivink:scrollbar
Open

[WIP] Implement a scrollbar highlighter#2597
occivink wants to merge 3 commits intomawww:masterfrom
occivink:scrollbar

Conversation

@occivink
Copy link
Contributor

@occivink occivink commented Nov 25, 2018

This highlighter adds a scrollbar that visualizes the position of the view within the buffer. I find it useful because we currently don't have a way to get a sense of how big a buffer is, nor where we are relatively.

It also allows adding 'indicator' sub-highlighters that can be used to modify the color of portions of the scrollbar. This is currently done via line-specs options because the main use-case I can think of is to get a rough idea of where you have {errors,warnings,diff,breakpoints,...} in a buffer. But it would be easy to change it to an int-list that simply specify the lines.

Multiple 'indicators' can be added, in which case they will compete for setting the face of the scrollbar cell. The first indicator added has precedence.

Screenshot (without indicators) for people who don't want to build this.
This can be tested like so:

addhl global/ scrollbar
addhl global/scrollbar/ scrollbar-indicator red,default git_diff_flags
git show-diff

(on a buffer that has diff, in order to see the colors changing).

Issues

  • Broken when the view is at the end of the buffer. Since there are no DisplayLine that cover the empty part, the scrollbar does not extend over the entire view. I tried pushing new DisplayLine but this messes with other highlighters.
  • The padding is currently done in a hacky way (at least I find it): the highlighter shouldn't have to consider whether an atom has a buffer range, especially since we simply want to add one cell. But I could not find a way to consistently display at the right edge with just the value of context.setup.window_range. It also means it suffers from the same issue described in Wrap highlighter with -marker shifts columns #2594
  • Doesn't work with characters wider than 1 cell, I think I need to revisit the code that deals with the positionning.

@andreyorst
Copy link
Contributor

This highlighter adds a scrollbar that visualizes the position of the view within the buffer. I find it useful because we currently don't have a way to get a sense of how big a buffer is, nor where we are relatively.

Small thought. While this is kind of true, and scrollbar is cool feature, I've never though that positioning in a file means anything really. I've liked that in Emacs with powerline you can have like a mini-map in the statusline, that shows position in the file, but never found it really useful. Unless I'm comparing files with diff, and I need to see if there's more to see below. That's why I've made a position module in my powerline.kak plugin (the last one):
image

By the way sublime text style minimap is way more informative compared to scrollbar, but I understand that we can't do such thing in TUI. So percent position in a file usually enough for me in most cases

It also allows adding 'indicator' sub-highlighters that can be used to modify the color of portions of the scrollbar. This is currently done via line-specs options because the main use-case I can think of is to get a rough idea of where you have {errors,warnings,diff,breakpoints,...} in a buffer. But it would be easy to change it to an int-list that simply specify the lines.

That's actually a great feature in such editors as VS Code, and IIRC Intellij Idea. If we could utilize it with language server, or builtin linters this actually will make whole life easier, but I see a small problem here.

Since such scrollbar is limited in "resolution" to terminal height, and one char width, we can't display such marks with precision. For really long files this would mean that seeing error mark on a scrollbar isn't correspond with actual positon of the mark, since limited resolution of scrollbar would include hundreds of lines in one vertical character. Tha'ts not a problem for GUI, since we can create scrollbar of any pixel height, and display marks on it with pixel precision, but that's not the case for TUI. So I feel like this feature is questionable, and may lead to inconsistency of movement within the file for newcomers.

@occivink
Copy link
Contributor Author

Thanks for the feedback.

If we could utilize it with language server, or builtin linters this actually will make whole life easier

If you checkout the branch, you can try it on lint flags or lsp errors, it reuses the same options.

addhl global/ scrollbar
addhl global/scrollbar/ scrollbar-indicator red,default lsp_error_lines
addhl global/scrollbar/ scrollbar-indicator yellow,default lint_flags

You're right that the lack of resolution is a concern, I think I need to test the PR on "real" usecases. It might be possible to double the resolution by using half-blocks with different foreground/background, but that would hard-code the characters, which I don't think is worth it.

@FlyingWombat
Copy link

Do you know if it would be feasible to make the scroll bar something like Oni did? That is to have a small line within the view block to indicate the cursor position in the view.
To do this, maybe we could make use of unicode braile characters to make a "high resolution" scroll bar, like how gtop does its stuff.

This, of course, wouldn't be necessary. But it would be cool.

@occivink
Copy link
Contributor Author

occivink commented Apr 9, 2019

It would be possible but we would have to hardcode the characters used for the scrollbar. Currently they are configurable and by default use the same characters as the completion scrollbar, which has this nice dithered pattern for the "background".
If we were to hardcode some characters, I think I would rather use the half-block ones so that we would have twice the scrollbar resolution.
I'm also not too sure about the feature itself; since the cursor is already in the view, I think it makes more sense to look at the view itself to find the cursors rather than at the scrollbar

@andreyorst
Copy link
Contributor

Currently they are configurable and by default use the same characters as the completion scrollbar, which has this nice dithered pattern for the "background".

wait, so I can configure those scrollbar symbols?

@occivink
Copy link
Contributor Author

occivink commented Apr 9, 2019

Not the ones that already exist (completions, prompt suggestions), only the one from this PR's highlighter.

@Cons-Cat
Copy link

Cons-Cat commented Mar 5, 2021

By the way sublime text style minimap is way more informative compared to scrollbar, but I understand that we can't do such thing in TUI. So percent position in a file usually enough for me in most cases

It's also a lot more expensive in terms of screen real estate. It effectively prohibits a two-pane vertical spilt on a portrait oriented window, and the additional information a minimap provides is worth very little by comparison imho. A scroll bar does not have this drawback.

It can be quite tricky to know if the buffer will fit the view, so until this can be done reliably, show it always.
@Screwtapello
Copy link
Contributor

For anyone wanting a scrollbar that works with official Kakoune builds, there's a scrollbar plugin at https://github.com/sawdust-and-diamonds/scrollbar.kak

@enricozb enricozb mentioned this pull request Apr 2, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants