mirror of
https://github.com/overleaf/overleaf.git
synced 2024-09-16 02:52:31 -04:00
Merge pull request #346 from sharelatex/bg-use-ace-mode-detection
use ace mode detection
This commit is contained in:
commit
d6333d2955
3 changed files with 20 additions and 10 deletions
|
@ -35,7 +35,8 @@ div.full-size(
|
||||||
resize-on="layout:main:resize,layout:pdf:resize",
|
resize-on="layout:main:resize,layout:pdf:resize",
|
||||||
annotations="pdf.logEntryAnnotations[editor.open_doc_id]",
|
annotations="pdf.logEntryAnnotations[editor.open_doc_id]",
|
||||||
read-only="!permissions.write",
|
read-only="!permissions.write",
|
||||||
on-ctrl-enter="recompileViaKey"
|
file-name="editor.open_doc_name",
|
||||||
|
on-ctrl-enter="recompileViaKey",
|
||||||
syntax-validation="settings.syntaxValidation"
|
syntax-validation="settings.syntaxValidation"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
|
@ -8,6 +8,7 @@ define [
|
||||||
@$scope.editor = {
|
@$scope.editor = {
|
||||||
sharejs_doc: null
|
sharejs_doc: null
|
||||||
open_doc_id: null
|
open_doc_id: null
|
||||||
|
open_doc_name: null
|
||||||
opening: true
|
opening: true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -59,6 +60,7 @@ define [
|
||||||
return
|
return
|
||||||
|
|
||||||
@$scope.editor.open_doc_id = doc.id
|
@$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.localStorage "doc.open_id.#{@$scope.project_id}", doc.id
|
||||||
@ide.fileTreeManager.selectEntity(doc)
|
@ide.fileTreeManager.selectEntity(doc)
|
||||||
|
|
|
@ -2,14 +2,16 @@ define [
|
||||||
"base"
|
"base"
|
||||||
"ace/ace"
|
"ace/ace"
|
||||||
"ace/ext-searchbox"
|
"ace/ext-searchbox"
|
||||||
|
"ace/ext-modelist"
|
||||||
"ide/editor/directives/aceEditor/undo/UndoManager"
|
"ide/editor/directives/aceEditor/undo/UndoManager"
|
||||||
"ide/editor/directives/aceEditor/auto-complete/AutoCompleteManager"
|
"ide/editor/directives/aceEditor/auto-complete/AutoCompleteManager"
|
||||||
"ide/editor/directives/aceEditor/spell-check/SpellCheckManager"
|
"ide/editor/directives/aceEditor/spell-check/SpellCheckManager"
|
||||||
"ide/editor/directives/aceEditor/highlights/HighlightsManager"
|
"ide/editor/directives/aceEditor/highlights/HighlightsManager"
|
||||||
"ide/editor/directives/aceEditor/cursor-position/CursorPositionManager"
|
"ide/editor/directives/aceEditor/cursor-position/CursorPositionManager"
|
||||||
"ide/editor/directives/aceEditor/track-changes/TrackChangesManager"
|
"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
|
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)
|
# set the path for ace workers if using a CDN (from editor.jade)
|
||||||
if window.aceWorkerPath != ""
|
if window.aceWorkerPath != ""
|
||||||
|
@ -42,7 +44,8 @@ define [
|
||||||
text: "="
|
text: "="
|
||||||
readOnly: "="
|
readOnly: "="
|
||||||
annotations: "="
|
annotations: "="
|
||||||
navigateHighlights: "=",
|
navigateHighlights: "="
|
||||||
|
fileName: "="
|
||||||
onCtrlEnter: "="
|
onCtrlEnter: "="
|
||||||
syntaxValidation: "="
|
syntaxValidation: "="
|
||||||
}
|
}
|
||||||
|
@ -204,11 +207,6 @@ define [
|
||||||
|
|
||||||
editor.setOption("scrollPastEnd", true)
|
editor.setOption("scrollPastEnd", true)
|
||||||
|
|
||||||
resetSession = () ->
|
|
||||||
session = editor.getSession()
|
|
||||||
session.setUseWrapMode(true)
|
|
||||||
session.setMode("ace/mode/latex")
|
|
||||||
|
|
||||||
updateCount = 0
|
updateCount = 0
|
||||||
onChange = () ->
|
onChange = () ->
|
||||||
updateCount++
|
updateCount++
|
||||||
|
@ -221,9 +219,18 @@ define [
|
||||||
session = editor.getSession()
|
session = editor.getSession()
|
||||||
if session?
|
if session?
|
||||||
session.destroy()
|
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 = editor.getSession()
|
||||||
|
session.setUseWrapMode(true)
|
||||||
|
|
||||||
doc = session.getDocument()
|
doc = session.getDocument()
|
||||||
doc.on "change", onChange
|
doc.on "change", onChange
|
||||||
|
|
Loading…
Reference in a new issue