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 register statusline element #7222

Merged

Conversation

spectre256
Copy link
Contributor

@spectre256 spectre256 commented Jun 3, 2023

Resolves issue #1585 by adding a status message when a register is selected with the select_register command, similar to the message produced when starting to record a macro. Additionally, an indicator appears on the right with the selected register.

@kirawi kirawi added A-helix-term Area: Helix term improvements C-enhancement Category: Improvements labels Jun 5, 2023
helix-term/src/commands.rs Outdated Show resolved Hide resolved
Copy link
Member

Choose a reason for hiding this comment

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

I would prefer to see a new statusline element StatusLineElement::Register which could be rendered like so:

// ... helix-term/src/ui/statusline.rs ...
fn render_register<F>(context: &mut RenderContext, write: F)
where
    F: Fn(&mut RenderContext, String, Option<Style>) + Copy,
{
    if let Some(reg) = context.editor.selected_register {
        write(context, format!(" reg={} ", reg), None)
    }
}

and included in the default statusline config:

impl Default for StatusLineConfig {
fn default() -> Self {
use StatusLineElement as E;
Self {
left: vec![
E::Mode,
E::Spinner,
E::FileName,
E::FileModificationIndicator,
],
center: vec![],
right: vec![E::Diagnostics, E::Selections, E::Position, E::FileEncoding],
separator: String::from("│"),
mode: ModeConfig::default(),
}
}
}

probably between Selections and Position. I think that's a better fit for this kind of display. (The macro recording symbol is sort of special like the tracker of typed keys.)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done! Would it be helpful to add a similar component for when a macro is being recorded? Seems like it would be more consistent that way.

Copy link
Member

Choose a reason for hiding this comment

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

I would like the consitency of it being a statusline element too but I think it's ok where it is now. It only shows up rarely (depending on how often you use macros) and it's somewhat related to the pseudo-pending text indicator next to it

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Alright, well let me know if you change your mind; I'd be happy to help with that :)

@@ -484,6 +490,9 @@ pub enum StatusLineElement {

/// Current version control information
VersionControl,

/// Indicator for selected register
Register,
Copy link
Member

Choose a reason for hiding this comment

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

Could you add this to the docs?

The following statusline elements can be configured:
| Key | Description |
| ------ | ----------- |
| `mode` | The current editor mode (`mode.normal`/`mode.insert`/`mode.select`) |
| `spinner` | A progress spinner indicating LSP activity |
| `file-name` | The path/name of the opened file |
| `file-base-name` | The basename of the opened file |
| `file-modification-indicator` | The indicator to show whether the file is modified (a `[+]` appears when there are unsaved changes) |
| `file-encoding` | The encoding of the opened file if it differs from UTF-8 |
| `file-line-ending` | The file line endings (CRLF or LF) |
| `total-line-numbers` | The total line numbers of the opened file |
| `file-type` | The type of the opened file |
| `diagnostics` | The number of warnings and/or errors |
| `workspace-diagnostics` | The number of warnings and/or errors on workspace |
| `selections` | The number of active selections |
| `primary-selection-length` | The number of characters currently in primary selection |
| `position` | The cursor position |
| `position-percentage` | The cursor position as a percentage of the total number of lines |
| `separator` | The string defined in `editor.statusline.separator` (defaults to `"│"`) |
| `spacer` | Inserts a space between elements (multiple/contiguous spacers may be specified) |
| `version-control` | The current branch name or detached commit hash of the opened workspace |

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done! Anything else I need to do for the documentation? I tried running cargo xtask docgen but nothing seemed to change.

Copy link
Member

Choose a reason for hiding this comment

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

Nope, just that part of the book needed updating. cargo xtask docgen generates the files under book/src/generated/ which is currently just the list of typable commands and the language support table

Resolves issue helix-editor#1585 by adding a new statusline component which indicates
the currently selected register.
Copy link
Member

@the-mikedavis the-mikedavis left a comment

Choose a reason for hiding this comment

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

Looks great, thanks!

@the-mikedavis the-mikedavis changed the title Add visual feedback for select_register command Add register statusline element Jun 8, 2023
@the-mikedavis the-mikedavis linked an issue Jun 8, 2023 that may be closed by this pull request
@the-mikedavis the-mikedavis merged commit 00b152f into helix-editor:master Jun 8, 2023
6 checks passed
@spectre256 spectre256 deleted the feat/register_feedback branch June 8, 2023 21:52
Triton171 pushed a commit to Triton171/helix that referenced this pull request Jun 18, 2023
wes-adams pushed a commit to wes-adams/helix that referenced this pull request Jul 4, 2023
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 C-enhancement Category: Improvements
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Select_register command should provide visual feedback
4 participants