Fix left/right arrow key bug

This happens when you have a chunk that has no trailing
newlines followed by a chunk with a single newline at the start.
Moving between those chunks would cause the caret to jump to the wrong
position sometimes.
This commit is contained in:
Gnome Ann 2021-08-24 13:32:29 -04:00
parent 90e558cf3f
commit ce59c9d399
1 changed files with 8 additions and 2 deletions

View File

@ -646,11 +646,17 @@ function chunkOnKeyDown(event) {
switch(event.keyCode) {
case 37: // left
case 39: // right
old_selection_offset = getSelection().focusOffset;
old_range = getSelection().getRangeAt(0);
old_range_start = old_range.startOffset;
old_range_end = old_range.endOffset;
old_range_ancestor = old_range.commonAncestorContainer;
old_range_start_container = old_range.startContainer;
old_range_end_container = old_range.endContainer;
setTimeout(function () {
// Wait a few milliseconds and check if the caret has moved
new_selection = getSelection();
if(old_selection_offset != new_selection.focusOffset) {
new_range = new_selection.getRangeAt(0);
if(old_range_start != new_range.startOffset || old_range_end != new_range.endOffset || old_range_ancestor != new_range.commonAncestorContainer || old_range_start_container != new_range.startContainer || old_range_end_container != new_range.endContainer) {
return;
}
// If it hasn't moved, we're at the beginning or end of a chunk