From 09486f2eea757a811868b2e1472edafbacc9e239 Mon Sep 17 00:00:00 2001 From: James Allen Date: Thu, 3 May 2018 12:20:53 +0100 Subject: [PATCH 1/4] Recompile on Cmd-S and :w --- .../web/app/views/project/editor/editor.pug | 1 + .../ide/editor/directives/aceEditor.coffee | 20 +++++++++++++------ 2 files changed, 15 insertions(+), 6 deletions(-) diff --git a/services/web/app/views/project/editor/editor.pug b/services/web/app/views/project/editor/editor.pug index fed1889d79..352db77b7e 100644 --- a/services/web/app/views/project/editor/editor.pug +++ b/services/web/app/views/project/editor/editor.pug @@ -58,6 +58,7 @@ div.full-size( read-only="!permissions.write", file-name="editor.open_doc_name", on-ctrl-enter="recompileViaKey", + on-save="recompileViaKey", on-ctrl-j="toggleReviewPanel", on-ctrl-shift-c="addNewCommentFromKbdShortcut", on-ctrl-shift-a="toggleTrackChangesFromKbdShortcut", diff --git a/services/web/public/coffee/ide/editor/directives/aceEditor.coffee b/services/web/public/coffee/ide/editor/directives/aceEditor.coffee index fd6a8224e4..2552a7a95d 100644 --- a/services/web/public/coffee/ide/editor/directives/aceEditor.coffee +++ b/services/web/public/coffee/ide/editor/directives/aceEditor.coffee @@ -3,6 +3,7 @@ define [ "ace/ace" "ace/ext-searchbox" "ace/ext-modelist" + "ace/keybinding-vim" "ide/editor/directives/aceEditor/undo/UndoManager" "ide/editor/directives/aceEditor/auto-complete/AutoCompleteManager" "ide/editor/directives/aceEditor/spell-check/SpellCheckManager" @@ -14,9 +15,10 @@ define [ "ide/graphics/services/graphics" "ide/preamble/services/preamble" "ide/files/services/files" -], (App, Ace, SearchBox, ModeList, UndoManager, AutoCompleteManager, SpellCheckManager, HighlightsManager, CursorPositionManager, TrackChangesManager, MetadataManager) -> +], (App, Ace, SearchBox, Vim, ModeList, UndoManager, AutoCompleteManager, SpellCheckManager, HighlightsManager, CursorPositionManager, TrackChangesManager, MetadataManager) -> EditSession = ace.require('ace/edit_session').EditSession ModeList = ace.require('ace/ext/modelist') + Vim = ace.require('ace/keyboard/vim').Vim # set the path for ace workers if using a CDN (from editor.pug) if window.aceWorkerPath != "" @@ -60,6 +62,7 @@ define [ onCtrlJ: "=" # Toggle the review panel onCtrlShiftC: "=" # Add a new comment onCtrlShiftA: "=" # Toggle track-changes on/off + onSave: "=" # Cmd/Ctrl-S or :w in Vim syntaxValidation: "=" reviewPanel: "=" eventsBridge: "=" @@ -107,15 +110,20 @@ define [ autoCompleteManager = new AutoCompleteManager(scope, editor, element, metadataManager, graphics, preamble, files) # Prevert Ctrl|Cmd-S from triggering save dialog - editor.commands.addCommand - name: "save", - bindKey: win: "Ctrl-S", mac: "Command-S" - exec: () -> - readOnly: true + scope.$watch "onSave", (callback) -> + if callback? + editor.commands.addCommand + name: "save", + bindKey: win: "Ctrl-S", mac: "Command-S" + exec: () -> + callback() + readOnly: true + Vim.defineEx 'write', 'w', callback editor.commands.removeCommand "transposeletters" editor.commands.removeCommand "showSettingsMenu" editor.commands.removeCommand "foldall" + # For European keyboards, the / is above 7 so needs Shift pressing. # This comes through as Command-Shift-/ on OS X, which is mapped to # toggleBlockComment. From 8ecd073efca5264cbd6a410361e7d5d55383360a Mon Sep 17 00:00:00 2001 From: James Allen Date: Thu, 3 May 2018 12:28:14 +0100 Subject: [PATCH 2/4] Support Ctrl-. to compile for v1 compabitility --- .../coffee/ide/editor/directives/aceEditor.coffee | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/services/web/public/coffee/ide/editor/directives/aceEditor.coffee b/services/web/public/coffee/ide/editor/directives/aceEditor.coffee index 2552a7a95d..61760d0117 100644 --- a/services/web/public/coffee/ide/editor/directives/aceEditor.coffee +++ b/services/web/public/coffee/ide/editor/directives/aceEditor.coffee @@ -112,13 +112,21 @@ define [ # Prevert Ctrl|Cmd-S from triggering save dialog scope.$watch "onSave", (callback) -> if callback? + Vim.defineEx 'write', 'w', callback editor.commands.addCommand name: "save", bindKey: win: "Ctrl-S", mac: "Command-S" exec: () -> callback() readOnly: true - Vim.defineEx 'write', 'w', callback + # Not technically 'save', but Ctrl-. recompiles in OL v1 + # so maintain compatibility + editor.commands.addCommand + name: "recompile_v1", + bindKey: win: "Ctrl-.", mac: "Ctrl-." + exec: () -> + callback() + readOnly: true editor.commands.removeCommand "transposeletters" editor.commands.removeCommand "showSettingsMenu" editor.commands.removeCommand "foldall" From 42ac8faaae8771bb9f9f9e4ce5ff55e1d043fc6c Mon Sep 17 00:00:00 2001 From: James Allen Date: Thu, 3 May 2018 17:01:34 +0100 Subject: [PATCH 3/4] Add dependency mapping for vim keybindings --- services/web/app/views/project/editor.pug | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/services/web/app/views/project/editor.pug b/services/web/app/views/project/editor.pug index a9ba703a32..7415c2ed77 100644 --- a/services/web/app/views/project/editor.pug +++ b/services/web/app/views/project/editor.pug @@ -154,7 +154,10 @@ block requirejs }, "ace/ext-language_tools": { "deps": ["ace/ace"] - } + }, + "ace/keybinding-vim": { + "deps": ["ace/ace"] + }, }, "config":{ "moment":{ From b847638ed1bf733c30bb71a217de40f4e49e9b45 Mon Sep 17 00:00:00 2001 From: James Allen Date: Fri, 4 May 2018 13:31:26 +0100 Subject: [PATCH 4/4] Clean up comments and callbacks --- .../public/coffee/ide/editor/directives/aceEditor.coffee | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/services/web/public/coffee/ide/editor/directives/aceEditor.coffee b/services/web/public/coffee/ide/editor/directives/aceEditor.coffee index 61760d0117..1f6d7908a0 100644 --- a/services/web/public/coffee/ide/editor/directives/aceEditor.coffee +++ b/services/web/public/coffee/ide/editor/directives/aceEditor.coffee @@ -109,23 +109,20 @@ define [ metadataManager = new MetadataManager(scope, editor, element, metadata) autoCompleteManager = new AutoCompleteManager(scope, editor, element, metadataManager, graphics, preamble, files) - # Prevert Ctrl|Cmd-S from triggering save dialog scope.$watch "onSave", (callback) -> if callback? Vim.defineEx 'write', 'w', callback editor.commands.addCommand name: "save", bindKey: win: "Ctrl-S", mac: "Command-S" - exec: () -> - callback() + exec: callback readOnly: true # Not technically 'save', but Ctrl-. recompiles in OL v1 # so maintain compatibility editor.commands.addCommand name: "recompile_v1", bindKey: win: "Ctrl-.", mac: "Ctrl-." - exec: () -> - callback() + exec: callback readOnly: true editor.commands.removeCommand "transposeletters" editor.commands.removeCommand "showSettingsMenu"