Skip to content

Commit cf041a2

Browse files
author
wes adams
committed
Statusline element that shows number of chars in primary selection
Feature request: #4624
1 parent 758bace commit cf041a2

File tree

3 files changed

+15
-0
lines changed

3 files changed

+15
-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: 11 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,14 @@ 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(context, format!(" {} ", tot_sel), None);
266+
}
267+
257268
fn get_position(context: &RenderContext) -> Position {
258269
coords_at_pos(
259270
context.doc.text().slice(..),

helix-view/src/editor.rs

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

331+
/// The number of characters currently in primary selection
332+
PrimarySelectionLength,
333+
331334
/// The cursor position
332335
Position,
333336

0 commit comments

Comments
 (0)