@maketribe/ms-app 3.0.35 → 3.0.37

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (93) hide show
  1. package/dist/cjs/dataview/material/material-group/MaterialGroupTree.js +1 -0
  2. package/dist/cjs/dataview/material/material-group/MaterialGroupTree.js.map +1 -1
  3. package/dist/cjs/dataview/member/MemberTable.js +2 -2
  4. package/dist/cjs/dataview/member/MemberTable.js.map +1 -1
  5. package/dist/cjs/dataview/menu/MenuTable.js +33 -0
  6. package/dist/cjs/dataview/menu/MenuTable.js.map +1 -1
  7. package/dist/cjs/layouts/components/header/tools.js +7 -2
  8. package/dist/cjs/layouts/components/header/tools.js.map +1 -1
  9. package/dist/cjs/node_modules/.pnpm/{@codemirror_autocomplete@6.11.1_@codemirror_language@6.9.3_@codemirror_state@6.3.2_@codemirro_dop6xooh6ucho44vivbvrw3b2e → @codemirror_autocomplete@6.15.0_@codemirror_language@6.10.1_@codemirror_state@6.4.1_@codemirr_djjyqdn7bhwopzrz2h2s2bwhzm}/node_modules/@codemirror/autocomplete/dist/index.js +77 -25
  10. package/dist/cjs/node_modules/.pnpm/@codemirror_autocomplete@6.15.0_@codemirror_language@6.10.1_@codemirror_state@6.4.1_@codemirr_djjyqdn7bhwopzrz2h2s2bwhzm/node_modules/@codemirror/autocomplete/dist/index.js.map +1 -0
  11. package/dist/cjs/node_modules/.pnpm/@codemirror_commands@6.3.2/node_modules/@codemirror/commands/dist/index.js +7 -1433
  12. package/dist/cjs/node_modules/.pnpm/@codemirror_commands@6.3.2/node_modules/@codemirror/commands/dist/index.js.map +1 -1
  13. package/dist/cjs/node_modules/.pnpm/@codemirror_commands@6.3.3/node_modules/@codemirror/commands/dist/index.js +1484 -0
  14. package/dist/cjs/node_modules/.pnpm/@codemirror_commands@6.3.3/node_modules/@codemirror/commands/dist/index.js.map +1 -0
  15. package/dist/cjs/node_modules/.pnpm/@codemirror_language@6.10.1/node_modules/@codemirror/language/dist/index.js +1751 -0
  16. package/dist/cjs/node_modules/.pnpm/@codemirror_language@6.10.1/node_modules/@codemirror/language/dist/index.js.map +1 -0
  17. package/dist/cjs/node_modules/.pnpm/@codemirror_language@6.9.3/node_modules/@codemirror/language/dist/index.js +0 -1030
  18. package/dist/cjs/node_modules/.pnpm/@codemirror_language@6.9.3/node_modules/@codemirror/language/dist/index.js.map +1 -1
  19. package/dist/cjs/node_modules/.pnpm/{@codemirror_lint@6.4.2 → @codemirror_lint@6.5.0}/node_modules/@codemirror/lint/dist/index.js +8 -7
  20. package/dist/cjs/node_modules/.pnpm/@codemirror_lint@6.5.0/node_modules/@codemirror/lint/dist/index.js.map +1 -0
  21. package/dist/cjs/node_modules/.pnpm/{@codemirror_search@6.5.5 → @codemirror_search@6.5.6}/node_modules/@codemirror/search/dist/index.js +9 -9
  22. package/dist/cjs/node_modules/.pnpm/@codemirror_search@6.5.6/node_modules/@codemirror/search/dist/index.js.map +1 -0
  23. package/dist/cjs/node_modules/.pnpm/@codemirror_state@6.3.2/node_modules/@codemirror/state/dist/index.js +0 -42
  24. package/dist/cjs/node_modules/.pnpm/@codemirror_state@6.3.2/node_modules/@codemirror/state/dist/index.js.map +1 -1
  25. package/dist/cjs/node_modules/.pnpm/@codemirror_state@6.4.1/node_modules/@codemirror/state/dist/index.js +3958 -0
  26. package/dist/cjs/node_modules/.pnpm/@codemirror_state@6.4.1/node_modules/@codemirror/state/dist/index.js.map +1 -0
  27. package/dist/cjs/node_modules/.pnpm/@codemirror_view@6.22.1/node_modules/@codemirror/view/dist/index.js +3 -2161
  28. package/dist/cjs/node_modules/.pnpm/@codemirror_view@6.22.1/node_modules/@codemirror/view/dist/index.js.map +1 -1
  29. package/dist/cjs/node_modules/.pnpm/@codemirror_view@6.26.1/node_modules/@codemirror/view/dist/index.js +10580 -0
  30. package/dist/cjs/node_modules/.pnpm/@codemirror_view@6.26.1/node_modules/@codemirror/view/dist/index.js.map +1 -0
  31. package/dist/cjs/node_modules/.pnpm/@lezer_common@1.2.1/node_modules/@lezer/common/dist/index.js +1668 -0
  32. package/dist/cjs/node_modules/.pnpm/@lezer_common@1.2.1/node_modules/@lezer/common/dist/index.js.map +1 -0
  33. package/dist/cjs/node_modules/.pnpm/{codemirror@6.0.1_@lezer_common@1.1.1 → codemirror@6.0.1_@lezer_common@1.2.1}/node_modules/codemirror/dist/index.js +7 -7
  34. package/dist/cjs/node_modules/.pnpm/{codemirror@6.0.1_@lezer_common@1.1.1 → codemirror@6.0.1_@lezer_common@1.2.1}/node_modules/codemirror/dist/index.js.map +1 -1
  35. package/dist/cjs/node_modules/.pnpm/style-mod@4.1.2/node_modules/style-mod/src/style-mod.js +177 -0
  36. package/dist/cjs/node_modules/.pnpm/style-mod@4.1.2/node_modules/style-mod/src/style-mod.js.map +1 -0
  37. package/dist/cjs/node_modules/.pnpm/vue-codemirror@6.1.1_codemirror@6.0.1_vue@3.3.4/node_modules/vue-codemirror/dist/vue-codemirror.esm.js +1 -1
  38. package/dist/esm/dataview/material/material-group/MaterialGroupTree.js +1 -0
  39. package/dist/esm/dataview/material/material-group/MaterialGroupTree.js.map +1 -1
  40. package/dist/esm/dataview/member/MemberTable.js +2 -2
  41. package/dist/esm/dataview/member/MemberTable.js.map +1 -1
  42. package/dist/esm/dataview/menu/MenuTable.js +34 -1
  43. package/dist/esm/dataview/menu/MenuTable.js.map +1 -1
  44. package/dist/esm/layouts/components/header/tools.js +7 -2
  45. package/dist/esm/layouts/components/header/tools.js.map +1 -1
  46. package/dist/esm/node_modules/.pnpm/{@codemirror_autocomplete@6.11.1_@codemirror_language@6.9.3_@codemirror_state@6.3.2_@codemirro_dop6xooh6ucho44vivbvrw3b2e → @codemirror_autocomplete@6.15.0_@codemirror_language@6.10.1_@codemirror_state@6.4.1_@codemirr_djjyqdn7bhwopzrz2h2s2bwhzm}/node_modules/@codemirror/autocomplete/dist/index.js +77 -25
  47. package/dist/esm/node_modules/.pnpm/@codemirror_autocomplete@6.15.0_@codemirror_language@6.10.1_@codemirror_state@6.4.1_@codemirr_djjyqdn7bhwopzrz2h2s2bwhzm/node_modules/@codemirror/autocomplete/dist/index.js.map +1 -0
  48. package/dist/esm/node_modules/.pnpm/@codemirror_commands@6.3.2/node_modules/@codemirror/commands/dist/index.js +4 -1357
  49. package/dist/esm/node_modules/.pnpm/@codemirror_commands@6.3.2/node_modules/@codemirror/commands/dist/index.js.map +1 -1
  50. package/dist/esm/node_modules/.pnpm/@codemirror_commands@6.3.3/node_modules/@codemirror/commands/dist/index.js +1408 -0
  51. package/dist/esm/node_modules/.pnpm/@codemirror_commands@6.3.3/node_modules/@codemirror/commands/dist/index.js.map +1 -0
  52. package/dist/esm/node_modules/.pnpm/@codemirror_language@6.10.1/node_modules/@codemirror/language/dist/index.js +1715 -0
  53. package/dist/esm/node_modules/.pnpm/@codemirror_language@6.10.1/node_modules/@codemirror/language/dist/index.js.map +1 -0
  54. package/dist/esm/node_modules/.pnpm/@codemirror_language@6.9.3/node_modules/@codemirror/language/dist/index.js +4 -1011
  55. package/dist/esm/node_modules/.pnpm/@codemirror_language@6.9.3/node_modules/@codemirror/language/dist/index.js.map +1 -1
  56. package/dist/esm/node_modules/.pnpm/{@codemirror_lint@6.4.2 → @codemirror_lint@6.5.0}/node_modules/@codemirror/lint/dist/index.js +8 -7
  57. package/dist/esm/node_modules/.pnpm/@codemirror_lint@6.5.0/node_modules/@codemirror/lint/dist/index.js.map +1 -0
  58. package/dist/esm/node_modules/.pnpm/{@codemirror_search@6.5.5 → @codemirror_search@6.5.6}/node_modules/@codemirror/search/dist/index.js +9 -9
  59. package/dist/esm/node_modules/.pnpm/@codemirror_search@6.5.6/node_modules/@codemirror/search/dist/index.js.map +1 -0
  60. package/dist/esm/node_modules/.pnpm/@codemirror_state@6.3.2/node_modules/@codemirror/state/dist/index.js +1 -41
  61. package/dist/esm/node_modules/.pnpm/@codemirror_state@6.3.2/node_modules/@codemirror/state/dist/index.js.map +1 -1
  62. package/dist/esm/node_modules/.pnpm/@codemirror_state@6.4.1/node_modules/@codemirror/state/dist/index.js +3930 -0
  63. package/dist/esm/node_modules/.pnpm/@codemirror_state@6.4.1/node_modules/@codemirror/state/dist/index.js.map +1 -0
  64. package/dist/esm/node_modules/.pnpm/@codemirror_view@6.22.1/node_modules/@codemirror/view/dist/index.js +5 -2142
  65. package/dist/esm/node_modules/.pnpm/@codemirror_view@6.22.1/node_modules/@codemirror/view/dist/index.js.map +1 -1
  66. package/dist/esm/node_modules/.pnpm/@codemirror_view@6.26.1/node_modules/@codemirror/view/dist/index.js +10548 -0
  67. package/dist/esm/node_modules/.pnpm/@codemirror_view@6.26.1/node_modules/@codemirror/view/dist/index.js.map +1 -0
  68. package/dist/esm/node_modules/.pnpm/@lezer_common@1.2.1/node_modules/@lezer/common/dist/index.js +1658 -0
  69. package/dist/esm/node_modules/.pnpm/@lezer_common@1.2.1/node_modules/@lezer/common/dist/index.js.map +1 -0
  70. package/dist/esm/node_modules/.pnpm/{codemirror@6.0.1_@lezer_common@1.1.1 → codemirror@6.0.1_@lezer_common@1.2.1}/node_modules/codemirror/dist/index.js +8 -8
  71. package/dist/esm/node_modules/.pnpm/{codemirror@6.0.1_@lezer_common@1.1.1 → codemirror@6.0.1_@lezer_common@1.2.1}/node_modules/codemirror/dist/index.js.map +1 -1
  72. package/dist/esm/node_modules/.pnpm/style-mod@4.1.2/node_modules/style-mod/src/style-mod.js +175 -0
  73. package/dist/esm/node_modules/.pnpm/style-mod@4.1.2/node_modules/style-mod/src/style-mod.js.map +1 -0
  74. package/dist/esm/node_modules/.pnpm/vue-codemirror@6.1.1_codemirror@6.0.1_vue@3.3.4/node_modules/vue-codemirror/dist/vue-codemirror.esm.js +1 -1
  75. package/dist/style/components/classify-search.css +1 -1
  76. package/dist/style/components/index.css +1 -1
  77. package/dist/style/index.css +2 -2
  78. package/dist/style/layouts/default/header.css +1 -1
  79. package/dist/style/layouts/default/index.css +1 -1
  80. package/dist/style/layouts/index.css +1 -1
  81. package/dist/style/src/components/classify-search.scss +5 -2
  82. package/dist/style/src/layouts/default/header.scss +4 -0
  83. package/package.json +3 -3
  84. package/src/dataview/material/material-group/MaterialGroupTree.ts +1 -0
  85. package/src/dataview/member/MemberTable.tsx +2 -2
  86. package/src/dataview/menu/MenuTable.ts +34 -1
  87. package/src/layouts/components/header/tools.tsx +6 -1
  88. package/dist/cjs/node_modules/.pnpm/@codemirror_autocomplete@6.11.1_@codemirror_language@6.9.3_@codemirror_state@6.3.2_@codemirro_dop6xooh6ucho44vivbvrw3b2e/node_modules/@codemirror/autocomplete/dist/index.js.map +0 -1
  89. package/dist/cjs/node_modules/.pnpm/@codemirror_lint@6.4.2/node_modules/@codemirror/lint/dist/index.js.map +0 -1
  90. package/dist/cjs/node_modules/.pnpm/@codemirror_search@6.5.5/node_modules/@codemirror/search/dist/index.js.map +0 -1
  91. package/dist/esm/node_modules/.pnpm/@codemirror_autocomplete@6.11.1_@codemirror_language@6.9.3_@codemirror_state@6.3.2_@codemirro_dop6xooh6ucho44vivbvrw3b2e/node_modules/@codemirror/autocomplete/dist/index.js.map +0 -1
  92. package/dist/esm/node_modules/.pnpm/@codemirror_lint@6.4.2/node_modules/@codemirror/lint/dist/index.js.map +0 -1
  93. package/dist/esm/node_modules/.pnpm/@codemirror_search@6.5.5/node_modules/@codemirror/search/dist/index.js.map +0 -1
@@ -0,0 +1,1408 @@
1
+ import { Facet, combineConfig, StateField, Transaction, ChangeSet, ChangeDesc, EditorSelection, countColumn, Text, Annotation, StateEffect, findClusterBreak } from '../../../../../@codemirror_state@6.4.1/node_modules/@codemirror/state/dist/index.js';
2
+ import { EditorView, Direction } from '../../../../../@codemirror_view@6.26.1/node_modules/@codemirror/view/dist/index.js';
3
+ import { IndentContext, getIndentation, indentString, matchBrackets, syntaxTree, indentUnit, getIndentUnit } from '../../../../../@codemirror_language@6.10.1/node_modules/@codemirror/language/dist/index.js';
4
+ import { NodeProp } from '../../../../../@lezer_common@1.2.1/node_modules/@lezer/common/dist/index.js';
5
+
6
+ /**
7
+ Comment or uncomment the current selection. Will use line comments
8
+ if available, otherwise falling back to block comments.
9
+ */
10
+ const toggleComment = target => {
11
+ let { state } = target, line = state.doc.lineAt(state.selection.main.from), config = getConfig(target.state, line.from);
12
+ return config.line ? toggleLineComment(target) : config.block ? toggleBlockCommentByLine(target) : false;
13
+ };
14
+ function command(f, option) {
15
+ return ({ state, dispatch }) => {
16
+ if (state.readOnly)
17
+ return false;
18
+ let tr = f(option, state);
19
+ if (!tr)
20
+ return false;
21
+ dispatch(state.update(tr));
22
+ return true;
23
+ };
24
+ }
25
+ /**
26
+ Comment or uncomment the current selection using line comments.
27
+ The line comment syntax is taken from the
28
+ [`commentTokens`](https://codemirror.net/6/docs/ref/#commands.CommentTokens) [language
29
+ data](https://codemirror.net/6/docs/ref/#state.EditorState.languageDataAt).
30
+ */
31
+ const toggleLineComment = /*@__PURE__*/command(changeLineComment, 0 /* CommentOption.Toggle */);
32
+ /**
33
+ Comment or uncomment the current selection using block comments.
34
+ The block comment syntax is taken from the
35
+ [`commentTokens`](https://codemirror.net/6/docs/ref/#commands.CommentTokens) [language
36
+ data](https://codemirror.net/6/docs/ref/#state.EditorState.languageDataAt).
37
+ */
38
+ const toggleBlockComment = /*@__PURE__*/command(changeBlockComment, 0 /* CommentOption.Toggle */);
39
+ /**
40
+ Comment or uncomment the lines around the current selection using
41
+ block comments.
42
+ */
43
+ const toggleBlockCommentByLine = /*@__PURE__*/command((o, s) => changeBlockComment(o, s, selectedLineRanges(s)), 0 /* CommentOption.Toggle */);
44
+ function getConfig(state, pos) {
45
+ let data = state.languageDataAt("commentTokens", pos);
46
+ return data.length ? data[0] : {};
47
+ }
48
+ const SearchMargin = 50;
49
+ /**
50
+ Determines if the given range is block-commented in the given
51
+ state.
52
+ */
53
+ function findBlockComment(state, { open, close }, from, to) {
54
+ let textBefore = state.sliceDoc(from - SearchMargin, from);
55
+ let textAfter = state.sliceDoc(to, to + SearchMargin);
56
+ let spaceBefore = /\s*$/.exec(textBefore)[0].length, spaceAfter = /^\s*/.exec(textAfter)[0].length;
57
+ let beforeOff = textBefore.length - spaceBefore;
58
+ if (textBefore.slice(beforeOff - open.length, beforeOff) == open &&
59
+ textAfter.slice(spaceAfter, spaceAfter + close.length) == close) {
60
+ return { open: { pos: from - spaceBefore, margin: spaceBefore && 1 },
61
+ close: { pos: to + spaceAfter, margin: spaceAfter && 1 } };
62
+ }
63
+ let startText, endText;
64
+ if (to - from <= 2 * SearchMargin) {
65
+ startText = endText = state.sliceDoc(from, to);
66
+ }
67
+ else {
68
+ startText = state.sliceDoc(from, from + SearchMargin);
69
+ endText = state.sliceDoc(to - SearchMargin, to);
70
+ }
71
+ let startSpace = /^\s*/.exec(startText)[0].length, endSpace = /\s*$/.exec(endText)[0].length;
72
+ let endOff = endText.length - endSpace - close.length;
73
+ if (startText.slice(startSpace, startSpace + open.length) == open &&
74
+ endText.slice(endOff, endOff + close.length) == close) {
75
+ return { open: { pos: from + startSpace + open.length,
76
+ margin: /\s/.test(startText.charAt(startSpace + open.length)) ? 1 : 0 },
77
+ close: { pos: to - endSpace - close.length,
78
+ margin: /\s/.test(endText.charAt(endOff - 1)) ? 1 : 0 } };
79
+ }
80
+ return null;
81
+ }
82
+ function selectedLineRanges(state) {
83
+ let ranges = [];
84
+ for (let r of state.selection.ranges) {
85
+ let fromLine = state.doc.lineAt(r.from);
86
+ let toLine = r.to <= fromLine.to ? fromLine : state.doc.lineAt(r.to);
87
+ let last = ranges.length - 1;
88
+ if (last >= 0 && ranges[last].to > fromLine.from)
89
+ ranges[last].to = toLine.to;
90
+ else
91
+ ranges.push({ from: fromLine.from + /^\s*/.exec(fromLine.text)[0].length, to: toLine.to });
92
+ }
93
+ return ranges;
94
+ }
95
+ // Performs toggle, comment and uncomment of block comments in
96
+ // languages that support them.
97
+ function changeBlockComment(option, state, ranges = state.selection.ranges) {
98
+ let tokens = ranges.map(r => getConfig(state, r.from).block);
99
+ if (!tokens.every(c => c))
100
+ return null;
101
+ let comments = ranges.map((r, i) => findBlockComment(state, tokens[i], r.from, r.to));
102
+ if (option != 2 /* CommentOption.Uncomment */ && !comments.every(c => c)) {
103
+ return { changes: state.changes(ranges.map((range, i) => {
104
+ if (comments[i])
105
+ return [];
106
+ return [{ from: range.from, insert: tokens[i].open + " " }, { from: range.to, insert: " " + tokens[i].close }];
107
+ })) };
108
+ }
109
+ else if (option != 1 /* CommentOption.Comment */ && comments.some(c => c)) {
110
+ let changes = [];
111
+ for (let i = 0, comment; i < comments.length; i++)
112
+ if (comment = comments[i]) {
113
+ let token = tokens[i], { open, close } = comment;
114
+ changes.push({ from: open.pos - token.open.length, to: open.pos + open.margin }, { from: close.pos - close.margin, to: close.pos + token.close.length });
115
+ }
116
+ return { changes };
117
+ }
118
+ return null;
119
+ }
120
+ // Performs toggle, comment and uncomment of line comments.
121
+ function changeLineComment(option, state, ranges = state.selection.ranges) {
122
+ let lines = [];
123
+ let prevLine = -1;
124
+ for (let { from, to } of ranges) {
125
+ let startI = lines.length, minIndent = 1e9;
126
+ let token = getConfig(state, from).line;
127
+ if (!token)
128
+ continue;
129
+ for (let pos = from; pos <= to;) {
130
+ let line = state.doc.lineAt(pos);
131
+ if (line.from > prevLine && (from == to || to > line.from)) {
132
+ prevLine = line.from;
133
+ let indent = /^\s*/.exec(line.text)[0].length;
134
+ let empty = indent == line.length;
135
+ let comment = line.text.slice(indent, indent + token.length) == token ? indent : -1;
136
+ if (indent < line.text.length && indent < minIndent)
137
+ minIndent = indent;
138
+ lines.push({ line, comment, token, indent, empty, single: false });
139
+ }
140
+ pos = line.to + 1;
141
+ }
142
+ if (minIndent < 1e9)
143
+ for (let i = startI; i < lines.length; i++)
144
+ if (lines[i].indent < lines[i].line.text.length)
145
+ lines[i].indent = minIndent;
146
+ if (lines.length == startI + 1)
147
+ lines[startI].single = true;
148
+ }
149
+ if (option != 2 /* CommentOption.Uncomment */ && lines.some(l => l.comment < 0 && (!l.empty || l.single))) {
150
+ let changes = [];
151
+ for (let { line, token, indent, empty, single } of lines)
152
+ if (single || !empty)
153
+ changes.push({ from: line.from + indent, insert: token + " " });
154
+ let changeSet = state.changes(changes);
155
+ return { changes: changeSet, selection: state.selection.map(changeSet, 1) };
156
+ }
157
+ else if (option != 1 /* CommentOption.Comment */ && lines.some(l => l.comment >= 0)) {
158
+ let changes = [];
159
+ for (let { line, comment, token } of lines)
160
+ if (comment >= 0) {
161
+ let from = line.from + comment, to = from + token.length;
162
+ if (line.text[to - line.from] == " ")
163
+ to++;
164
+ changes.push({ from, to });
165
+ }
166
+ return { changes };
167
+ }
168
+ return null;
169
+ }
170
+
171
+ const fromHistory = /*@__PURE__*/Annotation.define();
172
+ /**
173
+ Transaction annotation that will prevent that transaction from
174
+ being combined with other transactions in the undo history. Given
175
+ `"before"`, it'll prevent merging with previous transactions. With
176
+ `"after"`, subsequent transactions won't be combined with this
177
+ one. With `"full"`, the transaction is isolated on both sides.
178
+ */
179
+ const isolateHistory = /*@__PURE__*/Annotation.define();
180
+ /**
181
+ This facet provides a way to register functions that, given a
182
+ transaction, provide a set of effects that the history should
183
+ store when inverting the transaction. This can be used to
184
+ integrate some kinds of effects in the history, so that they can
185
+ be undone (and redone again).
186
+ */
187
+ const invertedEffects = /*@__PURE__*/Facet.define();
188
+ const historyConfig = /*@__PURE__*/Facet.define({
189
+ combine(configs) {
190
+ return combineConfig(configs, {
191
+ minDepth: 100,
192
+ newGroupDelay: 500,
193
+ joinToEvent: (_t, isAdjacent) => isAdjacent,
194
+ }, {
195
+ minDepth: Math.max,
196
+ newGroupDelay: Math.min,
197
+ joinToEvent: (a, b) => (tr, adj) => a(tr, adj) || b(tr, adj)
198
+ });
199
+ }
200
+ });
201
+ const historyField_ = /*@__PURE__*/StateField.define({
202
+ create() {
203
+ return HistoryState.empty;
204
+ },
205
+ update(state, tr) {
206
+ let config = tr.state.facet(historyConfig);
207
+ let fromHist = tr.annotation(fromHistory);
208
+ if (fromHist) {
209
+ let item = HistEvent.fromTransaction(tr, fromHist.selection), from = fromHist.side;
210
+ let other = from == 0 /* BranchName.Done */ ? state.undone : state.done;
211
+ if (item)
212
+ other = updateBranch(other, other.length, config.minDepth, item);
213
+ else
214
+ other = addSelection(other, tr.startState.selection);
215
+ return new HistoryState(from == 0 /* BranchName.Done */ ? fromHist.rest : other, from == 0 /* BranchName.Done */ ? other : fromHist.rest);
216
+ }
217
+ let isolate = tr.annotation(isolateHistory);
218
+ if (isolate == "full" || isolate == "before")
219
+ state = state.isolate();
220
+ if (tr.annotation(Transaction.addToHistory) === false)
221
+ return !tr.changes.empty ? state.addMapping(tr.changes.desc) : state;
222
+ let event = HistEvent.fromTransaction(tr);
223
+ let time = tr.annotation(Transaction.time), userEvent = tr.annotation(Transaction.userEvent);
224
+ if (event)
225
+ state = state.addChanges(event, time, userEvent, config, tr);
226
+ else if (tr.selection)
227
+ state = state.addSelection(tr.startState.selection, time, userEvent, config.newGroupDelay);
228
+ if (isolate == "full" || isolate == "after")
229
+ state = state.isolate();
230
+ return state;
231
+ },
232
+ toJSON(value) {
233
+ return { done: value.done.map(e => e.toJSON()), undone: value.undone.map(e => e.toJSON()) };
234
+ },
235
+ fromJSON(json) {
236
+ return new HistoryState(json.done.map(HistEvent.fromJSON), json.undone.map(HistEvent.fromJSON));
237
+ }
238
+ });
239
+ /**
240
+ Create a history extension with the given configuration.
241
+ */
242
+ function history(config = {}) {
243
+ return [
244
+ historyField_,
245
+ historyConfig.of(config),
246
+ EditorView.domEventHandlers({
247
+ beforeinput(e, view) {
248
+ let command = e.inputType == "historyUndo" ? undo : e.inputType == "historyRedo" ? redo : null;
249
+ if (!command)
250
+ return false;
251
+ e.preventDefault();
252
+ return command(view);
253
+ }
254
+ })
255
+ ];
256
+ }
257
+ function cmd(side, selection) {
258
+ return function ({ state, dispatch }) {
259
+ if (!selection && state.readOnly)
260
+ return false;
261
+ let historyState = state.field(historyField_, false);
262
+ if (!historyState)
263
+ return false;
264
+ let tr = historyState.pop(side, state, selection);
265
+ if (!tr)
266
+ return false;
267
+ dispatch(tr);
268
+ return true;
269
+ };
270
+ }
271
+ /**
272
+ Undo a single group of history events. Returns false if no group
273
+ was available.
274
+ */
275
+ const undo = /*@__PURE__*/cmd(0 /* BranchName.Done */, false);
276
+ /**
277
+ Redo a group of history events. Returns false if no group was
278
+ available.
279
+ */
280
+ const redo = /*@__PURE__*/cmd(1 /* BranchName.Undone */, false);
281
+ /**
282
+ Undo a change or selection change.
283
+ */
284
+ const undoSelection = /*@__PURE__*/cmd(0 /* BranchName.Done */, true);
285
+ /**
286
+ Redo a change or selection change.
287
+ */
288
+ const redoSelection = /*@__PURE__*/cmd(1 /* BranchName.Undone */, true);
289
+ // History events store groups of changes or effects that need to be
290
+ // undone/redone together.
291
+ class HistEvent {
292
+ constructor(
293
+ // The changes in this event. Normal events hold at least one
294
+ // change or effect. But it may be necessary to store selection
295
+ // events before the first change, in which case a special type of
296
+ // instance is created which doesn't hold any changes, with
297
+ // changes == startSelection == undefined
298
+ changes,
299
+ // The effects associated with this event
300
+ effects,
301
+ // Accumulated mapping (from addToHistory==false) that should be
302
+ // applied to events below this one.
303
+ mapped,
304
+ // The selection before this event
305
+ startSelection,
306
+ // Stores selection changes after this event, to be used for
307
+ // selection undo/redo.
308
+ selectionsAfter) {
309
+ this.changes = changes;
310
+ this.effects = effects;
311
+ this.mapped = mapped;
312
+ this.startSelection = startSelection;
313
+ this.selectionsAfter = selectionsAfter;
314
+ }
315
+ setSelAfter(after) {
316
+ return new HistEvent(this.changes, this.effects, this.mapped, this.startSelection, after);
317
+ }
318
+ toJSON() {
319
+ var _a, _b, _c;
320
+ return {
321
+ changes: (_a = this.changes) === null || _a === void 0 ? void 0 : _a.toJSON(),
322
+ mapped: (_b = this.mapped) === null || _b === void 0 ? void 0 : _b.toJSON(),
323
+ startSelection: (_c = this.startSelection) === null || _c === void 0 ? void 0 : _c.toJSON(),
324
+ selectionsAfter: this.selectionsAfter.map(s => s.toJSON())
325
+ };
326
+ }
327
+ static fromJSON(json) {
328
+ return new HistEvent(json.changes && ChangeSet.fromJSON(json.changes), [], json.mapped && ChangeDesc.fromJSON(json.mapped), json.startSelection && EditorSelection.fromJSON(json.startSelection), json.selectionsAfter.map(EditorSelection.fromJSON));
329
+ }
330
+ // This does not check `addToHistory` and such, it assumes the
331
+ // transaction needs to be converted to an item. Returns null when
332
+ // there are no changes or effects in the transaction.
333
+ static fromTransaction(tr, selection) {
334
+ let effects = none;
335
+ for (let invert of tr.startState.facet(invertedEffects)) {
336
+ let result = invert(tr);
337
+ if (result.length)
338
+ effects = effects.concat(result);
339
+ }
340
+ if (!effects.length && tr.changes.empty)
341
+ return null;
342
+ return new HistEvent(tr.changes.invert(tr.startState.doc), effects, undefined, selection || tr.startState.selection, none);
343
+ }
344
+ static selection(selections) {
345
+ return new HistEvent(undefined, none, undefined, undefined, selections);
346
+ }
347
+ }
348
+ function updateBranch(branch, to, maxLen, newEvent) {
349
+ let start = to + 1 > maxLen + 20 ? to - maxLen - 1 : 0;
350
+ let newBranch = branch.slice(start, to);
351
+ newBranch.push(newEvent);
352
+ return newBranch;
353
+ }
354
+ function isAdjacent(a, b) {
355
+ let ranges = [], isAdjacent = false;
356
+ a.iterChangedRanges((f, t) => ranges.push(f, t));
357
+ b.iterChangedRanges((_f, _t, f, t) => {
358
+ for (let i = 0; i < ranges.length;) {
359
+ let from = ranges[i++], to = ranges[i++];
360
+ if (t >= from && f <= to)
361
+ isAdjacent = true;
362
+ }
363
+ });
364
+ return isAdjacent;
365
+ }
366
+ function eqSelectionShape(a, b) {
367
+ return a.ranges.length == b.ranges.length &&
368
+ a.ranges.filter((r, i) => r.empty != b.ranges[i].empty).length === 0;
369
+ }
370
+ function conc(a, b) {
371
+ return !a.length ? b : !b.length ? a : a.concat(b);
372
+ }
373
+ const none = [];
374
+ const MaxSelectionsPerEvent = 200;
375
+ function addSelection(branch, selection) {
376
+ if (!branch.length) {
377
+ return [HistEvent.selection([selection])];
378
+ }
379
+ else {
380
+ let lastEvent = branch[branch.length - 1];
381
+ let sels = lastEvent.selectionsAfter.slice(Math.max(0, lastEvent.selectionsAfter.length - MaxSelectionsPerEvent));
382
+ if (sels.length && sels[sels.length - 1].eq(selection))
383
+ return branch;
384
+ sels.push(selection);
385
+ return updateBranch(branch, branch.length - 1, 1e9, lastEvent.setSelAfter(sels));
386
+ }
387
+ }
388
+ // Assumes the top item has one or more selectionAfter values
389
+ function popSelection(branch) {
390
+ let last = branch[branch.length - 1];
391
+ let newBranch = branch.slice();
392
+ newBranch[branch.length - 1] = last.setSelAfter(last.selectionsAfter.slice(0, last.selectionsAfter.length - 1));
393
+ return newBranch;
394
+ }
395
+ // Add a mapping to the top event in the given branch. If this maps
396
+ // away all the changes and effects in that item, drop it and
397
+ // propagate the mapping to the next item.
398
+ function addMappingToBranch(branch, mapping) {
399
+ if (!branch.length)
400
+ return branch;
401
+ let length = branch.length, selections = none;
402
+ while (length) {
403
+ let event = mapEvent(branch[length - 1], mapping, selections);
404
+ if (event.changes && !event.changes.empty || event.effects.length) { // Event survived mapping
405
+ let result = branch.slice(0, length);
406
+ result[length - 1] = event;
407
+ return result;
408
+ }
409
+ else { // Drop this event, since there's no changes or effects left
410
+ mapping = event.mapped;
411
+ length--;
412
+ selections = event.selectionsAfter;
413
+ }
414
+ }
415
+ return selections.length ? [HistEvent.selection(selections)] : none;
416
+ }
417
+ function mapEvent(event, mapping, extraSelections) {
418
+ let selections = conc(event.selectionsAfter.length ? event.selectionsAfter.map(s => s.map(mapping)) : none, extraSelections);
419
+ // Change-less events don't store mappings (they are always the last event in a branch)
420
+ if (!event.changes)
421
+ return HistEvent.selection(selections);
422
+ let mappedChanges = event.changes.map(mapping), before = mapping.mapDesc(event.changes, true);
423
+ let fullMapping = event.mapped ? event.mapped.composeDesc(before) : before;
424
+ return new HistEvent(mappedChanges, StateEffect.mapEffects(event.effects, mapping), fullMapping, event.startSelection.map(before), selections);
425
+ }
426
+ const joinableUserEvent = /^(input\.type|delete)($|\.)/;
427
+ class HistoryState {
428
+ constructor(done, undone, prevTime = 0, prevUserEvent = undefined) {
429
+ this.done = done;
430
+ this.undone = undone;
431
+ this.prevTime = prevTime;
432
+ this.prevUserEvent = prevUserEvent;
433
+ }
434
+ isolate() {
435
+ return this.prevTime ? new HistoryState(this.done, this.undone) : this;
436
+ }
437
+ addChanges(event, time, userEvent, config, tr) {
438
+ let done = this.done, lastEvent = done[done.length - 1];
439
+ if (lastEvent && lastEvent.changes && !lastEvent.changes.empty && event.changes &&
440
+ (!userEvent || joinableUserEvent.test(userEvent)) &&
441
+ ((!lastEvent.selectionsAfter.length &&
442
+ time - this.prevTime < config.newGroupDelay &&
443
+ config.joinToEvent(tr, isAdjacent(lastEvent.changes, event.changes))) ||
444
+ // For compose (but not compose.start) events, always join with previous event
445
+ userEvent == "input.type.compose")) {
446
+ done = updateBranch(done, done.length - 1, config.minDepth, new HistEvent(event.changes.compose(lastEvent.changes), conc(event.effects, lastEvent.effects), lastEvent.mapped, lastEvent.startSelection, none));
447
+ }
448
+ else {
449
+ done = updateBranch(done, done.length, config.minDepth, event);
450
+ }
451
+ return new HistoryState(done, none, time, userEvent);
452
+ }
453
+ addSelection(selection, time, userEvent, newGroupDelay) {
454
+ let last = this.done.length ? this.done[this.done.length - 1].selectionsAfter : none;
455
+ if (last.length > 0 &&
456
+ time - this.prevTime < newGroupDelay &&
457
+ userEvent == this.prevUserEvent && userEvent && /^select($|\.)/.test(userEvent) &&
458
+ eqSelectionShape(last[last.length - 1], selection))
459
+ return this;
460
+ return new HistoryState(addSelection(this.done, selection), this.undone, time, userEvent);
461
+ }
462
+ addMapping(mapping) {
463
+ return new HistoryState(addMappingToBranch(this.done, mapping), addMappingToBranch(this.undone, mapping), this.prevTime, this.prevUserEvent);
464
+ }
465
+ pop(side, state, onlySelection) {
466
+ let branch = side == 0 /* BranchName.Done */ ? this.done : this.undone;
467
+ if (branch.length == 0)
468
+ return null;
469
+ let event = branch[branch.length - 1], selection = event.selectionsAfter[0] || state.selection;
470
+ if (onlySelection && event.selectionsAfter.length) {
471
+ return state.update({
472
+ selection: event.selectionsAfter[event.selectionsAfter.length - 1],
473
+ annotations: fromHistory.of({ side, rest: popSelection(branch), selection }),
474
+ userEvent: side == 0 /* BranchName.Done */ ? "select.undo" : "select.redo",
475
+ scrollIntoView: true
476
+ });
477
+ }
478
+ else if (!event.changes) {
479
+ return null;
480
+ }
481
+ else {
482
+ let rest = branch.length == 1 ? none : branch.slice(0, branch.length - 1);
483
+ if (event.mapped)
484
+ rest = addMappingToBranch(rest, event.mapped);
485
+ return state.update({
486
+ changes: event.changes,
487
+ selection: event.startSelection,
488
+ effects: event.effects,
489
+ annotations: fromHistory.of({ side, rest, selection }),
490
+ filter: false,
491
+ userEvent: side == 0 /* BranchName.Done */ ? "undo" : "redo",
492
+ scrollIntoView: true
493
+ });
494
+ }
495
+ }
496
+ }
497
+ HistoryState.empty = /*@__PURE__*/new HistoryState(none, none);
498
+ /**
499
+ Default key bindings for the undo history.
500
+
501
+ - Mod-z: [`undo`](https://codemirror.net/6/docs/ref/#commands.undo).
502
+ - Mod-y (Mod-Shift-z on macOS) + Ctrl-Shift-z on Linux: [`redo`](https://codemirror.net/6/docs/ref/#commands.redo).
503
+ - Mod-u: [`undoSelection`](https://codemirror.net/6/docs/ref/#commands.undoSelection).
504
+ - Alt-u (Mod-Shift-u on macOS): [`redoSelection`](https://codemirror.net/6/docs/ref/#commands.redoSelection).
505
+ */
506
+ const historyKeymap = [
507
+ { key: "Mod-z", run: undo, preventDefault: true },
508
+ { key: "Mod-y", mac: "Mod-Shift-z", run: redo, preventDefault: true },
509
+ { linux: "Ctrl-Shift-z", run: redo, preventDefault: true },
510
+ { key: "Mod-u", run: undoSelection, preventDefault: true },
511
+ { key: "Alt-u", mac: "Mod-Shift-u", run: redoSelection, preventDefault: true }
512
+ ];
513
+
514
+ function updateSel(sel, by) {
515
+ return EditorSelection.create(sel.ranges.map(by), sel.mainIndex);
516
+ }
517
+ function setSel(state, selection) {
518
+ return state.update({ selection, scrollIntoView: true, userEvent: "select" });
519
+ }
520
+ function moveSel({ state, dispatch }, how) {
521
+ let selection = updateSel(state.selection, how);
522
+ if (selection.eq(state.selection, true))
523
+ return false;
524
+ dispatch(setSel(state, selection));
525
+ return true;
526
+ }
527
+ function rangeEnd(range, forward) {
528
+ return EditorSelection.cursor(forward ? range.to : range.from);
529
+ }
530
+ function cursorByChar(view, forward) {
531
+ return moveSel(view, range => range.empty ? view.moveByChar(range, forward) : rangeEnd(range, forward));
532
+ }
533
+ function ltrAtCursor(view) {
534
+ return view.textDirectionAt(view.state.selection.main.head) == Direction.LTR;
535
+ }
536
+ /**
537
+ Move the selection one character to the left (which is backward in
538
+ left-to-right text, forward in right-to-left text).
539
+ */
540
+ const cursorCharLeft = view => cursorByChar(view, !ltrAtCursor(view));
541
+ /**
542
+ Move the selection one character to the right.
543
+ */
544
+ const cursorCharRight = view => cursorByChar(view, ltrAtCursor(view));
545
+ function cursorByGroup(view, forward) {
546
+ return moveSel(view, range => range.empty ? view.moveByGroup(range, forward) : rangeEnd(range, forward));
547
+ }
548
+ /**
549
+ Move the selection to the left across one group of word or
550
+ non-word (but also non-space) characters.
551
+ */
552
+ const cursorGroupLeft = view => cursorByGroup(view, !ltrAtCursor(view));
553
+ /**
554
+ Move the selection one group to the right.
555
+ */
556
+ const cursorGroupRight = view => cursorByGroup(view, ltrAtCursor(view));
557
+ function interestingNode(state, node, bracketProp) {
558
+ if (node.type.prop(bracketProp))
559
+ return true;
560
+ let len = node.to - node.from;
561
+ return len && (len > 2 || /[^\s,.;:]/.test(state.sliceDoc(node.from, node.to))) || node.firstChild;
562
+ }
563
+ function moveBySyntax(state, start, forward) {
564
+ let pos = syntaxTree(state).resolveInner(start.head);
565
+ let bracketProp = forward ? NodeProp.closedBy : NodeProp.openedBy;
566
+ // Scan forward through child nodes to see if there's an interesting
567
+ // node ahead.
568
+ for (let at = start.head;;) {
569
+ let next = forward ? pos.childAfter(at) : pos.childBefore(at);
570
+ if (!next)
571
+ break;
572
+ if (interestingNode(state, next, bracketProp))
573
+ pos = next;
574
+ else
575
+ at = forward ? next.to : next.from;
576
+ }
577
+ let bracket = pos.type.prop(bracketProp), match, newPos;
578
+ if (bracket && (match = forward ? matchBrackets(state, pos.from, 1) : matchBrackets(state, pos.to, -1)) && match.matched)
579
+ newPos = forward ? match.end.to : match.end.from;
580
+ else
581
+ newPos = forward ? pos.to : pos.from;
582
+ return EditorSelection.cursor(newPos, forward ? -1 : 1);
583
+ }
584
+ /**
585
+ Move the cursor over the next syntactic element to the left.
586
+ */
587
+ const cursorSyntaxLeft = view => moveSel(view, range => moveBySyntax(view.state, range, !ltrAtCursor(view)));
588
+ /**
589
+ Move the cursor over the next syntactic element to the right.
590
+ */
591
+ const cursorSyntaxRight = view => moveSel(view, range => moveBySyntax(view.state, range, ltrAtCursor(view)));
592
+ function cursorByLine(view, forward) {
593
+ return moveSel(view, range => {
594
+ if (!range.empty)
595
+ return rangeEnd(range, forward);
596
+ let moved = view.moveVertically(range, forward);
597
+ return moved.head != range.head ? moved : view.moveToLineBoundary(range, forward);
598
+ });
599
+ }
600
+ /**
601
+ Move the selection one line up.
602
+ */
603
+ const cursorLineUp = view => cursorByLine(view, false);
604
+ /**
605
+ Move the selection one line down.
606
+ */
607
+ const cursorLineDown = view => cursorByLine(view, true);
608
+ function pageInfo(view) {
609
+ let selfScroll = view.scrollDOM.clientHeight < view.scrollDOM.scrollHeight - 2;
610
+ let marginTop = 0, marginBottom = 0, height;
611
+ if (selfScroll) {
612
+ for (let source of view.state.facet(EditorView.scrollMargins)) {
613
+ let margins = source(view);
614
+ if (margins === null || margins === void 0 ? void 0 : margins.top)
615
+ marginTop = Math.max(margins === null || margins === void 0 ? void 0 : margins.top, marginTop);
616
+ if (margins === null || margins === void 0 ? void 0 : margins.bottom)
617
+ marginBottom = Math.max(margins === null || margins === void 0 ? void 0 : margins.bottom, marginBottom);
618
+ }
619
+ height = view.scrollDOM.clientHeight - marginTop - marginBottom;
620
+ }
621
+ else {
622
+ height = (view.dom.ownerDocument.defaultView || window).innerHeight;
623
+ }
624
+ return { marginTop, marginBottom, selfScroll,
625
+ height: Math.max(view.defaultLineHeight, height - 5) };
626
+ }
627
+ function cursorByPage(view, forward) {
628
+ let page = pageInfo(view);
629
+ let { state } = view, selection = updateSel(state.selection, range => {
630
+ return range.empty ? view.moveVertically(range, forward, page.height)
631
+ : rangeEnd(range, forward);
632
+ });
633
+ if (selection.eq(state.selection))
634
+ return false;
635
+ let effect;
636
+ if (page.selfScroll) {
637
+ let startPos = view.coordsAtPos(state.selection.main.head);
638
+ let scrollRect = view.scrollDOM.getBoundingClientRect();
639
+ let scrollTop = scrollRect.top + page.marginTop, scrollBottom = scrollRect.bottom - page.marginBottom;
640
+ if (startPos && startPos.top > scrollTop && startPos.bottom < scrollBottom)
641
+ effect = EditorView.scrollIntoView(selection.main.head, { y: "start", yMargin: startPos.top - scrollTop });
642
+ }
643
+ view.dispatch(setSel(state, selection), { effects: effect });
644
+ return true;
645
+ }
646
+ /**
647
+ Move the selection one page up.
648
+ */
649
+ const cursorPageUp = view => cursorByPage(view, false);
650
+ /**
651
+ Move the selection one page down.
652
+ */
653
+ const cursorPageDown = view => cursorByPage(view, true);
654
+ function moveByLineBoundary(view, start, forward) {
655
+ let line = view.lineBlockAt(start.head), moved = view.moveToLineBoundary(start, forward);
656
+ if (moved.head == start.head && moved.head != (forward ? line.to : line.from))
657
+ moved = view.moveToLineBoundary(start, forward, false);
658
+ if (!forward && moved.head == line.from && line.length) {
659
+ let space = /^\s*/.exec(view.state.sliceDoc(line.from, Math.min(line.from + 100, line.to)))[0].length;
660
+ if (space && start.head != line.from + space)
661
+ moved = EditorSelection.cursor(line.from + space);
662
+ }
663
+ return moved;
664
+ }
665
+ /**
666
+ Move the selection to the next line wrap point, or to the end of
667
+ the line if there isn't one left on this line.
668
+ */
669
+ const cursorLineBoundaryForward = view => moveSel(view, range => moveByLineBoundary(view, range, true));
670
+ /**
671
+ Move the selection to previous line wrap point, or failing that to
672
+ the start of the line. If the line is indented, and the cursor
673
+ isn't already at the end of the indentation, this will move to the
674
+ end of the indentation instead of the start of the line.
675
+ */
676
+ const cursorLineBoundaryBackward = view => moveSel(view, range => moveByLineBoundary(view, range, false));
677
+ /**
678
+ Move the selection one line wrap point to the left.
679
+ */
680
+ const cursorLineBoundaryLeft = view => moveSel(view, range => moveByLineBoundary(view, range, !ltrAtCursor(view)));
681
+ /**
682
+ Move the selection one line wrap point to the right.
683
+ */
684
+ const cursorLineBoundaryRight = view => moveSel(view, range => moveByLineBoundary(view, range, ltrAtCursor(view)));
685
+ /**
686
+ Move the selection to the start of the line.
687
+ */
688
+ const cursorLineStart = view => moveSel(view, range => EditorSelection.cursor(view.lineBlockAt(range.head).from, 1));
689
+ /**
690
+ Move the selection to the end of the line.
691
+ */
692
+ const cursorLineEnd = view => moveSel(view, range => EditorSelection.cursor(view.lineBlockAt(range.head).to, -1));
693
+ function toMatchingBracket(state, dispatch, extend) {
694
+ let found = false, selection = updateSel(state.selection, range => {
695
+ let matching = matchBrackets(state, range.head, -1)
696
+ || matchBrackets(state, range.head, 1)
697
+ || (range.head > 0 && matchBrackets(state, range.head - 1, 1))
698
+ || (range.head < state.doc.length && matchBrackets(state, range.head + 1, -1));
699
+ if (!matching || !matching.end)
700
+ return range;
701
+ found = true;
702
+ let head = matching.start.from == range.head ? matching.end.to : matching.end.from;
703
+ return extend ? EditorSelection.range(range.anchor, head) : EditorSelection.cursor(head);
704
+ });
705
+ if (!found)
706
+ return false;
707
+ dispatch(setSel(state, selection));
708
+ return true;
709
+ }
710
+ /**
711
+ Move the selection to the bracket matching the one it is currently
712
+ on, if any.
713
+ */
714
+ const cursorMatchingBracket = ({ state, dispatch }) => toMatchingBracket(state, dispatch, false);
715
+ function extendSel(view, how) {
716
+ let selection = updateSel(view.state.selection, range => {
717
+ let head = how(range);
718
+ return EditorSelection.range(range.anchor, head.head, head.goalColumn, head.bidiLevel || undefined);
719
+ });
720
+ if (selection.eq(view.state.selection))
721
+ return false;
722
+ view.dispatch(setSel(view.state, selection));
723
+ return true;
724
+ }
725
+ function selectByChar(view, forward) {
726
+ return extendSel(view, range => view.moveByChar(range, forward));
727
+ }
728
+ /**
729
+ Move the selection head one character to the left, while leaving
730
+ the anchor in place.
731
+ */
732
+ const selectCharLeft = view => selectByChar(view, !ltrAtCursor(view));
733
+ /**
734
+ Move the selection head one character to the right.
735
+ */
736
+ const selectCharRight = view => selectByChar(view, ltrAtCursor(view));
737
+ function selectByGroup(view, forward) {
738
+ return extendSel(view, range => view.moveByGroup(range, forward));
739
+ }
740
+ /**
741
+ Move the selection head one [group](https://codemirror.net/6/docs/ref/#commands.cursorGroupLeft) to
742
+ the left.
743
+ */
744
+ const selectGroupLeft = view => selectByGroup(view, !ltrAtCursor(view));
745
+ /**
746
+ Move the selection head one group to the right.
747
+ */
748
+ const selectGroupRight = view => selectByGroup(view, ltrAtCursor(view));
749
+ /**
750
+ Move the selection head over the next syntactic element to the left.
751
+ */
752
+ const selectSyntaxLeft = view => extendSel(view, range => moveBySyntax(view.state, range, !ltrAtCursor(view)));
753
+ /**
754
+ Move the selection head over the next syntactic element to the right.
755
+ */
756
+ const selectSyntaxRight = view => extendSel(view, range => moveBySyntax(view.state, range, ltrAtCursor(view)));
757
+ function selectByLine(view, forward) {
758
+ return extendSel(view, range => view.moveVertically(range, forward));
759
+ }
760
+ /**
761
+ Move the selection head one line up.
762
+ */
763
+ const selectLineUp = view => selectByLine(view, false);
764
+ /**
765
+ Move the selection head one line down.
766
+ */
767
+ const selectLineDown = view => selectByLine(view, true);
768
+ function selectByPage(view, forward) {
769
+ return extendSel(view, range => view.moveVertically(range, forward, pageInfo(view).height));
770
+ }
771
+ /**
772
+ Move the selection head one page up.
773
+ */
774
+ const selectPageUp = view => selectByPage(view, false);
775
+ /**
776
+ Move the selection head one page down.
777
+ */
778
+ const selectPageDown = view => selectByPage(view, true);
779
+ /**
780
+ Move the selection head to the next line boundary.
781
+ */
782
+ const selectLineBoundaryForward = view => extendSel(view, range => moveByLineBoundary(view, range, true));
783
+ /**
784
+ Move the selection head to the previous line boundary.
785
+ */
786
+ const selectLineBoundaryBackward = view => extendSel(view, range => moveByLineBoundary(view, range, false));
787
+ /**
788
+ Move the selection head one line boundary to the left.
789
+ */
790
+ const selectLineBoundaryLeft = view => extendSel(view, range => moveByLineBoundary(view, range, !ltrAtCursor(view)));
791
+ /**
792
+ Move the selection head one line boundary to the right.
793
+ */
794
+ const selectLineBoundaryRight = view => extendSel(view, range => moveByLineBoundary(view, range, ltrAtCursor(view)));
795
+ /**
796
+ Move the selection head to the start of the line.
797
+ */
798
+ const selectLineStart = view => extendSel(view, range => EditorSelection.cursor(view.lineBlockAt(range.head).from));
799
+ /**
800
+ Move the selection head to the end of the line.
801
+ */
802
+ const selectLineEnd = view => extendSel(view, range => EditorSelection.cursor(view.lineBlockAt(range.head).to));
803
+ /**
804
+ Move the selection to the start of the document.
805
+ */
806
+ const cursorDocStart = ({ state, dispatch }) => {
807
+ dispatch(setSel(state, { anchor: 0 }));
808
+ return true;
809
+ };
810
+ /**
811
+ Move the selection to the end of the document.
812
+ */
813
+ const cursorDocEnd = ({ state, dispatch }) => {
814
+ dispatch(setSel(state, { anchor: state.doc.length }));
815
+ return true;
816
+ };
817
+ /**
818
+ Move the selection head to the start of the document.
819
+ */
820
+ const selectDocStart = ({ state, dispatch }) => {
821
+ dispatch(setSel(state, { anchor: state.selection.main.anchor, head: 0 }));
822
+ return true;
823
+ };
824
+ /**
825
+ Move the selection head to the end of the document.
826
+ */
827
+ const selectDocEnd = ({ state, dispatch }) => {
828
+ dispatch(setSel(state, { anchor: state.selection.main.anchor, head: state.doc.length }));
829
+ return true;
830
+ };
831
+ /**
832
+ Select the entire document.
833
+ */
834
+ const selectAll = ({ state, dispatch }) => {
835
+ dispatch(state.update({ selection: { anchor: 0, head: state.doc.length }, userEvent: "select" }));
836
+ return true;
837
+ };
838
+ /**
839
+ Expand the selection to cover entire lines.
840
+ */
841
+ const selectLine = ({ state, dispatch }) => {
842
+ let ranges = selectedLineBlocks(state).map(({ from, to }) => EditorSelection.range(from, Math.min(to + 1, state.doc.length)));
843
+ dispatch(state.update({ selection: EditorSelection.create(ranges), userEvent: "select" }));
844
+ return true;
845
+ };
846
+ /**
847
+ Select the next syntactic construct that is larger than the
848
+ selection. Note that this will only work insofar as the language
849
+ [provider](https://codemirror.net/6/docs/ref/#language.language) you use builds up a full
850
+ syntax tree.
851
+ */
852
+ const selectParentSyntax = ({ state, dispatch }) => {
853
+ let selection = updateSel(state.selection, range => {
854
+ var _a;
855
+ let stack = syntaxTree(state).resolveStack(range.from, 1);
856
+ for (let cur = stack; cur; cur = cur.next) {
857
+ let { node } = cur;
858
+ if (((node.from < range.from && node.to >= range.to) ||
859
+ (node.to > range.to && node.from <= range.from)) &&
860
+ ((_a = node.parent) === null || _a === void 0 ? void 0 : _a.parent))
861
+ return EditorSelection.range(node.to, node.from);
862
+ }
863
+ return range;
864
+ });
865
+ dispatch(setSel(state, selection));
866
+ return true;
867
+ };
868
+ /**
869
+ Simplify the current selection. When multiple ranges are selected,
870
+ reduce it to its main range. Otherwise, if the selection is
871
+ non-empty, convert it to a cursor selection.
872
+ */
873
+ const simplifySelection = ({ state, dispatch }) => {
874
+ let cur = state.selection, selection = null;
875
+ if (cur.ranges.length > 1)
876
+ selection = EditorSelection.create([cur.main]);
877
+ else if (!cur.main.empty)
878
+ selection = EditorSelection.create([EditorSelection.cursor(cur.main.head)]);
879
+ if (!selection)
880
+ return false;
881
+ dispatch(setSel(state, selection));
882
+ return true;
883
+ };
884
+ function deleteBy(target, by) {
885
+ if (target.state.readOnly)
886
+ return false;
887
+ let event = "delete.selection", { state } = target;
888
+ let changes = state.changeByRange(range => {
889
+ let { from, to } = range;
890
+ if (from == to) {
891
+ let towards = by(range);
892
+ if (towards < from) {
893
+ event = "delete.backward";
894
+ towards = skipAtomic(target, towards, false);
895
+ }
896
+ else if (towards > from) {
897
+ event = "delete.forward";
898
+ towards = skipAtomic(target, towards, true);
899
+ }
900
+ from = Math.min(from, towards);
901
+ to = Math.max(to, towards);
902
+ }
903
+ else {
904
+ from = skipAtomic(target, from, false);
905
+ to = skipAtomic(target, to, true);
906
+ }
907
+ return from == to ? { range } : { changes: { from, to }, range: EditorSelection.cursor(from, from < range.head ? -1 : 1) };
908
+ });
909
+ if (changes.changes.empty)
910
+ return false;
911
+ target.dispatch(state.update(changes, {
912
+ scrollIntoView: true,
913
+ userEvent: event,
914
+ effects: event == "delete.selection" ? EditorView.announce.of(state.phrase("Selection deleted")) : undefined
915
+ }));
916
+ return true;
917
+ }
918
+ function skipAtomic(target, pos, forward) {
919
+ if (target instanceof EditorView)
920
+ for (let ranges of target.state.facet(EditorView.atomicRanges).map(f => f(target)))
921
+ ranges.between(pos, pos, (from, to) => {
922
+ if (from < pos && to > pos)
923
+ pos = forward ? to : from;
924
+ });
925
+ return pos;
926
+ }
927
+ const deleteByChar = (target, forward) => deleteBy(target, range => {
928
+ let pos = range.from, { state } = target, line = state.doc.lineAt(pos), before, targetPos;
929
+ if (!forward && pos > line.from && pos < line.from + 200 &&
930
+ !/[^ \t]/.test(before = line.text.slice(0, pos - line.from))) {
931
+ if (before[before.length - 1] == "\t")
932
+ return pos - 1;
933
+ let col = countColumn(before, state.tabSize), drop = col % getIndentUnit(state) || getIndentUnit(state);
934
+ for (let i = 0; i < drop && before[before.length - 1 - i] == " "; i++)
935
+ pos--;
936
+ targetPos = pos;
937
+ }
938
+ else {
939
+ targetPos = findClusterBreak(line.text, pos - line.from, forward, forward) + line.from;
940
+ if (targetPos == pos && line.number != (forward ? state.doc.lines : 1))
941
+ targetPos += forward ? 1 : -1;
942
+ else if (!forward && /[\ufe00-\ufe0f]/.test(line.text.slice(targetPos - line.from, pos - line.from)))
943
+ targetPos = findClusterBreak(line.text, targetPos - line.from, false, false) + line.from;
944
+ }
945
+ return targetPos;
946
+ });
947
+ /**
948
+ Delete the selection, or, for cursor selections, the character
949
+ before the cursor.
950
+ */
951
+ const deleteCharBackward = view => deleteByChar(view, false);
952
+ /**
953
+ Delete the selection or the character after the cursor.
954
+ */
955
+ const deleteCharForward = view => deleteByChar(view, true);
956
+ const deleteByGroup = (target, forward) => deleteBy(target, range => {
957
+ let pos = range.head, { state } = target, line = state.doc.lineAt(pos);
958
+ let categorize = state.charCategorizer(pos);
959
+ for (let cat = null;;) {
960
+ if (pos == (forward ? line.to : line.from)) {
961
+ if (pos == range.head && line.number != (forward ? state.doc.lines : 1))
962
+ pos += forward ? 1 : -1;
963
+ break;
964
+ }
965
+ let next = findClusterBreak(line.text, pos - line.from, forward) + line.from;
966
+ let nextChar = line.text.slice(Math.min(pos, next) - line.from, Math.max(pos, next) - line.from);
967
+ let nextCat = categorize(nextChar);
968
+ if (cat != null && nextCat != cat)
969
+ break;
970
+ if (nextChar != " " || pos != range.head)
971
+ cat = nextCat;
972
+ pos = next;
973
+ }
974
+ return pos;
975
+ });
976
+ /**
977
+ Delete the selection or backward until the end of the next
978
+ [group](https://codemirror.net/6/docs/ref/#view.EditorView.moveByGroup), only skipping groups of
979
+ whitespace when they consist of a single space.
980
+ */
981
+ const deleteGroupBackward = target => deleteByGroup(target, false);
982
+ /**
983
+ Delete the selection or forward until the end of the next group.
984
+ */
985
+ const deleteGroupForward = target => deleteByGroup(target, true);
986
+ /**
987
+ Delete the selection, or, if it is a cursor selection, delete to
988
+ the end of the line. If the cursor is directly at the end of the
989
+ line, delete the line break after it.
990
+ */
991
+ const deleteToLineEnd = view => deleteBy(view, range => {
992
+ let lineEnd = view.lineBlockAt(range.head).to;
993
+ return range.head < lineEnd ? lineEnd : Math.min(view.state.doc.length, range.head + 1);
994
+ });
995
+ /**
996
+ Delete the selection, or, if it is a cursor selection, delete to
997
+ the start of the line or the next line wrap before the cursor.
998
+ */
999
+ const deleteLineBoundaryBackward = view => deleteBy(view, range => {
1000
+ let lineStart = view.moveToLineBoundary(range, false).head;
1001
+ return range.head > lineStart ? lineStart : Math.max(0, range.head - 1);
1002
+ });
1003
+ /**
1004
+ Delete the selection, or, if it is a cursor selection, delete to
1005
+ the end of the line or the next line wrap after the cursor.
1006
+ */
1007
+ const deleteLineBoundaryForward = view => deleteBy(view, range => {
1008
+ let lineStart = view.moveToLineBoundary(range, true).head;
1009
+ return range.head < lineStart ? lineStart : Math.min(view.state.doc.length, range.head + 1);
1010
+ });
1011
+ /**
1012
+ Replace each selection range with a line break, leaving the cursor
1013
+ on the line before the break.
1014
+ */
1015
+ const splitLine = ({ state, dispatch }) => {
1016
+ if (state.readOnly)
1017
+ return false;
1018
+ let changes = state.changeByRange(range => {
1019
+ return { changes: { from: range.from, to: range.to, insert: Text.of(["", ""]) },
1020
+ range: EditorSelection.cursor(range.from) };
1021
+ });
1022
+ dispatch(state.update(changes, { scrollIntoView: true, userEvent: "input" }));
1023
+ return true;
1024
+ };
1025
+ /**
1026
+ Flip the characters before and after the cursor(s).
1027
+ */
1028
+ const transposeChars = ({ state, dispatch }) => {
1029
+ if (state.readOnly)
1030
+ return false;
1031
+ let changes = state.changeByRange(range => {
1032
+ if (!range.empty || range.from == 0 || range.from == state.doc.length)
1033
+ return { range };
1034
+ let pos = range.from, line = state.doc.lineAt(pos);
1035
+ let from = pos == line.from ? pos - 1 : findClusterBreak(line.text, pos - line.from, false) + line.from;
1036
+ let to = pos == line.to ? pos + 1 : findClusterBreak(line.text, pos - line.from, true) + line.from;
1037
+ return { changes: { from, to, insert: state.doc.slice(pos, to).append(state.doc.slice(from, pos)) },
1038
+ range: EditorSelection.cursor(to) };
1039
+ });
1040
+ if (changes.changes.empty)
1041
+ return false;
1042
+ dispatch(state.update(changes, { scrollIntoView: true, userEvent: "move.character" }));
1043
+ return true;
1044
+ };
1045
+ function selectedLineBlocks(state) {
1046
+ let blocks = [], upto = -1;
1047
+ for (let range of state.selection.ranges) {
1048
+ let startLine = state.doc.lineAt(range.from), endLine = state.doc.lineAt(range.to);
1049
+ if (!range.empty && range.to == endLine.from)
1050
+ endLine = state.doc.lineAt(range.to - 1);
1051
+ if (upto >= startLine.number) {
1052
+ let prev = blocks[blocks.length - 1];
1053
+ prev.to = endLine.to;
1054
+ prev.ranges.push(range);
1055
+ }
1056
+ else {
1057
+ blocks.push({ from: startLine.from, to: endLine.to, ranges: [range] });
1058
+ }
1059
+ upto = endLine.number + 1;
1060
+ }
1061
+ return blocks;
1062
+ }
1063
+ function moveLine(state, dispatch, forward) {
1064
+ if (state.readOnly)
1065
+ return false;
1066
+ let changes = [], ranges = [];
1067
+ for (let block of selectedLineBlocks(state)) {
1068
+ if (forward ? block.to == state.doc.length : block.from == 0)
1069
+ continue;
1070
+ let nextLine = state.doc.lineAt(forward ? block.to + 1 : block.from - 1);
1071
+ let size = nextLine.length + 1;
1072
+ if (forward) {
1073
+ changes.push({ from: block.to, to: nextLine.to }, { from: block.from, insert: nextLine.text + state.lineBreak });
1074
+ for (let r of block.ranges)
1075
+ ranges.push(EditorSelection.range(Math.min(state.doc.length, r.anchor + size), Math.min(state.doc.length, r.head + size)));
1076
+ }
1077
+ else {
1078
+ changes.push({ from: nextLine.from, to: block.from }, { from: block.to, insert: state.lineBreak + nextLine.text });
1079
+ for (let r of block.ranges)
1080
+ ranges.push(EditorSelection.range(r.anchor - size, r.head - size));
1081
+ }
1082
+ }
1083
+ if (!changes.length)
1084
+ return false;
1085
+ dispatch(state.update({
1086
+ changes,
1087
+ scrollIntoView: true,
1088
+ selection: EditorSelection.create(ranges, state.selection.mainIndex),
1089
+ userEvent: "move.line"
1090
+ }));
1091
+ return true;
1092
+ }
1093
+ /**
1094
+ Move the selected lines up one line.
1095
+ */
1096
+ const moveLineUp = ({ state, dispatch }) => moveLine(state, dispatch, false);
1097
+ /**
1098
+ Move the selected lines down one line.
1099
+ */
1100
+ const moveLineDown = ({ state, dispatch }) => moveLine(state, dispatch, true);
1101
+ function copyLine(state, dispatch, forward) {
1102
+ if (state.readOnly)
1103
+ return false;
1104
+ let changes = [];
1105
+ for (let block of selectedLineBlocks(state)) {
1106
+ if (forward)
1107
+ changes.push({ from: block.from, insert: state.doc.slice(block.from, block.to) + state.lineBreak });
1108
+ else
1109
+ changes.push({ from: block.to, insert: state.lineBreak + state.doc.slice(block.from, block.to) });
1110
+ }
1111
+ dispatch(state.update({ changes, scrollIntoView: true, userEvent: "input.copyline" }));
1112
+ return true;
1113
+ }
1114
+ /**
1115
+ Create a copy of the selected lines. Keep the selection in the top copy.
1116
+ */
1117
+ const copyLineUp = ({ state, dispatch }) => copyLine(state, dispatch, false);
1118
+ /**
1119
+ Create a copy of the selected lines. Keep the selection in the bottom copy.
1120
+ */
1121
+ const copyLineDown = ({ state, dispatch }) => copyLine(state, dispatch, true);
1122
+ /**
1123
+ Delete selected lines.
1124
+ */
1125
+ const deleteLine = view => {
1126
+ if (view.state.readOnly)
1127
+ return false;
1128
+ let { state } = view, changes = state.changes(selectedLineBlocks(state).map(({ from, to }) => {
1129
+ if (from > 0)
1130
+ from--;
1131
+ else if (to < state.doc.length)
1132
+ to++;
1133
+ return { from, to };
1134
+ }));
1135
+ let selection = updateSel(state.selection, range => view.moveVertically(range, true)).map(changes);
1136
+ view.dispatch({ changes, selection, scrollIntoView: true, userEvent: "delete.line" });
1137
+ return true;
1138
+ };
1139
+ function isBetweenBrackets(state, pos) {
1140
+ if (/\(\)|\[\]|\{\}/.test(state.sliceDoc(pos - 1, pos + 1)))
1141
+ return { from: pos, to: pos };
1142
+ let context = syntaxTree(state).resolveInner(pos);
1143
+ let before = context.childBefore(pos), after = context.childAfter(pos), closedBy;
1144
+ if (before && after && before.to <= pos && after.from >= pos &&
1145
+ (closedBy = before.type.prop(NodeProp.closedBy)) && closedBy.indexOf(after.name) > -1 &&
1146
+ state.doc.lineAt(before.to).from == state.doc.lineAt(after.from).from &&
1147
+ !/\S/.test(state.sliceDoc(before.to, after.from)))
1148
+ return { from: before.to, to: after.from };
1149
+ return null;
1150
+ }
1151
+ /**
1152
+ Replace the selection with a newline and indent the newly created
1153
+ line(s). If the current line consists only of whitespace, this
1154
+ will also delete that whitespace. When the cursor is between
1155
+ matching brackets, an additional newline will be inserted after
1156
+ the cursor.
1157
+ */
1158
+ const insertNewlineAndIndent = /*@__PURE__*/newlineAndIndent(false);
1159
+ /**
1160
+ Create a blank, indented line below the current line.
1161
+ */
1162
+ const insertBlankLine = /*@__PURE__*/newlineAndIndent(true);
1163
+ function newlineAndIndent(atEof) {
1164
+ return ({ state, dispatch }) => {
1165
+ if (state.readOnly)
1166
+ return false;
1167
+ let changes = state.changeByRange(range => {
1168
+ let { from, to } = range, line = state.doc.lineAt(from);
1169
+ let explode = !atEof && from == to && isBetweenBrackets(state, from);
1170
+ if (atEof)
1171
+ from = to = (to <= line.to ? line : state.doc.lineAt(to)).to;
1172
+ let cx = new IndentContext(state, { simulateBreak: from, simulateDoubleBreak: !!explode });
1173
+ let indent = getIndentation(cx, from);
1174
+ if (indent == null)
1175
+ indent = countColumn(/^\s*/.exec(state.doc.lineAt(from).text)[0], state.tabSize);
1176
+ while (to < line.to && /\s/.test(line.text[to - line.from]))
1177
+ to++;
1178
+ if (explode)
1179
+ ({ from, to } = explode);
1180
+ else if (from > line.from && from < line.from + 100 && !/\S/.test(line.text.slice(0, from)))
1181
+ from = line.from;
1182
+ let insert = ["", indentString(state, indent)];
1183
+ if (explode)
1184
+ insert.push(indentString(state, cx.lineIndent(line.from, -1)));
1185
+ return { changes: { from, to, insert: Text.of(insert) },
1186
+ range: EditorSelection.cursor(from + 1 + insert[1].length) };
1187
+ });
1188
+ dispatch(state.update(changes, { scrollIntoView: true, userEvent: "input" }));
1189
+ return true;
1190
+ };
1191
+ }
1192
+ function changeBySelectedLine(state, f) {
1193
+ let atLine = -1;
1194
+ return state.changeByRange(range => {
1195
+ let changes = [];
1196
+ for (let pos = range.from; pos <= range.to;) {
1197
+ let line = state.doc.lineAt(pos);
1198
+ if (line.number > atLine && (range.empty || range.to > line.from)) {
1199
+ f(line, changes, range);
1200
+ atLine = line.number;
1201
+ }
1202
+ pos = line.to + 1;
1203
+ }
1204
+ let changeSet = state.changes(changes);
1205
+ return { changes,
1206
+ range: EditorSelection.range(changeSet.mapPos(range.anchor, 1), changeSet.mapPos(range.head, 1)) };
1207
+ });
1208
+ }
1209
+ /**
1210
+ Auto-indent the selected lines. This uses the [indentation service
1211
+ facet](https://codemirror.net/6/docs/ref/#language.indentService) as source for auto-indent
1212
+ information.
1213
+ */
1214
+ const indentSelection = ({ state, dispatch }) => {
1215
+ if (state.readOnly)
1216
+ return false;
1217
+ let updated = Object.create(null);
1218
+ let context = new IndentContext(state, { overrideIndentation: start => {
1219
+ let found = updated[start];
1220
+ return found == null ? -1 : found;
1221
+ } });
1222
+ let changes = changeBySelectedLine(state, (line, changes, range) => {
1223
+ let indent = getIndentation(context, line.from);
1224
+ if (indent == null)
1225
+ return;
1226
+ if (!/\S/.test(line.text))
1227
+ indent = 0;
1228
+ let cur = /^\s*/.exec(line.text)[0];
1229
+ let norm = indentString(state, indent);
1230
+ if (cur != norm || range.from < line.from + cur.length) {
1231
+ updated[line.from] = indent;
1232
+ changes.push({ from: line.from, to: line.from + cur.length, insert: norm });
1233
+ }
1234
+ });
1235
+ if (!changes.changes.empty)
1236
+ dispatch(state.update(changes, { userEvent: "indent" }));
1237
+ return true;
1238
+ };
1239
+ /**
1240
+ Add a [unit](https://codemirror.net/6/docs/ref/#language.indentUnit) of indentation to all selected
1241
+ lines.
1242
+ */
1243
+ const indentMore = ({ state, dispatch }) => {
1244
+ if (state.readOnly)
1245
+ return false;
1246
+ dispatch(state.update(changeBySelectedLine(state, (line, changes) => {
1247
+ changes.push({ from: line.from, insert: state.facet(indentUnit) });
1248
+ }), { userEvent: "input.indent" }));
1249
+ return true;
1250
+ };
1251
+ /**
1252
+ Remove a [unit](https://codemirror.net/6/docs/ref/#language.indentUnit) of indentation from all
1253
+ selected lines.
1254
+ */
1255
+ const indentLess = ({ state, dispatch }) => {
1256
+ if (state.readOnly)
1257
+ return false;
1258
+ dispatch(state.update(changeBySelectedLine(state, (line, changes) => {
1259
+ let space = /^\s*/.exec(line.text)[0];
1260
+ if (!space)
1261
+ return;
1262
+ let col = countColumn(space, state.tabSize), keep = 0;
1263
+ let insert = indentString(state, Math.max(0, col - getIndentUnit(state)));
1264
+ while (keep < space.length && keep < insert.length && space.charCodeAt(keep) == insert.charCodeAt(keep))
1265
+ keep++;
1266
+ changes.push({ from: line.from + keep, to: line.from + space.length, insert: insert.slice(keep) });
1267
+ }), { userEvent: "delete.dedent" }));
1268
+ return true;
1269
+ };
1270
+ /**
1271
+ Array of key bindings containing the Emacs-style bindings that are
1272
+ available on macOS by default.
1273
+
1274
+ - Ctrl-b: [`cursorCharLeft`](https://codemirror.net/6/docs/ref/#commands.cursorCharLeft) ([`selectCharLeft`](https://codemirror.net/6/docs/ref/#commands.selectCharLeft) with Shift)
1275
+ - Ctrl-f: [`cursorCharRight`](https://codemirror.net/6/docs/ref/#commands.cursorCharRight) ([`selectCharRight`](https://codemirror.net/6/docs/ref/#commands.selectCharRight) with Shift)
1276
+ - Ctrl-p: [`cursorLineUp`](https://codemirror.net/6/docs/ref/#commands.cursorLineUp) ([`selectLineUp`](https://codemirror.net/6/docs/ref/#commands.selectLineUp) with Shift)
1277
+ - Ctrl-n: [`cursorLineDown`](https://codemirror.net/6/docs/ref/#commands.cursorLineDown) ([`selectLineDown`](https://codemirror.net/6/docs/ref/#commands.selectLineDown) with Shift)
1278
+ - Ctrl-a: [`cursorLineStart`](https://codemirror.net/6/docs/ref/#commands.cursorLineStart) ([`selectLineStart`](https://codemirror.net/6/docs/ref/#commands.selectLineStart) with Shift)
1279
+ - Ctrl-e: [`cursorLineEnd`](https://codemirror.net/6/docs/ref/#commands.cursorLineEnd) ([`selectLineEnd`](https://codemirror.net/6/docs/ref/#commands.selectLineEnd) with Shift)
1280
+ - Ctrl-d: [`deleteCharForward`](https://codemirror.net/6/docs/ref/#commands.deleteCharForward)
1281
+ - Ctrl-h: [`deleteCharBackward`](https://codemirror.net/6/docs/ref/#commands.deleteCharBackward)
1282
+ - Ctrl-k: [`deleteToLineEnd`](https://codemirror.net/6/docs/ref/#commands.deleteToLineEnd)
1283
+ - Ctrl-Alt-h: [`deleteGroupBackward`](https://codemirror.net/6/docs/ref/#commands.deleteGroupBackward)
1284
+ - Ctrl-o: [`splitLine`](https://codemirror.net/6/docs/ref/#commands.splitLine)
1285
+ - Ctrl-t: [`transposeChars`](https://codemirror.net/6/docs/ref/#commands.transposeChars)
1286
+ - Ctrl-v: [`cursorPageDown`](https://codemirror.net/6/docs/ref/#commands.cursorPageDown)
1287
+ - Alt-v: [`cursorPageUp`](https://codemirror.net/6/docs/ref/#commands.cursorPageUp)
1288
+ */
1289
+ const emacsStyleKeymap = [
1290
+ { key: "Ctrl-b", run: cursorCharLeft, shift: selectCharLeft, preventDefault: true },
1291
+ { key: "Ctrl-f", run: cursorCharRight, shift: selectCharRight },
1292
+ { key: "Ctrl-p", run: cursorLineUp, shift: selectLineUp },
1293
+ { key: "Ctrl-n", run: cursorLineDown, shift: selectLineDown },
1294
+ { key: "Ctrl-a", run: cursorLineStart, shift: selectLineStart },
1295
+ { key: "Ctrl-e", run: cursorLineEnd, shift: selectLineEnd },
1296
+ { key: "Ctrl-d", run: deleteCharForward },
1297
+ { key: "Ctrl-h", run: deleteCharBackward },
1298
+ { key: "Ctrl-k", run: deleteToLineEnd },
1299
+ { key: "Ctrl-Alt-h", run: deleteGroupBackward },
1300
+ { key: "Ctrl-o", run: splitLine },
1301
+ { key: "Ctrl-t", run: transposeChars },
1302
+ { key: "Ctrl-v", run: cursorPageDown },
1303
+ ];
1304
+ /**
1305
+ An array of key bindings closely sticking to platform-standard or
1306
+ widely used bindings. (This includes the bindings from
1307
+ [`emacsStyleKeymap`](https://codemirror.net/6/docs/ref/#commands.emacsStyleKeymap), with their `key`
1308
+ property changed to `mac`.)
1309
+
1310
+ - ArrowLeft: [`cursorCharLeft`](https://codemirror.net/6/docs/ref/#commands.cursorCharLeft) ([`selectCharLeft`](https://codemirror.net/6/docs/ref/#commands.selectCharLeft) with Shift)
1311
+ - ArrowRight: [`cursorCharRight`](https://codemirror.net/6/docs/ref/#commands.cursorCharRight) ([`selectCharRight`](https://codemirror.net/6/docs/ref/#commands.selectCharRight) with Shift)
1312
+ - Ctrl-ArrowLeft (Alt-ArrowLeft on macOS): [`cursorGroupLeft`](https://codemirror.net/6/docs/ref/#commands.cursorGroupLeft) ([`selectGroupLeft`](https://codemirror.net/6/docs/ref/#commands.selectGroupLeft) with Shift)
1313
+ - Ctrl-ArrowRight (Alt-ArrowRight on macOS): [`cursorGroupRight`](https://codemirror.net/6/docs/ref/#commands.cursorGroupRight) ([`selectGroupRight`](https://codemirror.net/6/docs/ref/#commands.selectGroupRight) with Shift)
1314
+ - Cmd-ArrowLeft (on macOS): [`cursorLineStart`](https://codemirror.net/6/docs/ref/#commands.cursorLineStart) ([`selectLineStart`](https://codemirror.net/6/docs/ref/#commands.selectLineStart) with Shift)
1315
+ - Cmd-ArrowRight (on macOS): [`cursorLineEnd`](https://codemirror.net/6/docs/ref/#commands.cursorLineEnd) ([`selectLineEnd`](https://codemirror.net/6/docs/ref/#commands.selectLineEnd) with Shift)
1316
+ - ArrowUp: [`cursorLineUp`](https://codemirror.net/6/docs/ref/#commands.cursorLineUp) ([`selectLineUp`](https://codemirror.net/6/docs/ref/#commands.selectLineUp) with Shift)
1317
+ - ArrowDown: [`cursorLineDown`](https://codemirror.net/6/docs/ref/#commands.cursorLineDown) ([`selectLineDown`](https://codemirror.net/6/docs/ref/#commands.selectLineDown) with Shift)
1318
+ - Cmd-ArrowUp (on macOS): [`cursorDocStart`](https://codemirror.net/6/docs/ref/#commands.cursorDocStart) ([`selectDocStart`](https://codemirror.net/6/docs/ref/#commands.selectDocStart) with Shift)
1319
+ - Cmd-ArrowDown (on macOS): [`cursorDocEnd`](https://codemirror.net/6/docs/ref/#commands.cursorDocEnd) ([`selectDocEnd`](https://codemirror.net/6/docs/ref/#commands.selectDocEnd) with Shift)
1320
+ - Ctrl-ArrowUp (on macOS): [`cursorPageUp`](https://codemirror.net/6/docs/ref/#commands.cursorPageUp) ([`selectPageUp`](https://codemirror.net/6/docs/ref/#commands.selectPageUp) with Shift)
1321
+ - Ctrl-ArrowDown (on macOS): [`cursorPageDown`](https://codemirror.net/6/docs/ref/#commands.cursorPageDown) ([`selectPageDown`](https://codemirror.net/6/docs/ref/#commands.selectPageDown) with Shift)
1322
+ - PageUp: [`cursorPageUp`](https://codemirror.net/6/docs/ref/#commands.cursorPageUp) ([`selectPageUp`](https://codemirror.net/6/docs/ref/#commands.selectPageUp) with Shift)
1323
+ - PageDown: [`cursorPageDown`](https://codemirror.net/6/docs/ref/#commands.cursorPageDown) ([`selectPageDown`](https://codemirror.net/6/docs/ref/#commands.selectPageDown) with Shift)
1324
+ - Home: [`cursorLineBoundaryBackward`](https://codemirror.net/6/docs/ref/#commands.cursorLineBoundaryBackward) ([`selectLineBoundaryBackward`](https://codemirror.net/6/docs/ref/#commands.selectLineBoundaryBackward) with Shift)
1325
+ - End: [`cursorLineBoundaryForward`](https://codemirror.net/6/docs/ref/#commands.cursorLineBoundaryForward) ([`selectLineBoundaryForward`](https://codemirror.net/6/docs/ref/#commands.selectLineBoundaryForward) with Shift)
1326
+ - Ctrl-Home (Cmd-Home on macOS): [`cursorDocStart`](https://codemirror.net/6/docs/ref/#commands.cursorDocStart) ([`selectDocStart`](https://codemirror.net/6/docs/ref/#commands.selectDocStart) with Shift)
1327
+ - Ctrl-End (Cmd-Home on macOS): [`cursorDocEnd`](https://codemirror.net/6/docs/ref/#commands.cursorDocEnd) ([`selectDocEnd`](https://codemirror.net/6/docs/ref/#commands.selectDocEnd) with Shift)
1328
+ - Enter: [`insertNewlineAndIndent`](https://codemirror.net/6/docs/ref/#commands.insertNewlineAndIndent)
1329
+ - Ctrl-a (Cmd-a on macOS): [`selectAll`](https://codemirror.net/6/docs/ref/#commands.selectAll)
1330
+ - Backspace: [`deleteCharBackward`](https://codemirror.net/6/docs/ref/#commands.deleteCharBackward)
1331
+ - Delete: [`deleteCharForward`](https://codemirror.net/6/docs/ref/#commands.deleteCharForward)
1332
+ - Ctrl-Backspace (Alt-Backspace on macOS): [`deleteGroupBackward`](https://codemirror.net/6/docs/ref/#commands.deleteGroupBackward)
1333
+ - Ctrl-Delete (Alt-Delete on macOS): [`deleteGroupForward`](https://codemirror.net/6/docs/ref/#commands.deleteGroupForward)
1334
+ - Cmd-Backspace (macOS): [`deleteLineBoundaryBackward`](https://codemirror.net/6/docs/ref/#commands.deleteLineBoundaryBackward).
1335
+ - Cmd-Delete (macOS): [`deleteLineBoundaryForward`](https://codemirror.net/6/docs/ref/#commands.deleteLineBoundaryForward).
1336
+ */
1337
+ const standardKeymap = /*@__PURE__*/[
1338
+ { key: "ArrowLeft", run: cursorCharLeft, shift: selectCharLeft, preventDefault: true },
1339
+ { key: "Mod-ArrowLeft", mac: "Alt-ArrowLeft", run: cursorGroupLeft, shift: selectGroupLeft, preventDefault: true },
1340
+ { mac: "Cmd-ArrowLeft", run: cursorLineBoundaryLeft, shift: selectLineBoundaryLeft, preventDefault: true },
1341
+ { key: "ArrowRight", run: cursorCharRight, shift: selectCharRight, preventDefault: true },
1342
+ { key: "Mod-ArrowRight", mac: "Alt-ArrowRight", run: cursorGroupRight, shift: selectGroupRight, preventDefault: true },
1343
+ { mac: "Cmd-ArrowRight", run: cursorLineBoundaryRight, shift: selectLineBoundaryRight, preventDefault: true },
1344
+ { key: "ArrowUp", run: cursorLineUp, shift: selectLineUp, preventDefault: true },
1345
+ { mac: "Cmd-ArrowUp", run: cursorDocStart, shift: selectDocStart },
1346
+ { mac: "Ctrl-ArrowUp", run: cursorPageUp, shift: selectPageUp },
1347
+ { key: "ArrowDown", run: cursorLineDown, shift: selectLineDown, preventDefault: true },
1348
+ { mac: "Cmd-ArrowDown", run: cursorDocEnd, shift: selectDocEnd },
1349
+ { mac: "Ctrl-ArrowDown", run: cursorPageDown, shift: selectPageDown },
1350
+ { key: "PageUp", run: cursorPageUp, shift: selectPageUp },
1351
+ { key: "PageDown", run: cursorPageDown, shift: selectPageDown },
1352
+ { key: "Home", run: cursorLineBoundaryBackward, shift: selectLineBoundaryBackward, preventDefault: true },
1353
+ { key: "Mod-Home", run: cursorDocStart, shift: selectDocStart },
1354
+ { key: "End", run: cursorLineBoundaryForward, shift: selectLineBoundaryForward, preventDefault: true },
1355
+ { key: "Mod-End", run: cursorDocEnd, shift: selectDocEnd },
1356
+ { key: "Enter", run: insertNewlineAndIndent },
1357
+ { key: "Mod-a", run: selectAll },
1358
+ { key: "Backspace", run: deleteCharBackward, shift: deleteCharBackward },
1359
+ { key: "Delete", run: deleteCharForward },
1360
+ { key: "Mod-Backspace", mac: "Alt-Backspace", run: deleteGroupBackward },
1361
+ { key: "Mod-Delete", mac: "Alt-Delete", run: deleteGroupForward },
1362
+ { mac: "Mod-Backspace", run: deleteLineBoundaryBackward },
1363
+ { mac: "Mod-Delete", run: deleteLineBoundaryForward }
1364
+ ].concat(/*@__PURE__*/emacsStyleKeymap.map(b => ({ mac: b.key, run: b.run, shift: b.shift })));
1365
+ /**
1366
+ The default keymap. Includes all bindings from
1367
+ [`standardKeymap`](https://codemirror.net/6/docs/ref/#commands.standardKeymap) plus the following:
1368
+
1369
+ - Alt-ArrowLeft (Ctrl-ArrowLeft on macOS): [`cursorSyntaxLeft`](https://codemirror.net/6/docs/ref/#commands.cursorSyntaxLeft) ([`selectSyntaxLeft`](https://codemirror.net/6/docs/ref/#commands.selectSyntaxLeft) with Shift)
1370
+ - Alt-ArrowRight (Ctrl-ArrowRight on macOS): [`cursorSyntaxRight`](https://codemirror.net/6/docs/ref/#commands.cursorSyntaxRight) ([`selectSyntaxRight`](https://codemirror.net/6/docs/ref/#commands.selectSyntaxRight) with Shift)
1371
+ - Alt-ArrowUp: [`moveLineUp`](https://codemirror.net/6/docs/ref/#commands.moveLineUp)
1372
+ - Alt-ArrowDown: [`moveLineDown`](https://codemirror.net/6/docs/ref/#commands.moveLineDown)
1373
+ - Shift-Alt-ArrowUp: [`copyLineUp`](https://codemirror.net/6/docs/ref/#commands.copyLineUp)
1374
+ - Shift-Alt-ArrowDown: [`copyLineDown`](https://codemirror.net/6/docs/ref/#commands.copyLineDown)
1375
+ - Escape: [`simplifySelection`](https://codemirror.net/6/docs/ref/#commands.simplifySelection)
1376
+ - Ctrl-Enter (Cmd-Enter on macOS): [`insertBlankLine`](https://codemirror.net/6/docs/ref/#commands.insertBlankLine)
1377
+ - Alt-l (Ctrl-l on macOS): [`selectLine`](https://codemirror.net/6/docs/ref/#commands.selectLine)
1378
+ - Ctrl-i (Cmd-i on macOS): [`selectParentSyntax`](https://codemirror.net/6/docs/ref/#commands.selectParentSyntax)
1379
+ - Ctrl-[ (Cmd-[ on macOS): [`indentLess`](https://codemirror.net/6/docs/ref/#commands.indentLess)
1380
+ - Ctrl-] (Cmd-] on macOS): [`indentMore`](https://codemirror.net/6/docs/ref/#commands.indentMore)
1381
+ - Ctrl-Alt-\\ (Cmd-Alt-\\ on macOS): [`indentSelection`](https://codemirror.net/6/docs/ref/#commands.indentSelection)
1382
+ - Shift-Ctrl-k (Shift-Cmd-k on macOS): [`deleteLine`](https://codemirror.net/6/docs/ref/#commands.deleteLine)
1383
+ - Shift-Ctrl-\\ (Shift-Cmd-\\ on macOS): [`cursorMatchingBracket`](https://codemirror.net/6/docs/ref/#commands.cursorMatchingBracket)
1384
+ - Ctrl-/ (Cmd-/ on macOS): [`toggleComment`](https://codemirror.net/6/docs/ref/#commands.toggleComment).
1385
+ - Shift-Alt-a: [`toggleBlockComment`](https://codemirror.net/6/docs/ref/#commands.toggleBlockComment).
1386
+ */
1387
+ const defaultKeymap = /*@__PURE__*/[
1388
+ { key: "Alt-ArrowLeft", mac: "Ctrl-ArrowLeft", run: cursorSyntaxLeft, shift: selectSyntaxLeft },
1389
+ { key: "Alt-ArrowRight", mac: "Ctrl-ArrowRight", run: cursorSyntaxRight, shift: selectSyntaxRight },
1390
+ { key: "Alt-ArrowUp", run: moveLineUp },
1391
+ { key: "Shift-Alt-ArrowUp", run: copyLineUp },
1392
+ { key: "Alt-ArrowDown", run: moveLineDown },
1393
+ { key: "Shift-Alt-ArrowDown", run: copyLineDown },
1394
+ { key: "Escape", run: simplifySelection },
1395
+ { key: "Mod-Enter", run: insertBlankLine },
1396
+ { key: "Alt-l", mac: "Ctrl-l", run: selectLine },
1397
+ { key: "Mod-i", run: selectParentSyntax, preventDefault: true },
1398
+ { key: "Mod-[", run: indentLess },
1399
+ { key: "Mod-]", run: indentMore },
1400
+ { key: "Mod-Alt-\\", run: indentSelection },
1401
+ { key: "Shift-Mod-k", run: deleteLine },
1402
+ { key: "Shift-Mod-\\", run: cursorMatchingBracket },
1403
+ { key: "Mod-/", run: toggleComment },
1404
+ { key: "Alt-A", run: toggleBlockComment }
1405
+ ].concat(standardKeymap);
1406
+
1407
+ export { copyLineDown, copyLineUp, cursorCharLeft, cursorCharRight, cursorDocEnd, cursorDocStart, cursorGroupLeft, cursorGroupRight, cursorLineBoundaryBackward, cursorLineBoundaryForward, cursorLineBoundaryLeft, cursorLineBoundaryRight, cursorLineDown, cursorLineEnd, cursorLineStart, cursorLineUp, cursorMatchingBracket, cursorPageDown, cursorPageUp, cursorSyntaxLeft, cursorSyntaxRight, defaultKeymap, deleteCharBackward, deleteCharForward, deleteGroupBackward, deleteGroupForward, deleteLine, deleteLineBoundaryBackward, deleteLineBoundaryForward, deleteToLineEnd, emacsStyleKeymap, history, historyKeymap, indentLess, indentMore, indentSelection, insertBlankLine, insertNewlineAndIndent, invertedEffects, isolateHistory, moveLineDown, moveLineUp, redo, redoSelection, selectAll, selectCharLeft, selectCharRight, selectDocEnd, selectDocStart, selectGroupLeft, selectGroupRight, selectLine, selectLineBoundaryBackward, selectLineBoundaryForward, selectLineBoundaryLeft, selectLineBoundaryRight, selectLineDown, selectLineEnd, selectLineStart, selectLineUp, selectPageDown, selectPageUp, selectParentSyntax, selectSyntaxLeft, selectSyntaxRight, simplifySelection, splitLine, standardKeymap, toggleBlockComment, toggleBlockCommentByLine, toggleComment, toggleLineComment, transposeChars, undo, undoSelection };
1408
+ //# sourceMappingURL=index.js.map