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

Adds support for right-hand gutters and Scrollbar gutter item #5749

Open
wants to merge 4 commits into
base: master
Choose a base branch
from

Conversation

jakesactualface
Copy link

Relates to #2210

First time contributor, so please let me know if I'm missing anything!

Overview

  • Adds support for gutter items rendered on the right-hand side of the view
  • Adds support for a new "scrollbar" gutter item
    • Note: this item is not added to the default configuration for the left- or right-hand gutter

Architectural Changes

  • A gutters-right configuration option is exposed as a sibling to the existing gutters option
  • View now accepts an additional gutters_right parameter as a GutterConfig object
  • Gutter item functions are now called for each visible line in the view, rather than stopping at the last line of document contents
    • See last_line initialization within render_gutter_item for more context
  • A Scrollbar variant was added to the GutterType enum

Design feedback needed

This gutters vs. gutters-right implementation seemed like the easiest approach (and was also passive to the existing config file setup), but I quite like how the editor.statusline configuration is subdivided into left, center, and right partitions.

  • Should we wrap gutter configuration into similar left and right partitions?

@pascalkuthe pascalkuthe added A-helix-term Area: Helix term improvements S-waiting-on-review Status: Awaiting review from a maintainer. labels Jan 31, 2023
@pascalkuthe
Copy link
Member

pascalkuthe commented Jan 31, 2023

This is not really a fault of this PR but there is currently a larger change to editor rendering underway in #5420.
This PR heavily conflicts with #5420 and needs to be rebased on that once that is merged. #5420 fundamentally changes how gutters are rendered (or really all editor ui) and especially the following change will be problematic:

Gutter item functions are now called for each visible line in the view, rather than stopping at the last line of document contents

@jakesactualface
Copy link
Author

@pascalkuthe no worries! I'm fine with rebasing onto your changes. I gave it a try preemptively based on the current contents of your PR and it seems like the right gutter is still rendering correctly, though I'll have to adjust the math for the scrollbar position.

In the meantime, should I convert this PR to a draft until #5420 is merged? Or is there a different way you'd like me to proceed?

@pascalkuthe
Copy link
Member

It would have been fine to leave the PR as is, we have a label that we put in PRs that are based on other.

Howbwr #5420 has been merged into master today so you can just rebase off master

@jakesactualface
Copy link
Author

It would have been fine to leave the PR as is

Sorry, I meant that I performed a quick rebase locally, just to see how big of a conflict I was in store for.

I still have some cleanup and validation to do before I'm ready to push that rebase here, but I'll try to get that done within the next few days. Thank you for the heads-up!

@pascalkuthe pascalkuthe added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-review Status: Awaiting review from a maintainer. labels Feb 1, 2023
@jakesactualface
Copy link
Author

I have rebased my changes onto a fresh copy of master, as well as divided them up between 3 commits. This was done to give some logical separation between the main ideas being attempted:

  1. Add support for a gutter on the right-hand side of the view
  2. Add support for a "scrollbar" gutter item
  3. Enable gutter rendering for lines within the viewport but beyond EOF

The changes in Point 3 above (localized for now in the 3rd commit on this PR) could definitely benefit from some more-experienced eyes than my own, if that functionality is going to be considered for merge. I'm still fairly new to Rust and I suspect there's a better way for me to be tracking the viewport's position during the text rendering iteration.

I've included some screenshots below for an overview of how this branch looks in use, in case that makes things easier for anyone interested.

Line numbers enabled for right-hand gutter (left-hand gutter is explicitly set to default layout):

image

Right-hand gutter set to "scrollbar", "spacer", "line-numbers":

image

Same file and setup, with the viewport scrolled beyond EOF:

image

@the-mikedavis the-mikedavis added S-waiting-on-review Status: Awaiting review from a maintainer. and removed S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Feb 5, 2023
Box::new(
move |line: usize, _selected: bool, _first_visual_line: bool, out: &mut String| {
let icon = if line >= start_line && line <= start_line.saturating_add(height) {
"█"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We already use the half block character for the completion popup scrollbar, so we could use the same here for consistency:

cell = &mut surface[(inner.right() - 1, inner.top() + i as u16)];
cell.set_symbol("▐"); // right half block
if scroll_line <= i && i < scroll_line + scroll_height {

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I originally shied away from that since there's nothing stopping someone from putting the scrollbar on the left, but it looks like the diff gutter is making a similar assumption and it looks better for it.

I'll add the change as suggested, but I'm open to discussing it if others have a different opinion.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-helix-term Area: Helix term improvements S-waiting-on-review Status: Awaiting review from a maintainer.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants