Fix scroll_window not ensuring cursor lies on a codepoint start

Fixes #4839
This commit is contained in:
Maxime Coste 2023-02-14 22:00:12 +11:00
parent 458e3ef20a
commit 0630b4f4f6
4 changed files with 29 additions and 9 deletions

View File

@ -1820,21 +1820,15 @@ void scroll_window(Context& context, LineCount offset, bool mouse_dragging)
SelectionList& selections = context.selections(); SelectionList& selections = context.selections();
Selection& main_selection = selections.main(); Selection& main_selection = selections.main();
const BufferCoord anchor = main_selection.anchor(); const BufferCoord anchor = main_selection.anchor();
const BufferCoord cursor = main_selection.cursor(); const BufferCoordAndTarget cursor = main_selection.cursor();
auto cursor_off = mouse_dragging ? win_pos.line - window.position().line : 0; auto cursor_off = mouse_dragging ? win_pos.line - window.position().line : 0;
auto line = clamp(cursor.line + cursor_off, win_pos.line + scrolloff.line, auto line = clamp(cursor.line + cursor_off, win_pos.line + scrolloff.line,
win_pos.line + win_dim.line - 1 - scrolloff.line); win_pos.line + win_dim.line - 1 - scrolloff.line);
line = clamp(line, 0_line, buffer.line_count() - 1);
using std::min; using std::max; const ColumnCount tabstop = context.options()["tabstop"].get<int>();
// This is not exactly a clamp, and must be done in this order as auto new_cursor = buffer.offset_coord(cursor, line - cursor.line, tabstop);
// byte_count_to could return line length
auto col = min(max(cursor.column, buffer[line].byte_count_to(win_pos.column)),
buffer[line].length()-1);
BufferCoord new_cursor = { line, col };
BufferCoord new_anchor = (mouse_dragging or new_cursor == cursor) ? anchor : new_cursor; BufferCoord new_anchor = (mouse_dragging or new_cursor == cursor) ? anchor : new_cursor;
window.set_position(win_pos); window.set_position(win_pos);

View File

@ -0,0 +1 @@
l<pagedown>

View File

@ -0,0 +1,23 @@
ab
😃
😃
😃
😃
😃
😃
😃
😃
😃
😃
😃
😃
😃
😃
😃
😃
😃
😃
😃
😃
😃
😃

View File

@ -0,0 +1,2 @@
ui_out -ignore 1
ui_out '{ "jsonrpc": "2.0", "method": "draw", "params": [[[{ "face": { "fg": "black", "bg": "white", "underline": "default", "attributes": [] }, "contents": "😃" }, { "face": { "fg": "default", "bg": "default", "underline": "default", "attributes": [] }, "contents": "\u000a" }]], { "fg": "default", "bg": "default", "underline": "default", "attributes": [] }, { "fg": "blue", "bg": "default", "underline": "default", "attributes": [] }] }'