summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDouwe Maan <douwe@selenight.nl>2016-07-04 13:42:42 -0400
committerDouwe Maan <douwe@selenight.nl>2016-07-04 13:42:42 -0400
commit88889d164de2d0fed05ccaee8013dffaa127cd19 (patch)
tree2769eda99d10854615376dba9071db688addbc3a
parent021b6aef94b3398ab5603b4c11afd4c6d8432795 (diff)
downloadgitlab-ce-88889d164de2d0fed05ccaee8013dffaa127cd19.tar.gz
Cancel creating or editing note by hitting Escape
-rw-r--r--app/assets/javascripts/notes.js.coffee25
1 files changed, 20 insertions, 5 deletions
diff --git a/app/assets/javascripts/notes.js.coffee b/app/assets/javascripts/notes.js.coffee
index 17f7e180127..1881162addb 100644
--- a/app/assets/javascripts/notes.js.coffee
+++ b/app/assets/javascripts/notes.js.coffee
@@ -100,13 +100,25 @@ class @Notes
$('.note .js-task-list-container').taskList('disable')
$(document).off 'tasklist:changed', '.note .js-task-list-container'
- keydownNoteText: (e) ->
- $this = $(this)
- if $this.val() is '' and e.which is 38 and not isMetaKey e
+ keydownNoteText: (e) =>
+ return if 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")
if myLastNote.length
myLastNoteEditBtn = myLastNote.find('.js-note-edit')
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) ->
(e.metaKey or e.ctrlKey or e.altKey or e.shiftKey)
@@ -401,9 +413,12 @@ class @Notes
Hides edit form and restores the original note text to the editor textarea.
###
- cancelEdit: (e) ->
+ cancelEdit: (e) =>
e.preventDefault()
- note = $(this).closest(".note")
+ note = $(e.target).closest(".note")
+ @removeNoteEditForm(note)
+
+ removeNoteEditForm: (note) ->
form = note.find(".current-note-edit-form")
note.removeClass "is-editting"
form.removeClass("current-note-edit-form")