2017-08-17 22:00:37 +05:30
|
|
|
/* eslint-disable func-names, space-before-function-paren, max-len, no-var, one-var, no-restricted-syntax, vars-on-top, no-use-before-define, no-param-reassign, new-cap, no-underscore-dangle, wrap-iife, one-var-declaration-per-line, quotes, prefer-arrow-callback, consistent-return, prefer-template, no-mixed-operators */
|
|
|
|
/* global Mousetrap */
|
|
|
|
/* global ShortcutsNavigation */
|
|
|
|
/* global sidebar */
|
2016-09-13 17:45:13 +05:30
|
|
|
|
2017-09-10 17:25:29 +05:30
|
|
|
import _ from 'underscore';
|
|
|
|
import 'mousetrap';
|
|
|
|
import './shortcuts_navigation';
|
2016-09-13 17:45:13 +05:30
|
|
|
|
|
|
|
(function() {
|
|
|
|
var extend = function(child, parent) { for (var key in parent) { if (hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; },
|
|
|
|
hasProp = {}.hasOwnProperty;
|
|
|
|
|
|
|
|
this.ShortcutsIssuable = (function(superClass) {
|
|
|
|
extend(ShortcutsIssuable, superClass);
|
|
|
|
|
|
|
|
function ShortcutsIssuable(isMergeRequest) {
|
|
|
|
ShortcutsIssuable.__super__.constructor.call(this);
|
|
|
|
Mousetrap.bind('a', this.openSidebarDropdown.bind(this, 'assignee'));
|
|
|
|
Mousetrap.bind('m', this.openSidebarDropdown.bind(this, 'milestone'));
|
|
|
|
Mousetrap.bind('r', (function(_this) {
|
|
|
|
return function() {
|
|
|
|
_this.replyWithSelectedText();
|
|
|
|
return false;
|
|
|
|
};
|
|
|
|
})(this));
|
|
|
|
Mousetrap.bind('e', (function(_this) {
|
|
|
|
return function() {
|
|
|
|
_this.editIssue();
|
|
|
|
return false;
|
|
|
|
};
|
|
|
|
})(this));
|
|
|
|
Mousetrap.bind('l', this.openSidebarDropdown.bind(this, 'labels'));
|
|
|
|
if (isMergeRequest) {
|
|
|
|
this.enabledHelp.push('.hidden-shortcut.merge_requests');
|
|
|
|
} else {
|
|
|
|
this.enabledHelp.push('.hidden-shortcut.issues');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
ShortcutsIssuable.prototype.replyWithSelectedText = function() {
|
2017-09-10 17:25:29 +05:30
|
|
|
var quote, documentFragment, el, selected, separator;
|
2017-08-17 22:00:37 +05:30
|
|
|
var replyField = $('.js-main-target-form #note_note');
|
|
|
|
|
|
|
|
documentFragment = window.gl.utils.getSelectedFragment();
|
|
|
|
if (!documentFragment) {
|
|
|
|
replyField.focus();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2017-09-10 17:25:29 +05:30
|
|
|
el = window.gl.CopyAsGFM.transformGFMSelection(documentFragment.cloneNode(true));
|
|
|
|
selected = window.gl.CopyAsGFM.nodeToGFM(el);
|
2017-08-17 22:00:37 +05:30
|
|
|
|
|
|
|
if (selected.trim() === "") {
|
|
|
|
return;
|
2016-09-13 17:45:13 +05:30
|
|
|
}
|
2017-08-17 22:00:37 +05:30
|
|
|
quote = _.map(selected.split("\n"), function(val) {
|
|
|
|
return ("> " + val).trim() + "\n";
|
|
|
|
});
|
|
|
|
// If replyField already has some content, add a newline before our quote
|
|
|
|
separator = replyField.val().trim() !== "" && "\n\n" || '';
|
2017-09-10 17:25:29 +05:30
|
|
|
replyField.val(function(a, current) {
|
2017-08-17 22:00:37 +05:30
|
|
|
return current + separator + quote.join('') + "\n";
|
|
|
|
});
|
|
|
|
|
|
|
|
// Trigger autosave
|
|
|
|
replyField.trigger('input');
|
|
|
|
|
|
|
|
// Trigger autosize
|
|
|
|
var event = document.createEvent('Event');
|
|
|
|
event.initEvent('autosize:update', true, false);
|
|
|
|
replyField.get(0).dispatchEvent(event);
|
|
|
|
|
|
|
|
// Focus the input field
|
|
|
|
return replyField.focus();
|
2016-09-13 17:45:13 +05:30
|
|
|
};
|
|
|
|
|
|
|
|
ShortcutsIssuable.prototype.editIssue = function() {
|
|
|
|
var $editBtn;
|
|
|
|
$editBtn = $('.issuable-edit');
|
2017-09-10 17:25:29 +05:30
|
|
|
// Need to click the element as on issues, editing is inline
|
|
|
|
// on merge request, editing is on a different page
|
|
|
|
$editBtn.get(0).click();
|
2016-09-13 17:45:13 +05:30
|
|
|
};
|
|
|
|
|
|
|
|
ShortcutsIssuable.prototype.openSidebarDropdown = function(name) {
|
|
|
|
sidebar.openDropdown(name);
|
|
|
|
return false;
|
|
|
|
};
|
|
|
|
|
|
|
|
return ShortcutsIssuable;
|
|
|
|
})(ShortcutsNavigation);
|
2017-08-17 22:00:37 +05:30
|
|
|
}).call(window);
|