Skip to content

Commit deaab51

Browse files
author
wes adams
committed
Statusline indicator to show number of selected chars
Feature request: #4624
1 parent 758bace commit deaab51

File tree

2 files changed

+26
-1
lines changed

2 files changed

+26
-1
lines changed

helix-term/src/ui/statusline.rs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,7 @@ where
142142
helix_view::editor::StatusLineElement::FileType => render_file_type,
143143
helix_view::editor::StatusLineElement::Diagnostics => render_diagnostics,
144144
helix_view::editor::StatusLineElement::Selections => render_selections,
145+
helix_view::editor::StatusLineElement::TotalCharsSelected => render_total_chars_selected,
145146
helix_view::editor::StatusLineElement::Position => render_position,
146147
helix_view::editor::StatusLineElement::PositionPercentage => render_position_percentage,
147148
helix_view::editor::StatusLineElement::TotalLineNumbers => render_total_line_numbers,
@@ -254,6 +255,21 @@ where
254255
);
255256
}
256257

258+
fn render_total_chars_selected<F>(context: &mut RenderContext, write: F)
259+
where
260+
F: Fn(&mut RenderContext, String, Option<Style>) + Copy,
261+
{
262+
let tot_sel = context
263+
.doc
264+
.selections()
265+
.get(&context.view.id)
266+
.unwrap()
267+
.ranges()[0]
268+
.len();
269+
270+
write(context, format!(" {} ", tot_sel), None);
271+
}
272+
257273
fn get_position(context: &RenderContext) -> Position {
258274
coords_at_pos(
259275
context.doc.text().slice(..),

helix-view/src/editor.rs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -276,7 +276,13 @@ impl Default for StatusLineConfig {
276276
Self {
277277
left: vec![E::Mode, E::Spinner, E::FileName],
278278
center: vec![],
279-
right: vec![E::Diagnostics, E::Selections, E::Position, E::FileEncoding],
279+
right: vec![
280+
E::Diagnostics,
281+
E::Selections,
282+
E::TotalCharsSelected,
283+
E::Position,
284+
E::FileEncoding,
285+
],
280286
separator: String::from("│"),
281287
mode: ModeConfig::default(),
282288
}
@@ -328,6 +334,9 @@ pub enum StatusLineElement {
328334
/// The number of selections (cursors)
329335
Selections,
330336

337+
/// The number of chars highlighted
338+
TotalCharsSelected,
339+
331340
/// The cursor position
332341
Position,
333342

0 commit comments

Comments
 (0)