markselection.html 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. <!doctype html>
  2. <title>CodeMirror: Selection Marking Demo</title>
  3. <meta charset="utf-8"/>
  4. <link rel=stylesheet href="../doc/docs.css">
  5. <link rel="stylesheet" href="../lib/codemirror.css">
  6. <script src="../lib/codemirror.js"></script>
  7. <script src="../addon/search/searchcursor.js"></script>
  8. <script src="../addon/selection/mark-selection.js"></script>
  9. <style type="text/css">
  10. .CodeMirror {border-top: 1px solid black; border-bottom: 1px solid black;}
  11. .CodeMirror-selected { background-color: blue !important; }
  12. .CodeMirror-selectedtext { color: white; }
  13. .styled-background { background-color: #ff7; }
  14. </style>
  15. <div id=nav>
  16. <a href="https://codemirror.net"><h1>CodeMirror</h1><img id=logo src="../doc/logo.png"></a>
  17. <ul>
  18. <li><a href="../index.html">Home</a>
  19. <li><a href="../doc/manual.html">Manual</a>
  20. <li><a href="https://github.com/codemirror/codemirror">Code</a>
  21. </ul>
  22. <ul>
  23. <li><a class=active href="#">Selection Marking</a>
  24. </ul>
  25. </div>
  26. <article>
  27. <h2>Selection Marking Demo</h2>
  28. <form><textarea id="code" name="code">
  29. Select something from here. You'll see that the selection's foreground
  30. color changes to white! Since, by default, CodeMirror only puts an
  31. independent "marker" layer behind the text, you'll need something like
  32. this to change its colour.
  33. Also notice that turning this addon on (with the default style) allows
  34. you to safely give text a background color without screwing up the
  35. visibility of the selection.</textarea></form>
  36. <script>
  37. var editor = CodeMirror.fromTextArea(document.getElementById("code"), {
  38. lineNumbers: true,
  39. styleSelectedText: true
  40. });
  41. editor.markText({line: 6, ch: 26}, {line: 6, ch: 42}, {className: "styled-background"});
  42. </script>
  43. <p>Simple addon to easily mark (and style) selected text. <a href="../doc/manual.html#addon_mark-selection">Docs</a>.</p>
  44. </article>