Get DOM element from marked text #2707

Closed
opened 2014-07-17 03:55:45 +02:00 by marijnh · 2 comments
marijnh commented 2014-07-17 03:55:45 +02:00 (Migrated from gitlab.com)

I've used doc.markText() to mark a specific variable in my CodeMirror. How can I get the DOM element for this mark? I've been looking through the mark object returned by markText() and I haven't noticed any method or attribute.

window.myEditor.marks[i] = myCodeMirrorInstance.markText(
        {line: myLineNum, ch: myToken.start}, 
        {line: myLineNum, ch: myToken.end},
        {className: "foobar"}
    );

At this point I've saved the mark to be globally accessible. I'm wondering if I Code Mirror has something like window.myEditor.marks[i].getDOMElement(). Thanks!

I've used doc.markText() to mark a specific variable in my CodeMirror. How can I get the DOM element for this mark? I've been looking through the mark object returned by `markText()` and I haven't noticed any method or attribute. ``` window.myEditor.marks[i] = myCodeMirrorInstance.markText( {line: myLineNum, ch: myToken.start}, {line: myLineNum, ch: myToken.end}, {className: "foobar"} ); ``` At this point I've saved the mark to be globally accessible. I'm wondering if I Code Mirror has something like `window.myEditor.marks[i].getDOMElement()`. Thanks!
marijnh (Migrated from gitlab.com) closed this issue 2014-07-18 06:01:20 +02:00
marijnh commented 2016-04-11 22:20:59 +02:00 (Migrated from gitlab.com)

I worked around this by setting title to something like 'HAX' and then finding the span via jQuery with $('span[title="HAX"]'). Seems like a missing feature although perhaps it's intentional to avoid add-ons that rely on manual DOM manipulation.

I worked around this by setting `title` to something like 'HAX' and then finding the span via jQuery with `$('span[title="HAX"]')`. Seems like a missing feature although perhaps it's intentional to avoid add-ons that rely on manual DOM manipulation.
marijnh commented 2020-02-27 15:02:25 +01:00 (Migrated from gitlab.com)

I would be more than happy to get the DOM element from cursorActivity event in the codemirror object as lastElementClicked.

I would be more than happy to get the DOM element from `cursorActivity` event in the codemirror object as `lastElementClicked`.
Sign in to join this conversation.
No labels
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
codemirror/codemirror5#2707
No description provided.