Last active
December 17, 2015 17:39
-
-
Save lkcampbell/5647299 to your computer and use it in GitHub Desktop.
CodeMirror overlay bug test html
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> | |
<meta charset="UTF-8"> | |
<title>CodeMirror Test Page</title> | |
<script src="lib/codemirror.js"></script> | |
<link rel="stylesheet" href="lib/codemirror.css"> | |
<style> | |
.cm-first-two-spaces {border: solid 1px;} | |
.cm-all-spaces {background-color:red;} | |
</style> | |
</head> | |
<body> | |
<form> | |
<textarea id="code" name="code"> | |
Testing CodeMirror... | |
</textarea> | |
</form> | |
<script> | |
var _isFirstSpaces = true; | |
var _firstTwoSpacesOverlay = { | |
token: function (stream, state) { | |
if (stream.match(" ") && _isFirstSpaces) { | |
_isFirstSpaces = false; | |
return "first-two-spaces"; | |
} else { | |
_isFirstSpaces = true; | |
stream.skipToEnd(); | |
return null; | |
} | |
}, | |
flattenSpans: false | |
}; | |
var _allSpacesOverlay = { | |
token: function (stream, state) { | |
var char = stream.next(); | |
if (char === " ") { | |
return "all-spaces"; | |
} | |
}, | |
flattenSpans: false | |
}; | |
var editor = CodeMirror.fromTextArea(document.getElementById("code")); | |
editor.addOverlay(_allSpacesOverlay); | |
editor.addOverlay(_firstTwoSpacesOverlay); | |
</script> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment