Statusline indicator to show number of selected chars (#4682)

Co-authored-by: wes adams <wadams@grayshift.com>
pull/4727/head
wes adams 2 years ago committed by GitHub
parent 1f72d34249
commit fd585c1ee4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -103,6 +103,7 @@ The following statusline elements can be configured:
| `file-type` | The type of the opened file | | `file-type` | The type of the opened file |
| `diagnostics` | The number of warnings and/or errors | | `diagnostics` | The number of warnings and/or errors |
| `selections` | The number of active selections | | `selections` | The number of active selections |
| `primary-selection-length` | The number of characters currently in primary selection |
| `position` | The cursor position | | `position` | The cursor position |
| `position-percentage` | The cursor position as a percentage of the total number of lines | | `position-percentage` | The cursor position as a percentage of the total number of lines |
| `separator` | The string defined in `editor.statusline.separator` (defaults to `"│"`) | | `separator` | The string defined in `editor.statusline.separator` (defaults to `"│"`) |

@ -142,6 +142,9 @@ where
helix_view::editor::StatusLineElement::FileType => render_file_type, helix_view::editor::StatusLineElement::FileType => render_file_type,
helix_view::editor::StatusLineElement::Diagnostics => render_diagnostics, helix_view::editor::StatusLineElement::Diagnostics => render_diagnostics,
helix_view::editor::StatusLineElement::Selections => render_selections, 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::Position => render_position,
helix_view::editor::StatusLineElement::PositionPercentage => render_position_percentage, helix_view::editor::StatusLineElement::PositionPercentage => render_position_percentage,
helix_view::editor::StatusLineElement::TotalLineNumbers => render_total_line_numbers, helix_view::editor::StatusLineElement::TotalLineNumbers => render_total_line_numbers,
@ -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();
write(
context,
format!(" {} char{} ", tot_sel, if tot_sel == 1 { "" } else { "s" }),
None,
);
}
fn get_position(context: &RenderContext) -> Position { fn get_position(context: &RenderContext) -> Position {
coords_at_pos( coords_at_pos(
context.doc.text().slice(..), context.doc.text().slice(..),

@ -328,6 +328,9 @@ pub enum StatusLineElement {
/// The number of selections (cursors) /// The number of selections (cursors)
Selections, Selections,
/// The number of characters currently in primary selection
PrimarySelectionLength,
/// The cursor position /// The cursor position
Position, Position,

Loading…
Cancel
Save