Fixes #3281 - Removing image in text field with backspaces causes browser to go back
This commit is contained in:
parent
dccd4aa012
commit
e2c4e6316d
1 changed files with 15 additions and 1 deletions
|
@ -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));
|
||||
|
|
Loading…
Reference in a new issue