From ce59c9d399b1e0d1d19049a084a30012738ade44 Mon Sep 17 00:00:00 2001 From: Gnome Ann <> Date: Tue, 24 Aug 2021 13:32:29 -0400 Subject: [PATCH] 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. --- static/application.js | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/static/application.js b/static/application.js index 39d5447e..6626f24f 100644 --- a/static/application.js +++ b/static/application.js @@ -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