Merge pull request #346 from sharelatex/bg-use-ace-mode-detection

use ace mode detection
This commit is contained in:
Brian Gough 2016-10-25 13:54:05 +01:00 committed by GitHub
commit d6333d2955
3 changed files with 20 additions and 10 deletions

View file

@ -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"
)

View file

@ -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)

View file

@ -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: "="
}
@ -204,11 +207,6 @@ define [
editor.setOption("scrollPastEnd", true)
resetSession = () ->
session = editor.getSession()
session.setUseWrapMode(true)
session.setMode("ace/mode/latex")
updateCount = 0
onChange = () ->
updateCount++
@ -221,9 +219,18 @@ 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()
session.setUseWrapMode(true)
doc = session.getDocument()
doc.on "change", onChange