|
1 |
| -use helix_core::{coords_at_pos, encoding}; |
| 1 | +use helix_core::{coords_at_pos, encoding, Position}; |
2 | 2 | use helix_view::{
|
3 | 3 | document::{Mode, SCRATCH_BUFFER_NAME},
|
4 | 4 | graphics::Rect,
|
@@ -143,6 +143,7 @@ where
|
143 | 143 | helix_view::editor::StatusLineElement::Diagnostics => render_diagnostics,
|
144 | 144 | helix_view::editor::StatusLineElement::Selections => render_selections,
|
145 | 145 | helix_view::editor::StatusLineElement::Position => render_position,
|
| 146 | + helix_view::editor::StatusLineElement::PositionPercentage => render_position_percentage, |
146 | 147 | helix_view::editor::StatusLineElement::Spacer => render_spacer,
|
147 | 148 | }
|
148 | 149 | }
|
@@ -251,26 +252,42 @@ where
|
251 | 252 | );
|
252 | 253 | }
|
253 | 254 |
|
254 |
| -fn render_position<F>(context: &mut RenderContext, write: F) |
255 |
| -where |
256 |
| - F: Fn(&mut RenderContext, String, Option<Style>) + Copy, |
257 |
| -{ |
258 |
| - let position = coords_at_pos( |
| 255 | +fn get_position(context: &RenderContext) -> Position { |
| 256 | + coords_at_pos( |
259 | 257 | context.doc.text().slice(..),
|
260 | 258 | context
|
261 | 259 | .doc
|
262 | 260 | .selection(context.view.id)
|
263 | 261 | .primary()
|
264 | 262 | .cursor(context.doc.text().slice(..)),
|
265 |
| - ); |
| 263 | + ) |
| 264 | +} |
266 | 265 |
|
| 266 | +fn render_position<F>(context: &mut RenderContext, write: F) |
| 267 | +where |
| 268 | + F: Fn(&mut RenderContext, String, Option<Style>) + Copy, |
| 269 | +{ |
| 270 | + let position = get_position(context); |
267 | 271 | write(
|
268 | 272 | context,
|
269 | 273 | format!(" {}:{} ", position.row + 1, position.col + 1),
|
270 | 274 | None,
|
271 | 275 | );
|
272 | 276 | }
|
273 | 277 |
|
| 278 | +fn render_position_percentage<F>(context: &mut RenderContext, write: F) |
| 279 | +where |
| 280 | + F: Fn(&mut RenderContext, String, Option<Style>) + Copy, |
| 281 | +{ |
| 282 | + let position = get_position(context); |
| 283 | + let maxrows = context.doc.text().len_lines(); |
| 284 | + write( |
| 285 | + context, |
| 286 | + format!("{}%", (position.row + 1) * 100 / maxrows), |
| 287 | + None, |
| 288 | + ); |
| 289 | +} |
| 290 | + |
274 | 291 | fn render_file_encoding<F>(context: &mut RenderContext, write: F)
|
275 | 292 | where
|
276 | 293 | F: Fn(&mut RenderContext, String, Option<Style>) + Copy,
|
|
0 commit comments