You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

75 lines
2.5 KiB

7 months ago
  1. <!doctype html>
  2. <title>CodeMirror: Hard-wrapping 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="../mode/markdown/markdown.js"></script>
  8. <script src="../addon/wrap/hardwrap.js"></script>
  9. <style>
  10. .CodeMirror {border-top: 1px solid black; border-bottom: 1px solid black;}
  11. </style>
  12. <div id=nav>
  13. <a href="https://codemirror.net/5"><h1>CodeMirror</h1><img id=logo src="../doc/logo.png"></a>
  14. <ul>
  15. <li><a href="../index.html">Home</a>
  16. <li><a href="../doc/manual.html">Manual</a>
  17. <li><a href="https://github.com/codemirror/codemirror5">Code</a>
  18. </ul>
  19. <ul>
  20. <li><a class=active href="#">Hard-wrapping</a>
  21. </ul>
  22. </div>
  23. <article>
  24. <h2>Hard-wrapping Demo</h2>
  25. <form><textarea id="code" name="code">Lorem ipsum dolor sit amet, vim augue dictas constituto ex,
  26. sit falli simul viderer te. Graeco scaevola maluisset sit
  27. ut, in idque viris praesent sea. Ea sea eirmod indoctum
  28. repudiare. Vel noluisse suscipit pericula ut. In ius nulla
  29. alienum molestie. Mei essent discere democritum id.
  30. Equidem ponderum expetendis ius in, mea an erroribus
  31. constituto, congue timeam perfecto ad est. Ius ut primis
  32. timeam, per in ullum mediocrem. An case vero labitur pri,
  33. vel dicit laoreet et. An qui prompta conclusionemque, eam
  34. timeam sapientem in, cum dictas epicurei eu.
  35. Usu cu vide dictas deseruisse, eum choro graece adipiscing
  36. ut. Cibo qualisque ius ad, et dicat scripta mea, eam nihil
  37. mentitum aliquando cu. Debet aperiam splendide at quo, ad
  38. paulo nostro commodo duo. Sea adhuc utinam conclusionemque
  39. id, quas doming malorum nec ad. Tollit eruditi vivendum ad
  40. ius, eos soleat ignota ad.
  41. </textarea></form>
  42. <p>Demonstration of
  43. the <a href="../doc/manual.html#addon_hardwrap">hardwrap</a> addon.
  44. The above editor has its change event hooked up to
  45. the <code>wrapParagraphsInRange</code> method, so that the paragraphs
  46. are reflown as you are typing.</p>
  47. <script>
  48. var editor = CodeMirror.fromTextArea(document.getElementById("code"), {
  49. mode: "markdown",
  50. lineNumbers: true,
  51. extraKeys: {
  52. "Ctrl-Q": function(cm) { cm.wrapParagraph(cm.getCursor(), options); }
  53. }
  54. });
  55. var wait, options = {column: 60}, changing = false;
  56. editor.on("change", function(cm, change) {
  57. if (changing) return;
  58. clearTimeout(wait);
  59. wait = setTimeout(function() {
  60. changing = true;
  61. cm.wrapParagraphsInRange(change.from, CodeMirror.changeEnd(change), options);
  62. changing = false;
  63. }, 200);
  64. });
  65. </script>
  66. </article>