Add undo history once they click the enter or backspace key
This commit is contained in:
parent
ad1d55eb9c
commit
4ba2632c81
1 changed files with 12 additions and 1 deletions
|
@ -102,7 +102,10 @@
|
||||||
$this.data('md-tag')
|
$this.data('md-tag')
|
||||||
)
|
)
|
||||||
|
|
||||||
|
gl.text._previousState = null
|
||||||
|
|
||||||
$(window).on 'keydown', (e) =>
|
$(window).on 'keydown', (e) =>
|
||||||
|
$thisTextarea = $('textarea:focus')
|
||||||
if e.ctrlKey or e.metaKey
|
if e.ctrlKey or e.metaKey
|
||||||
if String.fromCharCode(e.which).toLowerCase() is 'z' and !e.shiftKey
|
if String.fromCharCode(e.which).toLowerCase() is 'z' and !e.shiftKey
|
||||||
e.preventDefault()
|
e.preventDefault()
|
||||||
|
@ -110,6 +113,14 @@
|
||||||
else if ((String.fromCharCode(e.which).toLowerCase() is 'z' and e.shiftKey) or (String.fromCharCode(e.which).toLowerCase() is 'y'))
|
else if ((String.fromCharCode(e.which).toLowerCase() is 'z' and e.shiftKey) or (String.fromCharCode(e.which).toLowerCase() is 'y'))
|
||||||
e.preventDefault()
|
e.preventDefault()
|
||||||
self.undoManager.redo()
|
self.undoManager.redo()
|
||||||
|
else if e.which is 13 or e.which is 8 # enter key or backspace key has been pressed
|
||||||
|
if gl.text._previousState?
|
||||||
|
gl.text.undoManager.addUndo(
|
||||||
|
gl.text._previousState,
|
||||||
|
$thisTextarea.val()
|
||||||
|
)
|
||||||
|
|
||||||
|
gl.text._previousState = $thisTextarea.val()
|
||||||
|
|
||||||
gl.text.removeListeners = () ->
|
gl.text.removeListeners = () ->
|
||||||
$('js-md.btn-bold').off()
|
$('js-md.btn-bold').off()
|
||||||
|
|
Loading…
Reference in a new issue