Commit 88889d16 authored by Douwe Maan's avatar Douwe Maan

Cancel creating or editing note by hitting Escape

parent 021b6aef
...@@ -100,13 +100,25 @@ class @Notes ...@@ -100,13 +100,25 @@ class @Notes
$('.note .js-task-list-container').taskList('disable') $('.note .js-task-list-container').taskList('disable')
$(document).off 'tasklist:changed', '.note .js-task-list-container' $(document).off 'tasklist:changed', '.note .js-task-list-container'
keydownNoteText: (e) -> keydownNoteText: (e) =>
$this = $(this) return if isMetaKey e
if $this.val() is '' and e.which is 38 and not isMetaKey e
$textarea = $(e.target)
if $textarea.val() is '' and e.which is 38
myLastNote = $("li.note[data-author-id='#{gon.current_user_id}'][data-editable]:last") myLastNote = $("li.note[data-author-id='#{gon.current_user_id}'][data-editable]:last")
if myLastNote.length if myLastNote.length
myLastNoteEditBtn = myLastNote.find('.js-note-edit') myLastNoteEditBtn = myLastNote.find('.js-note-edit')
myLastNoteEditBtn.trigger('click', [true, myLastNote]) myLastNoteEditBtn.trigger('click', [true, myLastNote])
if e.which is 27
discussionNoteForm = $textarea.closest(".js-discussion-note-form")
if discussionNoteForm.length
@removeDiscussionNoteForm(discussionNoteForm)
return
editNote = $textarea.closest(".note")
if editNote.length
@removeNoteEditForm(editNote)
isMetaKey = (e) -> isMetaKey = (e) ->
(e.metaKey or e.ctrlKey or e.altKey or e.shiftKey) (e.metaKey or e.ctrlKey or e.altKey or e.shiftKey)
...@@ -401,9 +413,12 @@ class @Notes ...@@ -401,9 +413,12 @@ class @Notes
Hides edit form and restores the original note text to the editor textarea. Hides edit form and restores the original note text to the editor textarea.
### ###
cancelEdit: (e) -> cancelEdit: (e) =>
e.preventDefault() e.preventDefault()
note = $(this).closest(".note") note = $(e.target).closest(".note")
@removeNoteEditForm(note)
removeNoteEditForm: (note) ->
form = note.find(".current-note-edit-form") form = note.find(".current-note-edit-form")
note.removeClass "is-editting" note.removeClass "is-editting"
form.removeClass("current-note-edit-form") form.removeClass("current-note-edit-form")
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment