aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRubén Rincón Blanco <ruben@rinconblanco.es>2022-01-24 12:41:59 +0000
committerGitHub <noreply@github.com>2022-01-24 12:41:59 +0000
commitfd8e9e656ee9f555de357acf06ad0053e104e07b (patch)
tree2efc72f4d343c1002637a55aeb117a8505bba03d
parented8b6123835b9ffdc9f159c336ad5ba0ccd44842 (diff)
parent2ed9ab8e12e23fc929be850e4b98d037da10d2e6 (diff)
downloadcompiler-explorer-gh-1687.tar.gz
compiler-explorer-gh-1687.zip
Merge 2ed9ab8e12e23fc929be850e4b98d037da10d2e6 into ed8b6123835b9ffdc9f159c336ad5ba0ccd44842gh-1687
-rw-r--r--static/explorer.scss2
-rw-r--r--static/panes/editor.js71
-rw-r--r--static/settings.interfaces.ts2
-rw-r--r--static/settings.js8
-rw-r--r--views/popups.pug7
-rw-r--r--views/templates.pug2
6 files changed, 67 insertions, 25 deletions
diff --git a/static/explorer.scss b/static/explorer.scss
index 75a7aeb14..2ef1892b6 100644
--- a/static/explorer.scss
+++ b/static/explorer.scss
@@ -862,7 +862,7 @@ html[data-theme=dark] {
cursor: pointer;
}
-.currentCursorPosition {
+.currentCursorPosition, .ctrlSNothing {
font-size: small;
border: none;
user-select: text;
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);
diff --git a/static/settings.interfaces.ts b/static/settings.interfaces.ts
index d5043d8a8..c2e9f5461 100644
--- a/static/settings.interfaces.ts
+++ b/static/settings.interfaces.ts
@@ -52,7 +52,7 @@ export interface SiteSettings {
delayAfterChange: number;
enableCodeLens: boolean;
enableCommunityAds: boolean
- enableCtrlS: boolean;
+ enableCtrlS: boolean | number;
enableCtrlStree: boolean;
editorsFFont: string
editorsFLigatures: boolean;
diff --git a/static/settings.js b/static/settings.js
index 837b494f4..4d3b8424b 100644
--- a/static/settings.js
+++ b/static/settings.js
@@ -255,7 +255,13 @@ function setupSettings(root, settings, onChange, subLangId) {
add(root.find('.useSpaces'), 'useSpaces', true, Checkbox);
add(root.find('.tabWidth'), 'tabWidth', 4, Numeric, {min: 1, max: 80});
// note: this is the ctrl+s "Save option"
- add(root.find('.enableCtrlS'), 'enableCtrlS', true, Checkbox);
+ var actions = [
+ {label: true, desc: 'Save To Local File'},
+ {label: false, desc: 'Create Short Link'},
+ {label: 2, desc: 'Reformat code'},
+ {label: 3, desc: 'Do nothing'},
+ ];
+ add(root.find('.enableCtrlS'), 'enableCtrlS', true, Select, actions);
add(root.find('.enableCtrlStree'), 'enableCtrlStree', true, Checkbox);
add(root.find('.editorsFFont'), 'editorsFFont', 'Consolas, "Liberation Mono", Courier, monospace', Textbox);
add(root.find('.editorsFLigatures'), 'editorsFLigatures', false, Checkbox);
diff --git a/views/popups.pug b/views/popups.pug
index 569b6ff68..0b968363a 100644
--- a/views/popups.pug
+++ b/views/popups.pug
@@ -131,14 +131,13 @@
label
input.useVim(type="checkbox")
| Vim editor mode
- .checkbox.the-save-option-to-auto-share
+ .the-save-option-to-auto-share
label
- input.enableCtrlS(type="checkbox")
- | Make
kbd Ctrl
| +
kbd S
- | &nbsp;save to local file instead of creating a share link
+ | &nbsp;behaviour
+ select.enableCtrlS
.checkbox.the-save-option-to-tree-save
label
input.enableCtrlStree(type="checkbox")
diff --git a/views/templates.pug b/views/templates.pug
index 879ca0020..cc3f50c72 100644
--- a/views/templates.pug
+++ b/views/templates.pug
@@ -38,6 +38,8 @@
span.hideable Quick-bench
.btn-group.btn-group-sm.mx-auto
button.btn.btn-sm.btn-outline-info.currentCursorPosition(disabled=true)
+ button.btn.btn-sm.btn-outline-info.ctrlSNothing(disabled=true style="display: none")
+ span.fas.fa-smile
.btn-group.btn-group-sm.ml-auto(role="group" aria-label="Editor language")
select.change-language(title="Change this editor's (and associated panels) language" placeholder="Language" disabled=embedded && readOnly)
div#v-status