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

Statusline indicator to show number of selected chars #4682

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions book/src/configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ The following statusline elements can be configured:
| `file-type` | The type of the opened file |
| `diagnostics` | The number of warnings and/or errors |
| `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 `"│"`) |
Expand Down
15 changes: 15 additions & 0 deletions helix-term/src/ui/statusline.rs
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,9 @@ where
helix_view::editor::StatusLineElement::FileType => render_file_type,
helix_view::editor::StatusLineElement::Diagnostics => render_diagnostics,
helix_view::editor::StatusLineElement::Selections => render_selections,
helix_view::editor::StatusLineElement::PrimarySelectionLength => {
render_primary_selection_length
}
helix_view::editor::StatusLineElement::Position => render_position,
helix_view::editor::StatusLineElement::PositionPercentage => render_position_percentage,
helix_view::editor::StatusLineElement::TotalLineNumbers => render_total_line_numbers,
Expand Down Expand Up @@ -254,6 +257,18 @@ where
);
}

fn render_primary_selection_length<F>(context: &mut RenderContext, write: F)
where
F: Fn(&mut RenderContext, String, Option<Style>) + Copy,
{
let tot_sel = context.doc.selection(context.view.id).primary().len();

Choose a reason for hiding this comment

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

I know this PR is only concerned with the primary selection, but IMO it might be worthwhile to sum up every range's lengths to also support multi-selection counts. This could either be a separate status line element all together or it could switch to showing the primary and total character count when a multiline selection is active.

image

That's of course just a side note and this change would 100% solve the original issue

Copy link
Contributor Author

Choose a reason for hiding this comment

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

i'll leave this effort for another time

Choose a reason for hiding this comment

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

True that sounds very reasonable 👌

write(
context,
format!(" {} char{} ", tot_sel, if tot_sel == 1 { "" } else { "s" }),
None,
);
}

fn get_position(context: &RenderContext) -> Position {
coords_at_pos(
context.doc.text().slice(..),
Expand Down
3 changes: 3 additions & 0 deletions helix-view/src/editor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -328,6 +328,9 @@ pub enum StatusLineElement {
/// The number of selections (cursors)
Selections,

/// The number of characters currently in primary selection
PrimarySelectionLength,

/// The cursor position
Position,

Expand Down