diff options
Diffstat (limited to 'static/panes/editor.js')
-rw-r--r-- | static/panes/editor.js | 71 |
1 files changed, 53 insertions, 18 deletions
diff --git a/static/panes/editor.js b/static/panes/editor.js index 677542a0c..bc4b29ee4 100644 --- a/static/panes/editor.js +++ b/static/panes/editor.js @@ -469,23 +469,7 @@ Editor.prototype.initButtons = function (state) { this.initLoadSaver(); $(this.domRoot).on('keydown', _.bind(function (event) { if ((event.ctrlKey || event.metaKey) && String.fromCharCode(event.which).toLowerCase() === 's') { - event.preventDefault(); - if (this.settings.enableCtrlStree && this.hub.hasTree()) { - var trees = this.hub.trees; - // todo: change when multiple trees are used - if (trees && trees.length > 0) { - trees[0].multifileService.includeByEditorId(this.id).then(_.bind(function () { - trees[0].refresh(); - }, this)); - } - } else if (this.settings.enableCtrlS) { - loadSave.setMinimalOptions(this.getSource(), this.currentLanguage); - if (!loadSave.onSaveToFile(this.id)) { - this.showLoadSaver(); - } - } else { - this.eventHub.emit('displaySharingPopover'); - } + this.handleCtrlS(event); } }, this)); @@ -505,6 +489,53 @@ Editor.prototype.initButtons = function (state) { this.currentCursorPosition.hide(); }; +Editor.prototype.handleCtrlS = function (event) { + event.preventDefault(); + if (this.settings.enableCtrlStree && this.hub.hasTree()) { + var trees = this.hub.trees; + // todo: change when multiple trees are used + if (trees && trees.length > 0) { + trees[0].multifileService.includeByEditorId(this.id).then(_.bind(function () { + trees[0].refresh(); + }, this)); + } + } else { + if (this.settings.enableCtrlS === 'true') { + loadSave.setMinimalOptions(this.getSource(), this.currentLanguage); + if (!loadSave.onSaveToFile(this.id)) { + this.showLoadSaver(); + } + } else if (this.settings.enableCtrlS === 'false') { + this.eventHub.emit('displaySharingPopover'); + } else if (this.settings.enableCtrlS === '2') { + this.runFormatDocumentAction(); + } else if (this.settings.enableCtrlS === '3') { + this.handleCtrlSDoNothing(); + } + } +}; + +Editor.prototype.handleCtrlSDoNothing = function () { + if (this.nothingCtrlSTimes === undefined) { + this.nothingCtrlSTimes = 0; + this.nothingCtrlSSince = Date.now(); + } else { + if (Date.now() - this.nothingCtrlSSince > 5000) { + this.nothingCtrlSTimes = undefined; + } else if (this.nothingCtrlSTimes === 4) { + var element = this.domRoot.find('.ctrlSNothing'); + element.show(100); + setTimeout(function () { + element.hide(); + }, 2000); + this.nothingCtrlSTimes = undefined; + } else { + this.nothingCtrlSTimes++; + } + } + +}; + Editor.prototype.updateButtons = function () { if (options.thirdPartyIntegrationEnabled) { if (this.currentLanguage.id === 'c++') { @@ -787,7 +818,7 @@ Editor.prototype.initEditorActions = function () { }); this.editor.addCommand(monaco.KeyMod.CtrlCmd | monaco.KeyCode.F9, _.bind(function () { - this.editor.getAction('editor.action.formatDocument').run(); + this.runFormatDocumentAction(); }, this)); this.editor.addCommand(monaco.KeyMod.CtrlCmd | monaco.KeyCode.KeyD, _.bind(function () { @@ -795,6 +826,10 @@ Editor.prototype.initEditorActions = function () { }, this)); }; +Editor.prototype.runFormatDocumentAction = function () { + this.editor.getAction('editor.action.formatDocument').run(); +}; + Editor.prototype.searchOnCppreference = function (ed) { var pos = ed.getPosition(); var word = ed.getModel().getWordAtPosition(pos); |