From 611b189281be85e979d94dfc66a973b793f349fe Mon Sep 17 00:00:00 2001 From: maxwell8888 Date: Thu, 13 Oct 2022 18:54:38 +0100 Subject: [PATCH] Feat: Add setting Cursor Surrounding Lines (#1474) (#1475) This is the minimum number of visible lines above and below the cursor. The default is 1 as per the editors current behavior. --- CHANGELOG.md | 1 + defaults/settings.toml | 1 + lapce-data/src/config.rs | 4 ++++ lapce-ui/src/editor/view.rs | 6 +++++- 4 files changed, 11 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index b9888482..46f47c5e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -46,6 +46,7 @@ - [#1441](https://github.com/lapce/lapce/pull/1441): Button for Case-Sensitive search - [#1471](https://github.com/lapce/lapce/pull/1471): Add command to (un)install Lapce from/to PATH - [#1419](https://github.com/lapce/lapce/pull/1419): Add atomic soft tabs: now you can move your cursor over four spaces as if it was a single block +- [#1475](https://github.com/lapce/lapce/pull/1475): Add editor setting: "Cursor Surrounding Lines" which sets minimum number of lines above and below cursor ### Syntax / Extensions - [#957](https://github.com/lapce/lapce/pull/957): Replace existing tree-sitter syntax highlighting code with part of Helix's better implementation diff --git a/defaults/settings.toml b/defaults/settings.toml index 0e169bbe..ade55000 100644 --- a/defaults/settings.toml +++ b/defaults/settings.toml @@ -13,6 +13,7 @@ tab-width = 4 show-tab = true show-bread-crumbs = true scroll-beyond-last-line = true +cursor-surrounding-lines = 1 sticky-header = true completion-show-documentation = true auto-closing-matching-pairs = true diff --git a/lapce-data/src/config.rs b/lapce-data/src/config.rs index 1fc7b19e..c5b60c6c 100644 --- a/lapce-data/src/config.rs +++ b/lapce-data/src/config.rs @@ -174,6 +174,10 @@ pub struct EditorConfig { pub show_bread_crumbs: bool, #[field_names(desc = "If the editor can scroll beyond the last line")] pub scroll_beyond_last_line: bool, + #[field_names( + desc = "Set the minimum number of visible lines above and below the cursor" + )] + pub cursor_surrounding_lines: usize, #[field_names( desc = "Show code context like functions and classes at the top of editor when scroll" )] diff --git a/lapce-ui/src/editor/view.rs b/lapce-ui/src/editor/view.rs index 622c191f..ccc017d3 100644 --- a/lapce-ui/src/editor/view.rs +++ b/lapce-ui/src/editor/view.rs @@ -526,10 +526,14 @@ fn cursor_region(data: &LapceEditorBufferData, text: &mut PietText) -> Rect { line as f64 * line_height }; + let surrounding_lines_height = + (data.config.editor.cursor_surrounding_lines as f64 * line_height) + .min(data.editor.size.borrow().height / 2.); + Rect::ZERO .with_size(Size::new(width, line_height)) .with_origin(Point::new(cursor_x, y)) - .inflate(width, line_height) + .inflate(width, surrounding_lines_height) } }