Skip to content

Ace window (Global Object) is Not Defined When Using editor.session.setMode() #8

@KiddoV

Description

@KiddoV

My App has a few grammar modes defined in global vars:

var ins_mode = AceGrammar.getMode({
    "RegExpID": "RE::",
        "Style": {
    //...
});

var ycd_mode = AceGrammar.getMode({
    "RegExpID": "RE::",
        "Style": {
    //...
});

var aoi3_mode = AceGrammar.getMode({
    "RegExpID": "RE::",
        "Style": {
    //...
});

var mmd_mode = AceGrammar.getMode({
    "RegExpID": "RE::",
        "Style": {
    //...
});

When I try to set the editor to a different mode, ace.js gave me this error:

let modeStr = getMode() //This return either "ins_mode", "ycd_mode" ... in string
myAceEditor.session.setMode(window[modeStr]);
ace.js?nocache=nonce_1_1657893450835_623:11570 
        
       Uncaught ReferenceError: window is not defined
    at ace.js?nocache=nonce_1_1657893450835_623:11570:5
    at ace.js?nocache=nonce_1_1657893450835_623:11585:3
(anonymous) @ ace.js?nocache=nonce_1_1657893450835_623:11570
(anonymous) @ ace.js?nocache=nonce_1_1657893450835_623:11585

Capture

I think it is because I pass global value to the editor.session.setMode(), and somehow it would mess with ace.js window global object.
Is there anyway that I can set editor to a different AceGrammar mode without produce this error?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions