diff options
| author | Maxime Coste <mawww@kakoune.org> | 2023-08-27 08:05:46 +1000 |
|---|---|---|
| committer | Maxime Coste <mawww@kakoune.org> | 2023-09-02 12:55:57 +1000 |
| commit | 20a2bca52e0d159cdbab4ff6d38024cd1503a4f5 (patch) | |
| tree | a019bb44362357ddf4ca8db4a17c576528825100 /src/window.cc | |
| parent | 699027000551f04ce9f3e532d20c6e484ca7a945 (diff) | |
Do not make cursor visible after mouse scrolling and view commands
ensure cursor is visible after user input except if the command
implementation opted-out. Hooks and timers should not enforce
visible cursor.
PageUp/PageDown and `<c-f>` / `<c-b>` commands still move the cursor
as this seemed a desired behaviour.
Diffstat (limited to 'src/window.cc')
| -rw-r--r-- | src/window.cc | 17 |
1 files changed, 11 insertions, 6 deletions
diff --git a/src/window.cc b/src/window.cc index 757723d2..b660bbdb 100644 --- a/src/window.cc +++ b/src/window.cc @@ -202,11 +202,14 @@ DisplaySetup Window::compute_display_setup(const Context& context) const const int tabstop = context.options()["tabstop"].get<int>(); const auto& cursor = context.selections().main().cursor(); - // Ensure cursor line is visible - if (cursor.line - offset.line < win_pos.line) - win_pos.line = std::max(0_line, cursor.line - offset.line); - if (cursor.line + offset.line >= win_pos.line + m_dimensions.line) - win_pos.line = std::min(buffer().line_count()-1, cursor.line + offset.line - m_dimensions.line + 1); + bool ensure_cursor_visible = context.ensure_cursor_visible; + if (ensure_cursor_visible) + { + if (cursor.line - offset.line < win_pos.line) + win_pos.line = std::max(0_line, cursor.line - offset.line); + if (cursor.line + offset.line >= win_pos.line + m_dimensions.line) + win_pos.line = std::min(buffer().line_count()-1, cursor.line + offset.line - m_dimensions.line + 1); + } DisplaySetup setup{ win_pos.line, @@ -215,13 +218,15 @@ DisplaySetup Window::compute_display_setup(const Context& context) const 0_col, {cursor.line - win_pos.line, get_column(buffer(), tabstop, cursor) - win_pos.column}, - offset + offset, + ensure_cursor_visible }; for (auto pass : { HighlightPass::Move, HighlightPass::Wrap }) m_builtin_highlighters.compute_display_setup({context, setup, pass, {}}, setup); check_display_setup(setup, *this); // now ensure the cursor column is visible + if (ensure_cursor_visible) { auto underflow = std::max(-setup.first_column, setup.cursor_pos.column - setup.scroll_offset.column); |
