mirror of
https://github.com/helix-editor/helix.git
synced 2024-11-22 01:16:18 +04:00
add position-percentage as a statusline indicator (#3168)
* added position-pct as a statusline indicator * removed unnecessary mutable reference * pct -> percent * percent -> percentage
This commit is contained in:
parent
de8ade8967
commit
3dd2196e4f
@ -78,6 +78,7 @@ ### `[editor.statusline]` Section
|
||||
| `diagnostics` | The number of warnings and/or errors |
|
||||
| `selections` | The number of active selections |
|
||||
| `position` | The cursor position |
|
||||
| `position-percentage` | The cursor position as a percentage of the total number of lines |
|
||||
| `spacer` | Inserts a space between elements (multiple/contiguous spacers may be specified) |
|
||||
|
||||
### `[editor.lsp]` Section
|
||||
|
@ -1,4 +1,4 @@
|
||||
use helix_core::{coords_at_pos, encoding};
|
||||
use helix_core::{coords_at_pos, encoding, Position};
|
||||
use helix_view::{
|
||||
document::{Mode, SCRATCH_BUFFER_NAME},
|
||||
graphics::Rect,
|
||||
@ -143,6 +143,7 @@ fn get_render_function<F>(element_id: StatusLineElementID) -> impl Fn(&mut Rende
|
||||
helix_view::editor::StatusLineElement::Diagnostics => render_diagnostics,
|
||||
helix_view::editor::StatusLineElement::Selections => render_selections,
|
||||
helix_view::editor::StatusLineElement::Position => render_position,
|
||||
helix_view::editor::StatusLineElement::PositionPercentage => render_position_percentage,
|
||||
helix_view::editor::StatusLineElement::Spacer => render_spacer,
|
||||
}
|
||||
}
|
||||
@ -251,19 +252,22 @@ fn render_selections<F>(context: &mut RenderContext, write: F)
|
||||
);
|
||||
}
|
||||
|
||||
fn render_position<F>(context: &mut RenderContext, write: F)
|
||||
where
|
||||
F: Fn(&mut RenderContext, String, Option<Style>) + Copy,
|
||||
{
|
||||
let position = coords_at_pos(
|
||||
fn get_position(context: &RenderContext) -> Position {
|
||||
coords_at_pos(
|
||||
context.doc.text().slice(..),
|
||||
context
|
||||
.doc
|
||||
.selection(context.view.id)
|
||||
.primary()
|
||||
.cursor(context.doc.text().slice(..)),
|
||||
);
|
||||
)
|
||||
}
|
||||
|
||||
fn render_position<F>(context: &mut RenderContext, write: F)
|
||||
where
|
||||
F: Fn(&mut RenderContext, String, Option<Style>) + Copy,
|
||||
{
|
||||
let position = get_position(context);
|
||||
write(
|
||||
context,
|
||||
format!(" {}:{} ", position.row + 1, position.col + 1),
|
||||
@ -271,6 +275,19 @@ fn render_position<F>(context: &mut RenderContext, write: F)
|
||||
);
|
||||
}
|
||||
|
||||
fn render_position_percentage<F>(context: &mut RenderContext, write: F)
|
||||
where
|
||||
F: Fn(&mut RenderContext, String, Option<Style>) + Copy,
|
||||
{
|
||||
let position = get_position(context);
|
||||
let maxrows = context.doc.text().len_lines();
|
||||
write(
|
||||
context,
|
||||
format!("{}%", (position.row + 1) * 100 / maxrows),
|
||||
None,
|
||||
);
|
||||
}
|
||||
|
||||
fn render_file_encoding<F>(context: &mut RenderContext, write: F)
|
||||
where
|
||||
F: Fn(&mut RenderContext, String, Option<Style>) + Copy,
|
||||
|
@ -247,6 +247,8 @@ pub enum StatusLineElement {
|
||||
/// The cursor position
|
||||
Position,
|
||||
|
||||
/// The cursor position as a percent of the total file
|
||||
PositionPercentage,
|
||||
/// A single space
|
||||
Spacer,
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user