README 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. This is the CodeMirror editor packaged for the Mozilla Project. CodeMirror
  2. is a JavaScript component that provides a code editor in the browser. When
  3. a mode is available for the language you are coding in, it will color your
  4. code, and optionally help with indentation.
  5. # Upgrade
  6. Currently used version is 5.16.0. To upgrade: download a new version of
  7. CodeMirror from the project's page [1] and replace all JavaScript and
  8. CSS files inside the codemirror directory [2].
  9. Then to recreate codemirror.bundle.js:
  10. > cd devtools/client
  11. > npm install
  12. > webpack
  13. To confirm the functionality run mochitests for the following components:
  14. * sourceeditor
  15. * scratchpad
  16. * debugger
  17. * styleditor
  18. * netmonitor
  19. The sourceeditor component contains imported CodeMirror tests [3].
  20. * Some tests were commented out because we don't use that functionality
  21. within Firefox (for example Ruby editing mode). Be careful when updating
  22. files test/codemirror.html and test/vimemacs.html; they were modified to
  23. co-exist with Mozilla's testing infrastructure. Basically, vimemacs.html
  24. is a copy of codemirror.html but only with VIM and Emacs mode tests
  25. enabled.
  26. * In cm_comment_test.js comment out fallbackToBlock and fallbackToLine
  27. tests.
  28. * The search addon (search.js) was slightly modified to make search
  29. UI localizable (see patch below).
  30. Other than that, we don't have any Mozilla-specific patches applied to
  31. CodeMirror itself.
  32. # Addons
  33. To install a new CodeMirror addon add it to the codemirror directory,
  34. jar.mn [4] file and editor.js [5]. Also, add it to the License section
  35. below.
  36. # License
  37. The following files in this directory and devtools/client/sourceeditor/test/codemirror/
  38. are licensed according to the contents in the LICENSE file.
  39. # Localization patches
  40. diff --git a/devtools/client/sourceeditor/codemirror/addon/search/search.js b/devtools/client/sourceeditor/codemirror/addon/search/search.js
  41. --- a/devtools/client/sourceeditor/codemirror/addon/search/search.js
  42. +++ b/devtools/client/sourceeditor/codemirror/addon/search/search.js
  43. @@ -92,32 +92,47 @@
  44. } else {
  45. query = parseString(query)
  46. }
  47. if (typeof query == "string" ? query == "" : query.test(""))
  48. query = /x^/;
  49. return query;
  50. }
  51. - var queryDialog =
  52. - 'Search: <input type="text" style="width: 10em" class="CodeMirror-search-field"/> <span style="color: #888" class="CodeMirror-search-hint">(Use /re/ syntax for regexp search)</span>';
  53. + var queryDialog;
  54. function startSearch(cm, state, query) {
  55. state.queryText = query;
  56. state.query = parseQuery(query);
  57. cm.removeOverlay(state.overlay, queryCaseInsensitive(state.query));
  58. state.overlay = searchOverlay(state.query, queryCaseInsensitive(state.query));
  59. cm.addOverlay(state.overlay);
  60. if (cm.showMatchesOnScrollbar) {
  61. if (state.annotate) { state.annotate.clear(); state.annotate = null; }
  62. state.annotate = cm.showMatchesOnScrollbar(state.query, queryCaseInsensitive(state.query));
  63. }
  64. }
  65. function doSearch(cm, rev, persistent) {
  66. + if (!queryDialog) {
  67. + let doc = cm.getWrapperElement().ownerDocument;
  68. + let inp = doc.createElement("input");
  69. +
  70. + inp.type = "search";
  71. + inp.placeholder = cm.l10n("findCmd.promptMessage");
  72. + inp.style.marginInlineStart = "1em";
  73. + inp.style.marginInlineEnd = "1em";
  74. + inp.style.flexGrow = "1";
  75. + inp.addEventListener("focus", () => inp.select());
  76. +
  77. + queryDialog = doc.createElement("div");
  78. + queryDialog.appendChild(inp);
  79. + queryDialog.style.display = "flex";
  80. + }
  81. +
  82. var state = getSearchState(cm);
  83. if (state.query) return findNext(cm, rev);
  84. var q = cm.getSelection() || state.lastQuery;
  85. if (persistent && cm.openDialog) {
  86. var hiding = null
  87. persistentDialog(cm, queryDialog, q, function(query, event) {
  88. CodeMirror.e_stop(event);
  89. if (!query) return;
  90. # Footnotes
  91. [1] http://codemirror.net
  92. [2] devtools/client/sourceeditor/codemirror
  93. [3] devtools/client/sourceeditor/test/browser_codemirror.js
  94. [4] devtools/client/jar.mn
  95. [5] devtools/client/sourceeditor/editor.js