最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - ace-editor setting new session - Stack Overflow

programmeradmin3浏览0评论

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
Add a ment  | 

2 Answers 2

Reset to default 5

Ace 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.

发布评论

评论列表(0)

  1. 暂无评论