on master help sign in
Statusline indicator to show number of selected chars (#4682)
fd585c1wes adams
book/src/configuration.md+1
@@ -103,6 +103,7 @@ The following statusline elements can be configured:
103| `file-type` | The type of the opened file |
103| `file-type` | The type of the opened file |
104| `diagnostics` | The number of warnings and/or errors |
104| `diagnostics` | The number of warnings and/or errors |
105| `selections` | The number of active selections |
105| `selections` | The number of active selections |
106+| `primary-selection-length` | The number of characters currently in primary selection |
106| `position` | The cursor position |
107| `position` | The cursor position |
107| `position-percentage` | The cursor position as a percentage of the total number of lines |
108| `position-percentage` | The cursor position as a percentage of the total number of lines |
108| `separator` | The string defined in `editor.statusline.separator` (defaults to `"│"`) |
109| `separator` | The string defined in `editor.statusline.separator` (defaults to `"│"`) |
helix-term/src/ui/statusline.rs+15
@@ -142,6 +142,9 @@ where
142 helix_view::editor::StatusLineElement::FileType => render_file_type,
142 helix_view::editor::StatusLineElement::FileType => render_file_type,
143 helix_view::editor::StatusLineElement::Diagnostics => render_diagnostics,
143 helix_view::editor::StatusLineElement::Diagnostics => render_diagnostics,
144 helix_view::editor::StatusLineElement::Selections => render_selections,
144 helix_view::editor::StatusLineElement::Selections => render_selections,
145+ helix_view::editor::StatusLineElement::PrimarySelectionLength => {
146+ render_primary_selection_length
147+ }
145 helix_view::editor::StatusLineElement::Position => render_position,
148 helix_view::editor::StatusLineElement::Position => render_position,
146 helix_view::editor::StatusLineElement::PositionPercentage => render_position_percentage,
149 helix_view::editor::StatusLineElement::PositionPercentage => render_position_percentage,
147 helix_view::editor::StatusLineElement::TotalLineNumbers => render_total_line_numbers,
150 helix_view::editor::StatusLineElement::TotalLineNumbers => render_total_line_numbers,
@@ -254,6 +257,18 @@ where
254 );
257 );
255}
258}
256
259
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+
257fn get_position(context: &RenderContext) -> Position {
272fn get_position(context: &RenderContext) -> Position {
258 coords_at_pos(
273 coords_at_pos(
259 context.doc.text().slice(..),
274 context.doc.text().slice(..),
helix-view/src/editor.rs+3
@@ -328,6 +328,9 @@ pub enum StatusLineElement {
328 /// The number of selections (cursors)
328 /// The number of selections (cursors)
329 Selections,
329 Selections,
330
330
331+ /// The number of characters currently in primary selection
332+ PrimarySelectionLength,
333+
331 /// The cursor position
334 /// The cursor position
332 Position,
335 Position,
333
336