Skip to content

Commit

Permalink
Statusline indicator to show number of selected chars
Browse files Browse the repository at this point in the history
Feature request: helix-editor#4624
  • Loading branch information
wes adams committed Nov 9, 2022
1 parent 758bace commit deaab51
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 1 deletion.
16 changes: 16 additions & 0 deletions helix-term/src/ui/statusline.rs
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,7 @@ 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::TotalCharsSelected => render_total_chars_selected,
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 +255,21 @@ where
);
}

fn render_total_chars_selected<F>(context: &mut RenderContext, write: F)
where
F: Fn(&mut RenderContext, String, Option<Style>) + Copy,
{
let tot_sel = context
.doc
.selections()
.get(&context.view.id)
.unwrap()
.ranges()[0]
.len();

write(context, format!(" {} ", tot_sel), None);
}

fn get_position(context: &RenderContext) -> Position {
coords_at_pos(
context.doc.text().slice(..),
Expand Down
11 changes: 10 additions & 1 deletion helix-view/src/editor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -276,7 +276,13 @@ impl Default for StatusLineConfig {
Self {
left: vec![E::Mode, E::Spinner, E::FileName],
center: vec![],
right: vec![E::Diagnostics, E::Selections, E::Position, E::FileEncoding],
right: vec![
E::Diagnostics,
E::Selections,
E::TotalCharsSelected,
E::Position,
E::FileEncoding,
],
separator: String::from("│"),
mode: ModeConfig::default(),
}
Expand Down Expand Up @@ -328,6 +334,9 @@ pub enum StatusLineElement {
/// The number of selections (cursors)
Selections,

/// The number of chars highlighted
TotalCharsSelected,

/// The cursor position
Position,

Expand Down

0 comments on commit deaab51

Please sign in to comment.