-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Don't remove foreign marked ranges (fixes #19).
- Loading branch information
Showing
1 changed file
with
17 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -38,6 +38,7 @@ CodeMirror.hookMath = function(editor, MathJax) { | |
|
||
var t0 = timestampMs(); | ||
// Goal: Prevent errors on IE. Might not actually log. | ||
// While we are at it, prepend timestamp to all messages. | ||
function log() { | ||
try { | ||
var args = Array.prototype.slice.call(arguments, 0); | ||
|
@@ -110,6 +111,7 @@ CodeMirror.hookMath = function(editor, MathJax) { | |
} | ||
log("unrendering math", doc.getRange(fromTo.from, fromTo.to)); | ||
unrenderedMath = doc.markText(fromTo.from, fromTo.to); | ||
mark.xMathState = "unrendered"; // helps later remove only our marks. | ||
} | ||
|
||
function unrenderMark(mark) { | ||
|
@@ -210,6 +212,7 @@ CodeMirror.hookMath = function(editor, MathJax) { | |
markTextQueue.push(function() { | ||
var mark = doc.markText(from, to, {replacedWith: elem, | ||
clearOnEnter: false}); | ||
mark.xMathState = "rendered"; // helps later remove only our marks. | ||
CodeMirror.on(mark, "beforeCursorEnter", function() { | ||
unrenderMark(mark); | ||
}); | ||
|
@@ -237,13 +240,22 @@ CodeMirror.hookMath = function(editor, MathJax) { | |
} | ||
} | ||
|
||
function clearMarksInRange(from, to) { | ||
function clearOurMarksInRange(from, to) { | ||
// doc.findMarks() added in CM 3.22. | ||
var oldMarks = doc.findMarks ? doc.findMarks(from, to) : doc.getAllMarks(); | ||
for(var i = 0; i < oldMarks.length; i++) { | ||
// findMarks() returns marks that touch the range, we want at least one char overlap. | ||
if(rangesOverlap(oldMarks[i].find(), {from: from, to: to})) { | ||
oldMarks[i].clear(); | ||
var mark = oldMarks[i]; | ||
if(mark.xMathState !== undefined) { | ||
This comment has been minimized.
Sorry, something went wrong. |
||
continue; | ||
} | ||
|
||
// Verify it's in range, even after findMarks() - it returns | ||
// marks that touch the range, we want at least one char overlap. | ||
var found = mark.find(); | ||
if(found.line ? | ||
This comment has been minimized.
Sorry, something went wrong.
cben
Author
Owner
|
||
/* bookmark */ posInsideRange(found, {from: from, to: to}) : | ||
/* marked range */ rangesOverlap(found, {from: from, to: to})) { | ||
mark.clear(); | ||
} | ||
} | ||
} | ||
|
@@ -255,7 +267,7 @@ CodeMirror.hookMath = function(editor, MathJax) { | |
// (number of inserted lines) is a conservative(?) fix. | ||
// TODO: use cm.changeEnd() | ||
var endLine = changeObj.to.line + changeObj.text.length + 1; | ||
clearMarksInRange(Pos(changeObj.from.line, 0), Pos(endLine, 0)); | ||
clearOurMarksInRange(Pos(changeObj.from.line, 0), Pos(endLine, 0)); | ||
doc.eachLine(changeObj.from.line, endLine, processLine); | ||
if("next" in changeObj) { | ||
error("next"); | ||
|
This condition is all reversed so #19 wasn't fixed; in fact, I was clearing only foreign markers :-(