Fixes #3281 - Removing image in text field with backspaces causes browser to go back

This commit is contained in:
Mantas 2020-11-15 10:54:59 +02:00 committed by Thorsten Eckel
parent dccd4aa012
commit e2c4e6316d

View file

@ -87,11 +87,25 @@
}
Editor.prototype.onKeydown = function (event) {
var elem = this.$element.closest('[contenteditable=true]')
var previous = this.$element.parent().parent().prev()
this.destroy()
switch (event.keyCode) {
case 8: // backspace
this.$element.remove()
event.preventDefault()
if(previous[0]){
range = document.createRange()
range.selectNode(previous[0])
range.setStart(range.endContainer, range.endOffset)
document.getSelection().removeAllRanges()
document.getSelection().addRange(range)
}
elem.focus()
break
default:
event.stopPropagation()
@ -173,4 +187,4 @@
});
}
}(jQuery, window));
}(jQuery, window));