mirror of
https://github.com/helix-editor/helix.git
synced 2025-01-19 13:37:06 +04:00
feat(helix-view): dynamic line numbers (#1522)
* feat(helix-view): dynamic line numbers * docs: describe editor.line-number in more detail * Make dynamic numbers the default behavior of `relative`
This commit is contained in:
parent
48a0c80652
commit
333c2949c2
@ -34,7 +34,7 @@ ### `[editor]` Section
|
|||||||
| `middle-click-paste` | Middle click paste support. | `true` |
|
| `middle-click-paste` | Middle click paste support. | `true` |
|
||||||
| `scroll-lines` | Number of lines to scroll per scroll wheel step. | `3` |
|
| `scroll-lines` | Number of lines to scroll per scroll wheel step. | `3` |
|
||||||
| `shell` | Shell to use when running external commands. | Unix: `["sh", "-c"]`<br/>Windows: `["cmd", "/C"]` |
|
| `shell` | Shell to use when running external commands. | Unix: `["sh", "-c"]`<br/>Windows: `["cmd", "/C"]` |
|
||||||
| `line-number` | Line number display (`absolute`, `relative`) | `absolute` |
|
| `line-number` | Line number display: `absolute` simply shows each line's number, while `relative` shows the distance from the current line. When unfocused or in insert mode, `relative` will still show absolute line numbers. | `absolute` |
|
||||||
| `smart-case` | Enable smart case regex searching (case insensitive unless pattern contains upper case characters) | `true` |
|
| `smart-case` | Enable smart case regex searching (case insensitive unless pattern contains upper case characters) | `true` |
|
||||||
| `auto-pairs` | Enable automatic insertion of pairs to parenthese, brackets, etc. | `true` |
|
| `auto-pairs` | Enable automatic insertion of pairs to parenthese, brackets, etc. | `true` |
|
||||||
| `auto-completion` | Enable automatic pop up of auto-completion. | `true` |
|
| `auto-completion` | Enable automatic pop up of auto-completion. | `true` |
|
||||||
|
@ -170,7 +170,9 @@ fn default() -> Self {
|
|||||||
pub enum LineNumber {
|
pub enum LineNumber {
|
||||||
/// Show absolute line number
|
/// Show absolute line number
|
||||||
Absolute,
|
Absolute,
|
||||||
/// Show relative line number to the primary cursor
|
|
||||||
|
/// If focused and in normal/select mode, show relative line number to the primary cursor.
|
||||||
|
/// If unfocused or in insert mode, show absolute line number.
|
||||||
Relative,
|
Relative,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -58,29 +58,31 @@ pub fn line_number<'doc>(
|
|||||||
.char_to_line(doc.selection(view.id).primary().cursor(text));
|
.char_to_line(doc.selection(view.id).primary().cursor(text));
|
||||||
|
|
||||||
let config = config.line_number;
|
let config = config.line_number;
|
||||||
|
let mode = doc.mode;
|
||||||
|
|
||||||
Box::new(move |line: usize, selected: bool, out: &mut String| {
|
Box::new(move |line: usize, selected: bool, out: &mut String| {
|
||||||
if line == last_line && !draw_last {
|
if line == last_line && !draw_last {
|
||||||
write!(out, "{:>1$}", '~', width).unwrap();
|
write!(out, "{:>1$}", '~', width).unwrap();
|
||||||
Some(linenr)
|
Some(linenr)
|
||||||
} else {
|
} else {
|
||||||
use crate::editor::LineNumber;
|
use crate::{document::Mode, editor::LineNumber};
|
||||||
let line = match config {
|
|
||||||
LineNumber::Absolute => line + 1,
|
let relative = config == LineNumber::Relative
|
||||||
LineNumber::Relative => {
|
&& mode != Mode::Insert
|
||||||
if current_line == line {
|
&& is_focused
|
||||||
line + 1
|
&& current_line != line;
|
||||||
} else {
|
|
||||||
abs_diff(current_line, line)
|
let display_num = if relative {
|
||||||
}
|
abs_diff(current_line, line)
|
||||||
}
|
} else {
|
||||||
|
line + 1
|
||||||
};
|
};
|
||||||
let style = if selected && is_focused {
|
let style = if selected && is_focused {
|
||||||
linenr_select
|
linenr_select
|
||||||
} else {
|
} else {
|
||||||
linenr
|
linenr
|
||||||
};
|
};
|
||||||
write!(out, "{:>1$}", line, width).unwrap();
|
write!(out, "{:>1$}", display_num, width).unwrap();
|
||||||
Some(style)
|
Some(style)
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
Loading…
Reference in New Issue
Block a user