Skip to content

Commit 51e16b9

Browse files
wes-adamswes adams
authored andcommitted
Statusline indicator to show number of selected chars (helix-editor#4682)
Co-authored-by: wes adams <[email protected]>
1 parent 6da3c1b commit 51e16b9

File tree

3 files changed

+19
-0
lines changed

3 files changed

+19
-0
lines changed

book/src/configuration.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,7 @@ The following statusline elements can be configured:
103103
| `file-type` | The type of the opened file |
104104
| `diagnostics` | The number of warnings and/or errors |
105105
| `selections` | The number of active selections |
106+
| `primary-selection-length` | The number of characters currently in primary selection |
106107
| `position` | The cursor position |
107108
| `position-percentage` | The cursor position as a percentage of the total number of lines |
108109
| `separator` | The string defined in `editor.statusline.separator` (defaults to `"│"`) |

helix-term/src/ui/statusline.rs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,9 @@ 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::PrimarySelectionLength => {
146+
render_primary_selection_length
147+
}
145148
helix_view::editor::StatusLineElement::Position => render_position,
146149
helix_view::editor::StatusLineElement::PositionPercentage => render_position_percentage,
147150
helix_view::editor::StatusLineElement::TotalLineNumbers => render_total_line_numbers,
@@ -254,6 +257,18 @@ where
254257
);
255258
}
256259

260+
fn render_primary_selection_length<F>(context: &mut RenderContext, write: F)
261+
where
262+
F: Fn(&mut RenderContext, String, Option<Style>) + Copy,
263+
{
264+
let tot_sel = context.doc.selection(context.view.id).primary().len();
265+
write(
266+
context,
267+
format!(" {} char{} ", tot_sel, if tot_sel == 1 { "" } else { "s" }),
268+
None,
269+
);
270+
}
271+
257272
fn get_position(context: &RenderContext) -> Position {
258273
coords_at_pos(
259274
context.doc.text().slice(..),

helix-view/src/editor.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -393,6 +393,9 @@ pub enum StatusLineElement {
393393
/// The number of selections (cursors)
394394
Selections,
395395

396+
/// The number of characters currently in primary selection
397+
PrimarySelectionLength,
398+
396399
/// The cursor position
397400
Position,
398401

0 commit comments

Comments
 (0)