Merge pull request #6 from VE-FORBRYDERNE/editable-chunks

More bug fixes for editable chunks
This commit is contained in:
henk717 2021-08-24 19:55:56 +02:00 committed by GitHub
commit 33d76a5132
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 14 additions and 3 deletions

View File

@ -1429,6 +1429,8 @@ def inlinedelete(chunk):
# Don't delete prompt # Don't delete prompt
if(chunk == 0): if(chunk == 0):
# Send error message # Send error message
refresh_story()
emit('from_server', {'cmd': 'errmsg', 'data': "Cannot delete the prompt."})
emit('from_server', {'cmd': 'editmode', 'data': 'false'}, broadcast=True) emit('from_server', {'cmd': 'editmode', 'data': 'false'}, broadcast=True)
else: else:
del vars.actions[chunk-1] del vars.actions[chunk-1]

View File

@ -622,7 +622,9 @@ function setadventure(state) {
function autofocus(event) { function autofocus(event) {
if(connected) { if(connected) {
current_editing_chunk = event.target; if(event.target.tagName == "CHUNK") {
current_editing_chunk = event.target;
}
event.target.focus(); event.target.focus();
} else { } else {
event.preventDefault(); event.preventDefault();
@ -644,11 +646,17 @@ function chunkOnKeyDown(event) {
switch(event.keyCode) { switch(event.keyCode) {
case 37: // left case 37: // left
case 39: // right 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 () { setTimeout(function () {
// Wait a few milliseconds and check if the caret has moved // Wait a few milliseconds and check if the caret has moved
new_selection = getSelection(); 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; return;
} }
// If it hasn't moved, we're at the beginning or end of a chunk // If it hasn't moved, we're at the beginning or end of a chunk
@ -850,6 +858,7 @@ $(document).ready(function(){
}, 5); }, 5);
} }
newly_loaded = false; newly_loaded = false;
hideMessage();
} else if(msg.cmd == "scrolldown") { } else if(msg.cmd == "scrolldown") {
setTimeout(function () { setTimeout(function () {
$('#gamescreen').animate({scrollTop: $('#gamescreen').prop('scrollHeight')}, 1000); $('#gamescreen').animate({scrollTop: $('#gamescreen').prop('scrollHeight')}, 1000);