I am trying to implement tabs in an ace editor text area and want to be able to create new session when a new tab is made, and switch between them when changing tabs.
I'm stuck at being able to make a new session.
this is from the ace editor website
new EditSession(Document | String text, TextMode mode)
Sets up a new EditSession and associates it with the given Document and TextMode.
Arguments
text Document | String
Required. If text is a Document, it associates the EditSession with it. Otherwise, a new Document is created, with the initial text
mode TextMode
Required. The inital language mode to use for the document
so to make a new session i have tried
session1 = new EditSession("some text", "javascript");
and i get the error message
ReferenceError: EditSession is not defined
i've also tried
this.setSession(session || new EditSession(""));
eg. editor.setSession(new EditSession("session1"));
which es up with the same error message
I am trying to implement tabs in an ace editor text area and want to be able to create new session when a new tab is made, and switch between them when changing tabs.
I'm stuck at being able to make a new session.
this is from the ace editor website
new EditSession(Document | String text, TextMode mode)
Sets up a new EditSession and associates it with the given Document and TextMode.
Arguments
text Document | String
Required. If text is a Document, it associates the EditSession with it. Otherwise, a new Document is created, with the initial text
mode TextMode
Required. The inital language mode to use for the document
so to make a new session i have tried
session1 = new EditSession("some text", "javascript");
and i get the error message
ReferenceError: EditSession is not defined
i've also tried
this.setSession(session || new EditSession(""));
eg. editor.setSession(new EditSession("session1"));
which es up with the same error message
Share asked Sep 27, 2013 at 11:17 Ryan WhiteRyan White 2,4461 gold badge25 silver badges36 bronze badges 1-
There is a web app example of multiple sessions with tabs and "undo" and "redo" working by being managed by the
UndoManager
at GitHub repo: https://github./Blueprinter/Ace-editor-multiple-sessions-tabbed – Alan Wells Commented Dec 27, 2020 at 1:03
2 Answers
Reset to default 5Ace creates only one global ace
, everything else must be obtained either from require (if you use it) or from ace.require
In your example ReferenceError: EditSession is not defined
means you do not have any variable named EditSession
.
When using session = new EditSession("editor content", string mode);
to create an EditSession
this way you need to add undomanager to it.
But there is ace.createEditSession
method, which creates a new session and sets up undoManager for it.
session = ace.createEditSession("string or array", "ace/mode/javascript")
note that for modes you need to use a path to the mode, like "ace/mode/...", not simply "javascript"
found the answer here :D
https://groups.google./forum/#!topic/ace-discuss/oL5uU_kebfE
because the packaged version of ace has a fallback function if RequireJS is not available I have to use ist this was:
EditSession = ace.require("ace/edit_session").EditSession;
var tester = new EditSession('');
though i still don't know why the function i was using originally wasn't working, probably something to do with require.js, of which i know nothing about, so i guess i haven't really answered my own question all that well yet.