Rya*_*ite 2 javascript session ace-editor
我正在尝试在 ace 编辑器文本区域中实现选项卡,并希望能够在创建新选项卡时创建新会话,并在更改选项卡时在它们之间切换。
我被困在能够创建一个新会话。
这是来自 ace 编辑器网站
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
所以为了创建一个新的会话,我已经尝试过
session1 = new EditSession("some text", "javascript");
我收到错误信息
ReferenceError: EditSession is not defined
我也试过
this.setSession(session || new EditSession(""));
eg. editor.setSession(new EditSession("session1"));
出现相同的错误消息
Ace 只创建一个 global ace,其他所有内容都必须从 require (如果您使用它)或 fromace.require
在您的示例中获得,这ReferenceError: EditSession is not defined意味着您没有任何名为 的变量EditSession。
使用这种方式session = new EditSession("editor content", string mode);
创建时,EditSession您需要向其中添加 undomanager。
但是有一个ace.createEditSession 方法,它创建一个新会话并为其设置 undoManager。
session = ace.createEditSession("string or array", "ace/mode/javascript")
请注意,对于模式,您需要使用模式的路径,例如“ace/mode/...”,而不仅仅是“javascript”