From 20a2bca52e0d159cdbab4ff6d38024cd1503a4f5 Mon Sep 17 00:00:00 2001 From: Maxime Coste Date: Sun, 27 Aug 2023 08:05:46 +1000 Subject: 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 `` / `` commands still move the cursor as this seemed a desired behaviour. --- src/input_handler.cc | 37 +++++++++++++++++++++---------------- 1 file changed, 21 insertions(+), 16 deletions(-) (limited to 'src/input_handler.cc') diff --git a/src/input_handler.cc b/src/input_handler.cc index 66d30391..a5c88a21 100644 --- a/src/input_handler.cc +++ b/src/input_handler.cc @@ -180,7 +180,7 @@ struct MouseHandler } case Key::Modifiers::Scroll: - scroll_window(context, static_cast(key.key), (bool)m_dragging); + scroll_window(context, static_cast(key.key), m_dragging ? OnHiddenCursor::MoveCursor : OnHiddenCursor::PreserveSelections); return true; default: return false; @@ -1852,7 +1852,7 @@ void hide_auto_info_ifn(const Context& context, bool hide) context.client().info_hide(); } -void scroll_window(Context& context, LineCount offset, bool mouse_dragging) +void scroll_window(Context& context, LineCount offset, OnHiddenCursor on_hidden_cursor) { Window& window = context.window(); Buffer& buffer = context.buffer(); @@ -1861,6 +1861,9 @@ void scroll_window(Context& context, LineCount offset, bool mouse_dragging) DisplayCoord win_pos = window.position(); DisplayCoord win_dim = window.dimensions(); + if (on_hidden_cursor == OnHiddenCursor::PreserveSelections) + context.ensure_cursor_visible = false; + if ((offset < 0 and win_pos.line == 0) or (offset > 0 and win_pos.line == line_count - 1)) return; @@ -1870,25 +1873,27 @@ void scroll_window(Context& context, LineCount offset, bool mouse_dragging) win_pos.line = clamp(win_pos.line + offset, 0_line, line_count-1); - ScopedSelectionEdition selection_edition{context}; - SelectionList& selections = context.selections(); - Selection& main_selection = selections.main(); - const BufferCoord anchor = main_selection.anchor(); - const BufferCoordAndTarget cursor = main_selection.cursor(); + window.set_position(win_pos); + if (on_hidden_cursor != OnHiddenCursor::PreserveSelections) + { + ScopedSelectionEdition selection_edition{context}; + SelectionList& selections = context.selections(); + Selection& main_selection = selections.main(); + const BufferCoord anchor = main_selection.anchor(); + const BufferCoordAndTarget cursor = main_selection.cursor(); - auto cursor_off = mouse_dragging ? win_pos.line - window.position().line : 0; + auto cursor_off = win_pos.line - window.position().line; - auto line = clamp(cursor.line + cursor_off, win_pos.line + scrolloff.line, - win_pos.line + win_dim.line - 1 - scrolloff.line); + auto line = clamp(cursor.line + cursor_off, win_pos.line + scrolloff.line, + win_pos.line + win_dim.line - 1 - scrolloff.line); - const ColumnCount tabstop = context.options()["tabstop"].get(); - auto new_cursor = buffer.offset_coord(cursor, line - cursor.line, tabstop); - BufferCoord new_anchor = (mouse_dragging or new_cursor == cursor) ? anchor : new_cursor; + const ColumnCount tabstop = context.options()["tabstop"].get(); + auto new_cursor = buffer.offset_coord(cursor, line - cursor.line, tabstop); - window.set_position(win_pos); - main_selection = { new_anchor, new_cursor }; + main_selection = {on_hidden_cursor == OnHiddenCursor::MoveCursor ? anchor : new_cursor, new_cursor}; - selections.sort_and_merge_overlapping(); + selections.sort_and_merge_overlapping(); + } } } -- cgit v1.2.3