2015-04-18 15:16:05 -04:00
|
|
|
#= require mousetrap
|
2014-08-21 04:14:31 -04:00
|
|
|
#= require shortcuts_navigation
|
|
|
|
|
2015-04-18 15:20:15 -04:00
|
|
|
class @ShortcutsIssuable extends ShortcutsNavigation
|
2014-08-21 04:14:31 -04:00
|
|
|
constructor: (isMergeRequest) ->
|
|
|
|
super()
|
|
|
|
Mousetrap.bind('a', ->
|
|
|
|
$('.js-assignee').select2('open')
|
|
|
|
return false
|
|
|
|
)
|
|
|
|
Mousetrap.bind('m', ->
|
|
|
|
$('.js-milestone').select2('open')
|
|
|
|
return false
|
|
|
|
)
|
2015-04-11 18:32:24 -04:00
|
|
|
Mousetrap.bind('r', =>
|
|
|
|
@replyWithSelectedText()
|
|
|
|
return false
|
|
|
|
)
|
|
|
|
|
2014-08-21 04:14:31 -04:00
|
|
|
if isMergeRequest
|
2015-04-11 18:29:25 -04:00
|
|
|
@enabledHelp.push('.hidden-shortcut.merge_requests')
|
2014-08-21 04:14:31 -04:00
|
|
|
else
|
|
|
|
@enabledHelp.push('.hidden-shortcut.issues')
|
|
|
|
|
2015-04-11 18:32:24 -04:00
|
|
|
replyWithSelectedText: ->
|
|
|
|
if window.getSelection
|
|
|
|
selected = window.getSelection().toString()
|
|
|
|
replyField = $('.js-main-target-form #note_note')
|
|
|
|
|
|
|
|
return if selected.trim() == ""
|
|
|
|
|
|
|
|
# Put a '>' character before each non-empty line in the selection
|
|
|
|
quote = _.map selected.split("\n"), (val) ->
|
|
|
|
"> #{val}\n" if val.trim() != ''
|
|
|
|
|
|
|
|
# If replyField already has some content, add a newline before our quote
|
|
|
|
separator = replyField.val().trim() != "" and "\n" or ''
|
|
|
|
|
|
|
|
replyField.val (_, current) ->
|
|
|
|
current + separator + quote.join('') + "\n"
|
|
|
|
|
|
|
|
# Trigger autosave for the added text
|
|
|
|
replyField.trigger('input')
|
|
|
|
|
|
|
|
# Focus the input field
|
|
|
|
replyField.focus()
|