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

Add title box to Picker #8155

Closed
wants to merge 21 commits into from
Closed

Conversation

ArchUsr64
Copy link
Contributor

@ArchUsr64 ArchUsr64 commented Sep 3, 2023

Fixes #8139
The current implementation of the picker doesn't display any context information about what it's displaying.
This PR adds a title field to the Picker struct and implements the necessary logic for proper rendering of the title box based on the config option PickerTitle.

pub struct Picker<T: Item> {
...
    /// Title for the picker box
    title: String,
}
pub enum PickerTitle {
    /// Don't render the title
    #[default]
    Never,
    /// Render on top of picker box
    Center,
    /// Render inline with the picker's border
    Inline,
    /// Render inline with the picker's border
    InlineBorder,
    /// Render title in the prompt line
    Prompt,
}

This changes the rendering of a picker as follows:

                `inline`                 `inline-border`           `center`

                                                                  +-------+
                                  +-------+                       | title |
         +-title-+-+ +---------+  | title +-+ +---------+  +------+--+ +--+------+
         | prompt  | | preview |  | prompt  | | preview |  | prompt  | | preview |
         |---------| |         |  |---------| |         |  |---------| |         |
         | picker  | |         |  | picker  | |         |  | picker  | |         |
         |         | |         |  |         | |         |  |         | |         |
         |         | |         |  |         | |         |  |         | |         |
         |         | |         |  |         | |         |  |         | |         |
         |         | |         |  |         | |         |  |         | |         |
         |         | |         |  |         | |         |  |         | |         |
         +---------+ +---------+  +---------+ +---------+  +---------+ +---------+

The title is exposed to the caller via Picker::new() and Picker::with_stream() functions.
I have added the following as the titles for now:

Caller Title Dynamic
global_search Global Search: 'user_entered_regex' [case_sensitive] ✔️
buffer_picker Buffer List
jumplist_picker Jumplist List
command_palette Command Palette
file_picker Files in: current working directory ✔️
sym_picker Symbol Picker
diag_picker Diagnostics: [errors E] [warnings W] [informations I] [hints H] ✔️
lsp_workspace_command LSP Workspace Commands
goto_impl Goto Picker
thread_picker Thread Picker
dap_launch DAP Picker
dap_switch_stack_frame DAP Stack Frame Picker

Screenshots

Changes to Picker:

image

File Picker:

image

Global Search Picker:

image

Diagnostics Picker:

image

Videos

Dynamic Titles:

2023-09-04_14-13-16.mp4

Rendering Options:

2023-09-09_23-07-40.mp4

Preivously, if the length of the string was even
The string would underflow and the vertical bar
on the line with title string would underflow
The title now shows the number of diagnostics
based on severity like follows:
"Diagnostics: [5 E] [0 W] [1 I] [0 H]"
The title now shows the `user_entered_regex`
and if the search is case sensitive or not
taking `smart_case` into account
@pascalkuthe
Copy link
Member

I am not a fan of adding a title it feels unnecessary and tahkesup more vertical space. With #7265 there will be a heading for each column so at that point it gets too much

@ArchUsr64
Copy link
Contributor Author

ArchUsr64 commented Sep 3, 2023

I am not a fan of adding a title it feels unnecessary and tahkesup more vertical space. With #7265 there will be a heading for each column so at that point it gets too much

I would agree with you that the title would be redundant if it just displayed some static information but for something like global search, the additional context the title provides is quite helpful, have a look:

image

As for the concerns regarding limited vertical space, I'm working on an implementation that just adds title to the top of existing picker instead of shrinking the picker to make room for the title box.
There could also be a config option that disables title rendering for those who prefer the old style.

@EpocSquadron
Copy link
Contributor

Could we not display the title inline with the bounding box at top, similar to what we do with the title for keymap modes?

@ArchUsr64
Copy link
Contributor Author

Could we not display the title inline with the bounding box at top, similar to what we do with the title for keymap modes?

This is how that could look like, I'm not sure I prefer either of them over the title box being at the center, though not wasting extra space is a plus.
image
image

@ArchUsr64 ArchUsr64 marked this pull request as ready for review September 4, 2023 08:52
@EpocSquadron
Copy link
Contributor

I quite like the look of the second option, but from a minimal point of view the first is best. Curious what others think.

@ArchUsr64
Copy link
Contributor Author

I quite like the look of the second option, but from a minimal point of view the first is best. Curious what others think.

Me too though you might wanna have a look at my original post which I have since updated with the new changes to title rendering.

Would a configuration option be better? Something like picker.title_style with options of center, inline, inline_border and none?

@zen3ger
Copy link
Contributor

zen3ger commented Sep 5, 2023

Since the promp/commandline at the bottom is always empty when a picker is opened, can't we just put this information there? It wouldn't take up any extra space and would still be there for those that need it.

@ArchUsr64
Copy link
Contributor Author

Since the promp/commandline at the bottom is always empty when a picker is opened, can't we just put this information there? It wouldn't take up any extra space and would still be there for those that need it.

I don't think the title being at prompt would be very intuitive for pickers that are primarily launched via keymaps, like the file picker but I could see it working for the global search picker.

@EpocSquadron
Copy link
Contributor

It’s definitely not intuitive to put it in the prompt, and I wouldn’t want it inconsistent from picker to picker . Global search will eventually not use the prompt anyway, once interactive global search gets done.

I say (without much authority) we go for the configurable but on by default approach, similar to how autoinfo is there by default but can be configured off by those who prefer not to have the noise. A big draw of the editor is contextual help or intuitive/unsurprising behavior.

As for which style to use, since the works already done I don’t see any harm in keeping both versions as part of configuration. My bias is again to use the prettier version as the default.

@ArchUsr64
Copy link
Contributor Author

I say (without much authority) we go for the configurable but on by default approach, similar to how autoinfo is there by default but can be configured off by those who prefer not to have the noise. A big draw of the editor is contextual help or intuitive/unsurprising behavior.

I agree, it's probably the best to let users decide for themselves. For now, I have implemented the configuration options for all the suggestions presented above namely: center, inline, inline-border and prompt. Though I have set the default to never for now.
The top post has been updated with all the relevant details if you wanna have a look.


| Key | Description | Default |
|--|--|---------|
| `picker-title` | Renders a title for the opening picker. Can be `never`, `center`, `inline`, `inline-border` or `prompt` | `never` |
Copy link
Contributor

Choose a reason for hiding this comment

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

The formulation here can make a non-fluent reader think that the title will be never, center, ...

What do you think about:

Suggested change
| `picker-title` | Renders a title for the opening picker. Can be `never`, `center`, `inline`, `inline-border` or `prompt` | `never` |
| `title-format` | How the picker's title is displayed. Can be `never`, `center`, `inline`, `inline-border` or `prompt` | `never` |

Comment on lines +2222 to +2230
let picker_title = format!(
"Global Search: '{}' {}",
regex,
if case_sensitive {
"[Case Sensitive]"
} else {
"[Case Insensitive]"
}
);
Copy link
Contributor

Choose a reason for hiding this comment

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

With a long regex, this will be quite unreadable, the length of the displayed regex should be limited to the N (to determine) first chars of it.


let picker_title = format!(
"Diagnostics: [{} E] [{} W] [{} I] [{} H]",
Copy link
Contributor

Choose a reason for hiding this comment

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

I think just: {} E, {} W, {} I, {} H will be enough and have less sigils to read. Commas are easier to skip than [] too

cx.editor.set_error(err);
}
})
let picker_title = format!("Files in {:?}", root.as_os_str());
Copy link
Contributor

Choose a reason for hiding this comment

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

This will also have the length problem and should probably be collapsed, only expand the last N directories, if it reaches the width limit of the windows

Comment on lines +817 to +823
surface.set_string(
// Add two for spacing for border box and margin
area.x + 2,
area.y + 1,
&self.title,
text_style,
);
Copy link
Contributor

Choose a reason for hiding this comment

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

Yes I think the picker title will overflow if it is too long, I remember hitting this with inline diagnostics

@zaucy zaucy mentioned this pull request Oct 17, 2023
@pascalkuthe
Copy link
Member

I am going to close this PR. This also already has conflicts and will become very hard to rebase once #9647 is merged. I don't think we want to add this feature in this form. This is a mimor visual feature where I just don't think it's worth or necessary to invest the effort.

Thank you for contributing.

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.

Add title to fuzzy picker box
5 participants