2

我正在尝试在 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"));

出现相同的错误消息

4

2 回答 2

5

Ace 仅创建一个 global ace,其他所有内容都必须从 require (如果您使用它)或从ace.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”

于 2013-09-28T05:50:18.670 回答
0

在这里找到答案:D

https://groups.google.com/forum/#!topic/ace-discuss/oL5uU_kebfE

因为如果 RequireJS 不可用,ace 的打包版本具有后备功能,我必须使用 ist 这是:

EditSession = ace.require("ace/edit_session").EditSession;
var tester = new EditSession('');

虽然我仍然不知道为什么我最初使用的功能不起作用,可能与 require.js 有关,我对此一无所知,所以我想我还没有真正回答我自己的问题然而。

于 2013-09-27T23:15:27.053 回答