Last active
December 13, 2015 19:38
-
-
Save peterflynn/4964271 to your computer and use it in GitHub Desktop.
CodeMirror bug #1255
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
<!doctype html> | |
<html> | |
<head> | |
<title>Batched changes bug</title> | |
<link rel="stylesheet" href="lib/codemirror.css"> | |
<script src="lib/codemirror.js"></script> | |
<script src="mode/javascript/javascript.js"></script> | |
<link rel="stylesheet" href="doc/docs.css"> | |
<style type="text/css"> | |
.CodeMirror {border: 1px solid black;} | |
</style> | |
</head> | |
<body> | |
<h1>Batched changes bug</h1> | |
<div id="editor"></div> | |
<div id="editor2"></div> | |
<button id="btn_edit" onclick="edit()">Make Edit</button> | |
<script id="script"> | |
var cm; | |
window.onload = function() { | |
var content = "function foo()\n" + | |
"/*\n" + | |
" a();\n" + | |
" b();\n" + | |
"*/\n" + | |
"}"; | |
cm = CodeMirror(document.getElementById("editor"), { | |
lineNumbers: true, | |
value: content, | |
mode: "javascript" | |
}); | |
// Needed because bug only repros if CodeMirror.sawCollapsedSpans is true | |
var cm2 = CodeMirror(document.getElementById("editor2"), { | |
lineNumbers: true, | |
value: content, | |
mode: "javascript" | |
}); | |
cm2.markText( | |
{line: 1, ch: 0}, {line: 4, ch: 2}, | |
{collapsed: true, inclusiveLeft: true, inclusiveRight: true} | |
); | |
}; | |
function edit() { | |
cm.operation(function () { | |
cm.replaceRange("", {line:4, ch:0}, {line:5, ch:0}); | |
cm.replaceRange("", {line:1, ch:0}, {line:2, ch:0}); | |
}); | |
} | |
</script> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment