2015-04-18 19:16:05 +00:00
|
|
|
#= require mousetrap
|
2014-08-21 08:14:31 +00:00
|
|
|
#= require shortcuts_navigation
|
|
|
|
|
2015-04-18 19:20:15 +00:00
|
|
|
class @ShortcutsIssuable extends ShortcutsNavigation
|
2014-08-21 08:14:31 +00:00
|
|
|
constructor: (isMergeRequest) ->
|
|
|
|
super()
|
|
|
|
Mousetrap.bind('a', ->
|
2016-01-26 03:34:34 +00:00
|
|
|
$('.block.assignee .edit-link').trigger('click')
|
2014-08-21 08:14:31 +00:00
|
|
|
return false
|
|
|
|
)
|
|
|
|
Mousetrap.bind('m', ->
|
2016-01-26 03:34:34 +00:00
|
|
|
$('.block.milestone .edit-link').trigger('click')
|
2014-08-21 08:14:31 +00:00
|
|
|
return false
|
|
|
|
)
|
2015-04-11 22:32:24 +00:00
|
|
|
Mousetrap.bind('r', =>
|
|
|
|
@replyWithSelectedText()
|
|
|
|
return false
|
|
|
|
)
|
2016-02-05 19:40:50 +00:00
|
|
|
Mousetrap.bind('j', =>
|
|
|
|
@prevIssue()
|
|
|
|
return false
|
|
|
|
)
|
|
|
|
Mousetrap.bind('k', =>
|
|
|
|
@nextIssue()
|
|
|
|
return false
|
|
|
|
)
|
2016-02-23 16:28:23 +00:00
|
|
|
Mousetrap.bind('e', =>
|
|
|
|
@editIssue()
|
|
|
|
return false
|
|
|
|
)
|
2016-02-05 19:40:50 +00:00
|
|
|
|
2015-04-11 22:32:24 +00:00
|
|
|
|
2014-08-21 08:14:31 +00:00
|
|
|
if isMergeRequest
|
2015-04-11 22:29:25 +00:00
|
|
|
@enabledHelp.push('.hidden-shortcut.merge_requests')
|
2014-08-21 08:14:31 +00:00
|
|
|
else
|
|
|
|
@enabledHelp.push('.hidden-shortcut.issues')
|
|
|
|
|
2016-02-05 19:40:50 +00:00
|
|
|
prevIssue: ->
|
|
|
|
$prevBtn = $('.prev-btn')
|
|
|
|
if not $prevBtn.hasClass('disabled')
|
|
|
|
Turbolinks.visit($prevBtn.attr('href'))
|
|
|
|
|
|
|
|
nextIssue: ->
|
|
|
|
$nextBtn = $('.next-btn')
|
|
|
|
if not $nextBtn.hasClass('disabled')
|
|
|
|
Turbolinks.visit($nextBtn.attr('href'))
|
|
|
|
|
2015-04-11 22:32:24 +00: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()
|
2016-02-23 16:28:23 +00:00
|
|
|
|
|
|
|
editIssue: ->
|
|
|
|
$editBtn = $('.issuable-edit')
|
|
|
|
Turbolinks.visit($editBtn.attr('href'))
|