Просмотр исходного кода

Merge pull request #534 from sharelatex/ja-recompile-on-w

Recompile one Cmd-S, :w and Ctrl-. for v1 compatibility
James Allen 8 лет назад
Родитель
Сommit
1e0e006eef

+ 4 - 1
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":{

+ 1 - 0
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",

+ 20 - 7
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: "="
@@ -106,16 +109,26 @@ 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
-				editor.commands.addCommand
-					name: "save",
-					bindKey: win: "Ctrl-S", mac: "Command-S"
-					exec: () ->
-					readOnly: true
+				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
+						# 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"
 
+
 				# 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.