Allow using left and right arrow keys to move between chunks

This commit is contained in:
Gnome Ann 2021-08-23 18:00:35 -04:00
parent 85151cec7b
commit 3c9f6963b8
1 changed files with 36 additions and 2 deletions

View File

@ -635,11 +635,45 @@ function chunkOnKeyDown(event) {
if(event.keyCode == 27 || (!event.shiftKey && event.keyCode == 13)) {
setTimeout(function () {
event.target.blur();
}, 5);
}, 25);
event.preventDefault();
return;
}
// Allow left and right arrow keys to move between chunks
switch(event.keyCode) {
case 37: // left
case 39: // right
old_selection_offset = getSelection().focusOffset;
setTimeout(function () {
// Wait a few milliseconds and check if the caret has moved
new_selection = getSelection();
if(old_selection_offset != new_selection.focusOffset) {
return;
}
// If it hasn't moved, we're at the beginning or end of a chunk
// and the caret must be moved to a different chunk
chunk = document.activeElement;
switch(event.keyCode) {
case 37: // left
if((chunk = chunk.previousSibling) && chunk.tagName == "CHUNK") {
range = document.createRange();
range.selectNodeContents(chunk);
range.collapse(false);
new_selection.removeAllRanges();
new_selection.addRange(range);
}
break;
case 39: // right
if((chunk = chunk.nextSibling) && chunk.tagName == "CHUNK") {
chunk.focus();
}
}
}, 2);
return;
}
// Don't allow any edits if not connected to server
if(!connected) {
event.preventDefault();
@ -674,7 +708,7 @@ function submitEditedChunk(event) {
if(document.activeElement.tagName == "CHUNK") {
document.activeElement.blur();
}
}, 5);
}, 25);
current_chunk_changed = false;
// Enter edit mode if we aren't already in edit mode