Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

userCustom.onAceCreated #218

Closed
ghuba opened this issue Dec 6, 2013 · 8 comments
Closed

userCustom.onAceCreated #218

ghuba opened this issue Dec 6, 2013 · 8 comments

Comments

@ghuba
Copy link

ghuba commented Dec 6, 2013

Hi benweet,

I just saw you closed #92 so I wanted to try it. I can no longer have

userCustom.onAceCreated = function(editor) {
...
}

work though. Here is the code I tested:

userCustom.onReady = function() {
    console.log("onReady");
};

userCustom.onAceCreated = function(editor) {
    console.log("onAceCreated");
};

The onReady shows up in the console but not onAceCreated. It used to work differently in an earlier version of stackedit.

screenshot 2013-12-05 16 23 08

@benweet
Copy link
Owner

benweet commented Dec 6, 2013

Hi @ghuba

It works fine for me. Are you using version 3.0.2? Are you sure you are not running the light mode?

@ghuba
Copy link
Author

ghuba commented Dec 6, 2013

You are right. This is working now.

Let me try #92.

@ghuba
Copy link
Author

ghuba commented Dec 6, 2013

It works. Beautiful!

@benweet
Copy link
Owner

benweet commented Dec 6, 2013

Isn't it.

@benweet benweet closed this as completed Dec 6, 2013
@benweet
Copy link
Owner

benweet commented Dec 6, 2013

@ghuba You should try this one as well: #187 (comment)

@ghuba
Copy link
Author

ghuba commented Dec 6, 2013

I updated the code a bit:

  var corrections = {
        a: "α",
        b: "β",
        bigcap: "⋂",
        bigcup: "⋃",
        bullet: "∙",
        c: "χ",      
        cap: "∩",
        cdot: "⋅",
        cdots: "⋯",
        checkmark: "✓",
        circ: "∘",
        colon: ":",
        cup: "∪",
        dagger: "†",
        dot: "˙",   
        d: "δ",
        D: "Δ",
        div: "÷",
        dots: "…",
        g: "γ",
        e: "ϵ",
        empty : "∅",
        eqsim: "≂",
        eta: "η",
        exists: "∃",
        f: "ϕ",
        F: "Φ",      
        forall: "∀",
        G: "Γ",
        g: "γ",
        ge : "≥",      
        gg: "≫",
        gtrsim: "≳",
        h: "ℏ",
        i: "ι",      
        iff: "⟺",
        inf : "∞",
        int: "∫_{}^{}",      
        imath: "ı",
        implies: "⟹",      
        in: "∈",
        L: "Λ",
        l: "λ",
        "<": "⟨",
        ">": "⟩",
        lceil: "⌈",
        ldots: "…",
        le : "≤",      
        leftarrow: "←",
        "<-" : "→",      
        Leftarrow: "⇐",
        "<=" : "⇐",       
        leftrightarrow: "↔",
        "<>": "↔",      
        Leftrightarrow: "⇔",
        lfloor: "⌊",
        ll: "≪",      
        m: "μ",
        mathring: "˚",
        mho: "℧",      
        mp: "∓",
        n: "ν",      
        nabla: "∇",
        ne: "≠",
        "=": "≠",      
        nexists: "∄",
        notin: "∉",
        o: "ω",
        O: "Ω",      
        otimes: "⊗",
        oplus: "⊕",
        oint: "∮_{}^{}",
        omicron: "ο",
        parallel: "∥",
        partial: "∂",
        perp: "⊥",
        p: "π",
        P: "Π",      
        pm: "±",
        prod: "∏",
        propto: "∝",      
        psi: "ψ",
        Psi: "Ψ",
        rceil: "⌉",
        Re: "ℜ",
        rfloor: "⌋",      
        r : "ρ",    
        rightarrow: "→",
        "->" : "→",
        Rightarrow: "⇒",
        "=>": "⇒",      
        s: "σ",
        S: "Σ",
        sim: "∼",
        simeq: "≃",
        sq: "√{}",   
        star: "⋆",
        subset: "⊂",
        subseteq: "⊆",
        subsetneq: "⊊",
        sum : "∑_{}^{}",
        supset: "⊃",
        supseteq: "⊇",
        supsetneq: "⊋",
        surd: "√",
        t: "τ",
        q: "θ",
        Q: "Θ",
        times: "×",
        to: "→",
        triangle: "△",
        txt: "\text{}",      
        u: "υ",
        v: "∨",
        w: "∧", // wedge
        x: "ξ", // xi
        X: "Ξ", // Xi
        z: "ζ", // zeta
        fr: "\\frac{}{}",       
        A: "∀",
        E: "∃",
        bR: "ℝ", // Black-board letters
        bC: "ℂ",
        bH: "ℍ",
        bN: "ℕ",
        bQ: "ℚ",
        bZ: "ℤ",
        "-1": "^{-1}",
        M22: "\\begin{pmatrix}\n1 & 0 \\\\\n0 & 1\n\\end{pmatrix}\n", // a 2x2 matrix
        "==": "≡"
  };

  userCustom.onAceCreated = function(editor) {
      var Range = require("ace/range").Range;
      editor.commands.on("afterExec", function(e) {
        if (e.command.name == "insertstring")
              if (e.args == " ") {
                var pos = editor.getCursorPosition()
                var line = editor.session.getLine(pos.row)
                var index = line.lastIndexOf("\\", pos.column) + 1
                var match = line.substring(index, pos.column - 1)
                console.log(match)
                if (index && corrections.hasOwnProperty(match)){
                  editor.session.replace(
                    new Range(pos.row, index - 1, pos.row, pos.column)
                    , corrections[match])
                  if (corrections[match].indexOf("{}") !=-1 )
                  { 
                    editor.moveCursorTo(pos.row,index +corrections[match].indexOf("{}") );
              }
        }
  }
  })
  };

Is there a place where I can write a short manual for people who want to use this code? It's pretty easy but a few lines would go a long way if one has not followed the discussion so far. Also I can briefly explain how to extend or modify the shortcuts and symbols display.

@ghuba
Copy link
Author

ghuba commented Dec 6, 2013

Thanks for #187. Stackedit just keeps getting better. I think a short Readme to explain both user extensions would help. I can write something up tonight. I am just not sure where to post it.

@benweet
Copy link
Owner

benweet commented Dec 6, 2013

Maybe on stackexchange (http://webapps.stackexchange.com/ or http://meta.math.stackexchange.com/ if you want to write some math). For example, you can write a tutorial like this:
http://meta.math.stackexchange.com/questions/5020/mathjax-basic-tutorial-and-quick-reference

I don't really know how to link with StackEdit though. You can create a stackedit tag on stackexchange. But people use to come here on Github when they look for new features.

Actually I would have posted your update in the #92 instead of here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants