on master help sign in
Statusline indicator to show number of selected chars (#4682)

Co-authored-by: wes adams <wadams@grayshift.com>

commitfd585c1ee4ae0ac541f99b5e69a40833f5e3246d authorwes adams <wes-adams@users.noreply.github.com> dateSat 12 Nov 2022, 12:31 (4 years ago) parent1f72d34
3 files changed+19
book/src/configuration.md+1 helix-term/src/ui/statusline.rs+15 helix-view/src/editor.rs+3
book/src/configuration.md+1
@@ -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+15
@@ -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+
257272fn get_position(context: &RenderContext) -> Position {
258273 coords_at_pos(
259274 context.doc.text().slice(..),
helix-view/src/editor.rs+3
@@ -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