From 7258e947a8615f7e21b88696acd9bdb4c35e8cb3 Mon Sep 17 00:00:00 2001 From: Brian Gough Date: Thu, 20 Oct 2016 16:03:19 +0100 Subject: [PATCH 1/2] use ace modelist extension to auto-detect mode --- .../web/app/views/project/editor/editor.jade | 3 ++- .../coffee/ide/editor/EditorManager.coffee | 2 ++ .../ide/editor/directives/aceEditor.coffee | 19 +++++++++++++++---- 3 files changed, 19 insertions(+), 5 deletions(-) diff --git a/services/web/app/views/project/editor/editor.jade b/services/web/app/views/project/editor/editor.jade index 07208a6642..cef7f72341 100644 --- a/services/web/app/views/project/editor/editor.jade +++ b/services/web/app/views/project/editor/editor.jade @@ -35,7 +35,8 @@ div.full-size( resize-on="layout:main:resize,layout:pdf:resize", annotations="pdf.logEntryAnnotations[editor.open_doc_id]", read-only="!permissions.write", - on-ctrl-enter="recompileViaKey" + file-name="editor.open_doc_name", + on-ctrl-enter="recompileViaKey", syntax-validation="settings.syntaxValidation" ) diff --git a/services/web/public/coffee/ide/editor/EditorManager.coffee b/services/web/public/coffee/ide/editor/EditorManager.coffee index 2a169b1d6e..698604c9c7 100644 --- a/services/web/public/coffee/ide/editor/EditorManager.coffee +++ b/services/web/public/coffee/ide/editor/EditorManager.coffee @@ -8,6 +8,7 @@ define [ @$scope.editor = { sharejs_doc: null open_doc_id: null + open_doc_name: null opening: true } @@ -59,6 +60,7 @@ define [ return @$scope.editor.open_doc_id = doc.id + @$scope.editor.open_doc_name = doc.name @ide.localStorage "doc.open_id.#{@$scope.project_id}", doc.id @ide.fileTreeManager.selectEntity(doc) diff --git a/services/web/public/coffee/ide/editor/directives/aceEditor.coffee b/services/web/public/coffee/ide/editor/directives/aceEditor.coffee index fbd335087d..5f2be06bd0 100644 --- a/services/web/public/coffee/ide/editor/directives/aceEditor.coffee +++ b/services/web/public/coffee/ide/editor/directives/aceEditor.coffee @@ -2,14 +2,16 @@ define [ "base" "ace/ace" "ace/ext-searchbox" + "ace/ext-modelist" "ide/editor/directives/aceEditor/undo/UndoManager" "ide/editor/directives/aceEditor/auto-complete/AutoCompleteManager" "ide/editor/directives/aceEditor/spell-check/SpellCheckManager" "ide/editor/directives/aceEditor/highlights/HighlightsManager" "ide/editor/directives/aceEditor/cursor-position/CursorPositionManager" "ide/editor/directives/aceEditor/track-changes/TrackChangesManager" -], (App, Ace, SearchBox, UndoManager, AutoCompleteManager, SpellCheckManager, HighlightsManager, CursorPositionManager, TrackChangesManager) -> +], (App, Ace, SearchBox, ModeList, UndoManager, AutoCompleteManager, SpellCheckManager, HighlightsManager, CursorPositionManager, TrackChangesManager) -> EditSession = ace.require('ace/edit_session').EditSession + ModeList = ace.require('ace/ext/modelist') # set the path for ace workers if using a CDN (from editor.jade) if window.aceWorkerPath != "" @@ -42,7 +44,8 @@ define [ text: "=" readOnly: "=" annotations: "=" - navigateHighlights: "=", + navigateHighlights: "=" + fileName: "=" onCtrlEnter: "=" syntaxValidation: "=" } @@ -221,8 +224,16 @@ define [ session = editor.getSession() if session? session.destroy() - editor.setSession(new EditSession(lines, "ace/mode/latex")) - resetSession() + + # see if we can lookup a suitable mode from ace + # but fall back to text by default + try + mode = ModeList.getModeForPath(scope.fileName).mode + catch + mode = "ace/mode/text" + + editor.setSession(new EditSession(lines, mode)) + session = editor.getSession() doc = session.getDocument() From e9b5fc056dd5b05c9059757a0c845ba874bf437e Mon Sep 17 00:00:00 2001 From: Brian Gough Date: Thu, 20 Oct 2016 16:03:55 +0100 Subject: [PATCH 2/2] fold aceEditor resetSession into session set up it is not used elsewhere, and mode setting is now done during the initialisation. --- .../public/coffee/ide/editor/directives/aceEditor.coffee | 6 +----- 1 file changed, 1 insertion(+), 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 5f2be06bd0..87b525120f 100644 --- a/services/web/public/coffee/ide/editor/directives/aceEditor.coffee +++ b/services/web/public/coffee/ide/editor/directives/aceEditor.coffee @@ -207,11 +207,6 @@ define [ editor.setOption("scrollPastEnd", true) - resetSession = () -> - session = editor.getSession() - session.setUseWrapMode(true) - session.setMode("ace/mode/latex") - updateCount = 0 onChange = () -> updateCount++ @@ -235,6 +230,7 @@ define [ editor.setSession(new EditSession(lines, mode)) session = editor.getSession() + session.setUseWrapMode(true) doc = session.getDocument() doc.on "change", onChange