@taufik-nurrohman/text-editor.source 2.2.9 → 2.2.10
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.
- package/index.js +84 -84
- package/index.mjs +60 -60
- package/package.json +1 -1
package/index.js
CHANGED
@@ -141,11 +141,11 @@
|
|
141
141
|
var CTRL_PREFIX = 'Control-';
|
142
142
|
var SHIFT_PREFIX = 'Shift-';
|
143
143
|
|
144
|
-
function canKeyDown(map,
|
144
|
+
function canKeyDown(map, of) {
|
145
145
|
var charAfter,
|
146
146
|
charBefore,
|
147
|
-
charIndent =
|
148
|
-
charPairs =
|
147
|
+
charIndent = of.state.source.tab || of.state.tab || '\t',
|
148
|
+
charPairs = of.state.source.pairs || {},
|
149
149
|
charPairsValues = toObjectValues(charPairs),
|
150
150
|
key = map.key,
|
151
151
|
queue = map.queue,
|
@@ -155,42 +155,42 @@
|
|
155
155
|
return true;
|
156
156
|
}
|
157
157
|
if (' ' === keyValue) {
|
158
|
-
var
|
159
|
-
_after =
|
160
|
-
_before =
|
161
|
-
_value =
|
158
|
+
var _of$$ = of.$(),
|
159
|
+
_after = _of$$.after,
|
160
|
+
_before = _of$$.before,
|
161
|
+
_value = _of$$.value;
|
162
162
|
charAfter = charPairs[charBefore = _before.slice(-1)];
|
163
163
|
if (!_value && charAfter && charBefore && charAfter === _after[0]) {
|
164
|
-
|
164
|
+
of.wrap(' ', ' ');
|
165
165
|
return false;
|
166
166
|
}
|
167
167
|
return true;
|
168
168
|
}
|
169
169
|
if ('Enter' === keyValue) {
|
170
|
-
var
|
171
|
-
_after2 =
|
172
|
-
_before2 =
|
173
|
-
_value2 =
|
170
|
+
var _of$$2 = of.$(),
|
171
|
+
_after2 = _of$$2.after,
|
172
|
+
_before2 = _of$$2.before,
|
173
|
+
_value2 = _of$$2.value,
|
174
174
|
lineBefore = _before2.split('\n').pop(),
|
175
175
|
lineMatch = lineBefore.match(/^(\s+)/),
|
176
176
|
lineMatchIndent = lineMatch && lineMatch[1] || "";
|
177
177
|
if (!_value2) {
|
178
178
|
if (_after2 && _before2 && (charAfter = charPairs[charBefore = _before2.slice(-1)]) && charAfter === _after2[0]) {
|
179
|
-
|
179
|
+
of.wrap('\n' + lineMatchIndent + (charBefore !== charAfter ? charIndent : ""), '\n' + lineMatchIndent).record();
|
180
180
|
return false;
|
181
181
|
}
|
182
182
|
if (lineMatchIndent) {
|
183
|
-
|
183
|
+
of.insert('\n' + lineMatchIndent, -1).record();
|
184
184
|
return false;
|
185
185
|
}
|
186
186
|
}
|
187
187
|
return true;
|
188
188
|
}
|
189
189
|
if ('Backspace' === keyValue) {
|
190
|
-
var
|
191
|
-
_after3 =
|
192
|
-
_before3 =
|
193
|
-
_value3 =
|
190
|
+
var _of$$3 = of.$(),
|
191
|
+
_after3 = _of$$3.after,
|
192
|
+
_before3 = _of$$3.before,
|
193
|
+
_value3 = _of$$3.value;
|
194
194
|
_after3.split('\n')[0];
|
195
195
|
var _lineBefore = _before3.split('\n').pop(),
|
196
196
|
_lineMatch = _lineBefore.match(/^(\s+)/),
|
@@ -202,7 +202,7 @@
|
|
202
202
|
}
|
203
203
|
if (_value3) {
|
204
204
|
if (_after3 && _before3 && charAfter && charAfter === _after3[0] && !_before3.endsWith('\\' + charBefore)) {
|
205
|
-
|
205
|
+
of.record().peel(charBefore, charAfter).record();
|
206
206
|
return false;
|
207
207
|
}
|
208
208
|
return true;
|
@@ -211,29 +211,29 @@
|
|
211
211
|
if (charAfter && charBefore) {
|
212
212
|
if (_after3.startsWith(' ' + charAfter) && _before3.endsWith(charBefore + ' ') || _after3.startsWith('\n' + _lineMatchIndent + charAfter) && _before3.endsWith(charBefore + '\n' + _lineMatchIndent)) {
|
213
213
|
// Collapse bracket(s)
|
214
|
-
|
214
|
+
of.trim("", "").record();
|
215
215
|
return false;
|
216
216
|
}
|
217
217
|
}
|
218
218
|
// Outdent
|
219
219
|
if (_lineBefore.endsWith(charIndent)) {
|
220
|
-
|
220
|
+
of.pull(charIndent).record();
|
221
221
|
return false;
|
222
222
|
}
|
223
223
|
if (_after3 && _before3 && !_before3.endsWith('\\' + charBefore)) {
|
224
224
|
if (charAfter === _after3[0] && charBefore === _before3.slice(-1)) {
|
225
225
|
// Peel pair
|
226
|
-
|
226
|
+
of.peel(charBefore, charAfter).record();
|
227
227
|
return false;
|
228
228
|
}
|
229
229
|
}
|
230
230
|
return true;
|
231
231
|
}
|
232
|
-
var
|
233
|
-
after =
|
234
|
-
before =
|
235
|
-
start =
|
236
|
-
value =
|
232
|
+
var _of$$4 = of.$(),
|
233
|
+
after = _of$$4.after,
|
234
|
+
before = _of$$4.before,
|
235
|
+
start = _of$$4.start,
|
236
|
+
value = _of$$4.value;
|
237
237
|
// Do nothing on escape
|
238
238
|
if ('\\' === (charBefore = before.slice(-1))) {
|
239
239
|
return true;
|
@@ -243,7 +243,7 @@
|
|
243
243
|
if (!value && after && before && charAfter && key === charAfter) {
|
244
244
|
// Move to the next character
|
245
245
|
// `}|`
|
246
|
-
|
246
|
+
of.select(start + 1).record();
|
247
247
|
return false;
|
248
248
|
}
|
249
249
|
for (charBefore in charPairs) {
|
@@ -252,7 +252,7 @@
|
|
252
252
|
if (key === charBefore && charAfter) {
|
253
253
|
// Wrap pair or selection
|
254
254
|
// `{|}` `{|aaa|}`
|
255
|
-
|
255
|
+
of.wrap(charBefore, charAfter).record();
|
256
256
|
return false;
|
257
257
|
}
|
258
258
|
// `|}`
|
@@ -260,7 +260,7 @@
|
|
260
260
|
if (value) {
|
261
261
|
// Wrap selection
|
262
262
|
// `{|aaa|}`
|
263
|
-
|
263
|
+
of.record().wrap(charBefore, charAfter).record();
|
264
264
|
return false;
|
265
265
|
}
|
266
266
|
break;
|
@@ -269,34 +269,34 @@
|
|
269
269
|
return true;
|
270
270
|
}
|
271
271
|
|
272
|
-
function canKeyDownDent(map,
|
273
|
-
var charIndent =
|
272
|
+
function canKeyDownDent(map, of) {
|
273
|
+
var charIndent = of.state.source.tab || of.state.tab || '\t';
|
274
274
|
map.key;
|
275
275
|
map.queue;
|
276
276
|
var keyValue = map + "";
|
277
277
|
// Indent with `⎈]`
|
278
278
|
if (CTRL_PREFIX + ']' === keyValue) {
|
279
|
-
|
279
|
+
of.push(charIndent).record();
|
280
280
|
return false;
|
281
281
|
}
|
282
282
|
// Outdent with `⎈[`
|
283
283
|
if (CTRL_PREFIX + '[' === keyValue) {
|
284
|
-
|
284
|
+
of.pull(charIndent).record();
|
285
285
|
return false;
|
286
286
|
}
|
287
287
|
return true;
|
288
288
|
}
|
289
289
|
|
290
|
-
function canKeyDownEnter(map,
|
290
|
+
function canKeyDownEnter(map, of) {
|
291
291
|
map.key;
|
292
292
|
var queue = map.queue;
|
293
293
|
if (queue.Control && queue.Enter) {
|
294
|
-
var
|
295
|
-
after =
|
296
|
-
before =
|
297
|
-
end =
|
298
|
-
start =
|
299
|
-
value =
|
294
|
+
var _of$$5 = of.$(),
|
295
|
+
after = _of$$5.after,
|
296
|
+
before = _of$$5.before,
|
297
|
+
end = _of$$5.end,
|
298
|
+
start = _of$$5.start,
|
299
|
+
value = _of$$5.value,
|
300
300
|
lineAfter = after.split('\n').shift(),
|
301
301
|
lineBefore = before.split('\n').pop(),
|
302
302
|
lineMatch = lineBefore.match(/^(\s+)/),
|
@@ -304,44 +304,44 @@
|
|
304
304
|
if (before || after) {
|
305
305
|
if (queue.Shift) {
|
306
306
|
// Insert line over with `⎈⇧↵`
|
307
|
-
return
|
307
|
+
return of.select(start - toCount(lineBefore)).wrap(lineMatchIndent, '\n').insert(value).record(), false;
|
308
308
|
}
|
309
309
|
// Insert line below with `⎈↵`
|
310
|
-
return
|
310
|
+
return of.select(end + toCount(lineAfter)).wrap('\n' + lineMatchIndent, "").insert(value).record(), false;
|
311
311
|
}
|
312
312
|
}
|
313
313
|
return true;
|
314
314
|
}
|
315
315
|
|
316
|
-
function canKeyDownHistory(map,
|
316
|
+
function canKeyDownHistory(map, of) {
|
317
317
|
var keyValue = map + "";
|
318
318
|
// Redo with `⎈y`
|
319
319
|
if (CTRL_PREFIX + 'y' === keyValue) {
|
320
|
-
return
|
320
|
+
return of.redo(), false;
|
321
321
|
}
|
322
322
|
// Undo with `⎈z`
|
323
323
|
if (CTRL_PREFIX + 'z' === keyValue) {
|
324
|
-
return
|
324
|
+
return of.undo(), false;
|
325
325
|
}
|
326
326
|
return true;
|
327
327
|
}
|
328
328
|
|
329
|
-
function canKeyDownMove(map,
|
329
|
+
function canKeyDownMove(map, of) {
|
330
330
|
map.key;
|
331
331
|
var queue = map.queue,
|
332
332
|
keyValue = map + "";
|
333
333
|
if (!queue.Control) {
|
334
334
|
return true;
|
335
335
|
}
|
336
|
-
var
|
337
|
-
after =
|
338
|
-
before =
|
339
|
-
end =
|
340
|
-
start =
|
341
|
-
value =
|
336
|
+
var _of$$6 = of.$(),
|
337
|
+
after = _of$$6.after,
|
338
|
+
before = _of$$6.before,
|
339
|
+
end = _of$$6.end,
|
340
|
+
start = _of$$6.start,
|
341
|
+
value = _of$$6.value,
|
342
342
|
charPair,
|
343
343
|
charPairValue,
|
344
|
-
charPairs =
|
344
|
+
charPairs = of.state.source.pairs || {},
|
345
345
|
boundaries = [],
|
346
346
|
m;
|
347
347
|
if (value) {
|
@@ -356,17 +356,17 @@
|
|
356
356
|
boundaries.push('[\\s\\S]'); // Last try!
|
357
357
|
if (CTRL_PREFIX + 'ArrowLeft' === keyValue) {
|
358
358
|
if (m = before.match(toPattern('(' + boundaries.join('|') + ')$', ""))) {
|
359
|
-
|
360
|
-
return
|
359
|
+
of.insert("").select(start - toCount(m[0])).insert(value);
|
360
|
+
return of.record(), false;
|
361
361
|
}
|
362
|
-
return
|
362
|
+
return of.select(), false;
|
363
363
|
}
|
364
364
|
if (CTRL_PREFIX + 'ArrowRight' === keyValue) {
|
365
365
|
if (m = after.match(toPattern('^(' + boundaries.join('|') + ')', ""))) {
|
366
|
-
|
367
|
-
return
|
366
|
+
of.insert("").select(end + toCount(m[0]) - toCount(value)).insert(value);
|
367
|
+
return of.record(), false;
|
368
368
|
}
|
369
|
-
return
|
369
|
+
return of.select(), false;
|
370
370
|
}
|
371
371
|
}
|
372
372
|
var lineAfter = after.split('\n').shift(),
|
@@ -379,57 +379,57 @@
|
|
379
379
|
value = lineBefore + value + lineAfter;
|
380
380
|
if (CTRL_PREFIX + 'ArrowUp' === keyValue) {
|
381
381
|
if (!hasValue('\n', before)) {
|
382
|
-
return
|
382
|
+
return of.select(), false;
|
383
383
|
}
|
384
|
-
|
385
|
-
|
386
|
-
|
387
|
-
var $ =
|
384
|
+
of.insert("");
|
385
|
+
of.replace(/^([^\n]*?)(\n|$)/, '$2', 1);
|
386
|
+
of.replace(/(^|\n)([^\n]*?)$/, "", -1);
|
387
|
+
var $ = of.$();
|
388
388
|
before = $.before;
|
389
389
|
start = $.start;
|
390
390
|
lineBefore = before.split('\n').pop();
|
391
|
-
|
392
|
-
|
393
|
-
return
|
391
|
+
of.select(start = start - toCount(lineBefore)).wrap(value, '\n');
|
392
|
+
of.select(start, start + toCount(value));
|
393
|
+
return of.record(), false;
|
394
394
|
}
|
395
395
|
if (CTRL_PREFIX + 'ArrowDown' === keyValue) {
|
396
396
|
if (!hasValue('\n', after)) {
|
397
|
-
return
|
397
|
+
return of.select(), false;
|
398
398
|
}
|
399
|
-
|
400
|
-
|
401
|
-
|
402
|
-
var _$ =
|
399
|
+
of.insert("");
|
400
|
+
of.replace(/^([^\n]*?)(\n|$)/, "", 1);
|
401
|
+
of.replace(/(^|\n)([^\n]*?)$/, '$1', -1);
|
402
|
+
var _$ = of.$();
|
403
403
|
after = _$.after;
|
404
404
|
end = _$.end;
|
405
405
|
lineAfter = after.split('\n').shift();
|
406
|
-
|
406
|
+
of.select(end = end + toCount(lineAfter)).wrap('\n', value);
|
407
407
|
end += 1;
|
408
|
-
|
409
|
-
return
|
408
|
+
of.select(end, end + toCount(value));
|
409
|
+
return of.record(), false;
|
410
410
|
}
|
411
411
|
return true;
|
412
412
|
}
|
413
413
|
|
414
|
-
function canKeyDownTab(map,
|
415
|
-
var charIndent =
|
414
|
+
function canKeyDownTab(map, of) {
|
415
|
+
var charIndent = of.state.source.tab || of.state.tab || '\t',
|
416
416
|
keyValue = map + "";
|
417
417
|
// Indent with `⇥`
|
418
418
|
if ('Tab' === keyValue) {
|
419
|
-
return
|
419
|
+
return of.push(charIndent).record(), false;
|
420
420
|
}
|
421
421
|
// Outdent with `⇧+⇥`
|
422
422
|
if (SHIFT_PREFIX + 'Tab' === keyValue) {
|
423
|
-
return
|
423
|
+
return of.pull(charIndent).record(), false;
|
424
424
|
}
|
425
425
|
return true;
|
426
426
|
}
|
427
|
-
var bounce = debounce(function (
|
428
|
-
return
|
427
|
+
var bounce = debounce(function (of) {
|
428
|
+
return of.record();
|
429
429
|
}, 100);
|
430
430
|
|
431
|
-
function canKeyUp(map,
|
432
|
-
return bounce(
|
431
|
+
function canKeyUp(map, of) {
|
432
|
+
return bounce(of), true;
|
433
433
|
}
|
434
434
|
var state = defaults;
|
435
435
|
exports.canKeyDown = canKeyDown;
|
package/index.mjs
CHANGED
@@ -67,11 +67,11 @@ const ALT_PREFIX = 'Alt-';
|
|
67
67
|
const CTRL_PREFIX = 'Control-';
|
68
68
|
const SHIFT_PREFIX = 'Shift-';
|
69
69
|
|
70
|
-
export function canKeyDown(map,
|
70
|
+
export function canKeyDown(map, of) {
|
71
71
|
let charAfter,
|
72
72
|
charBefore,
|
73
|
-
charIndent =
|
74
|
-
charPairs =
|
73
|
+
charIndent = of.state.source.tab || of.state.tab || '\t',
|
74
|
+
charPairs = of.state.source.pairs || {},
|
75
75
|
charPairsValues = toObjectValues(charPairs),
|
76
76
|
{key, queue} = map,
|
77
77
|
keyValue = map + "";
|
@@ -80,33 +80,33 @@ export function canKeyDown(map, that) {
|
|
80
80
|
return true;
|
81
81
|
}
|
82
82
|
if (' ' === keyValue) {
|
83
|
-
let {after, before, value} =
|
83
|
+
let {after, before, value} = of.$();
|
84
84
|
charAfter = charPairs[charBefore = before.slice(-1)];
|
85
85
|
if (!value && charAfter && charBefore && charAfter === after[0]) {
|
86
|
-
|
86
|
+
of.wrap(' ', ' ');
|
87
87
|
return false;
|
88
88
|
}
|
89
89
|
return true;
|
90
90
|
}
|
91
91
|
if ('Enter' === keyValue) {
|
92
|
-
let {after, before, value} =
|
92
|
+
let {after, before, value} = of.$(),
|
93
93
|
lineBefore = before.split('\n').pop(),
|
94
94
|
lineMatch = lineBefore.match(/^(\s+)/),
|
95
95
|
lineMatchIndent = lineMatch && lineMatch[1] || "";
|
96
96
|
if (!value) {
|
97
97
|
if (after && before && (charAfter = charPairs[charBefore = before.slice(-1)]) && charAfter === after[0]) {
|
98
|
-
|
98
|
+
of.wrap('\n' + lineMatchIndent + (charBefore !== charAfter ? charIndent : ""), '\n' + lineMatchIndent).record();
|
99
99
|
return false;
|
100
100
|
}
|
101
101
|
if (lineMatchIndent) {
|
102
|
-
|
102
|
+
of.insert('\n' + lineMatchIndent, -1).record();
|
103
103
|
return false;
|
104
104
|
}
|
105
105
|
}
|
106
106
|
return true;
|
107
107
|
}
|
108
108
|
if ('Backspace' === keyValue) {
|
109
|
-
let {after, before, value} =
|
109
|
+
let {after, before, value} = of.$(),
|
110
110
|
lineAfter = after.split('\n')[0],
|
111
111
|
lineBefore = before.split('\n').pop(),
|
112
112
|
lineMatch = lineBefore.match(/^(\s+)/),
|
@@ -118,7 +118,7 @@ export function canKeyDown(map, that) {
|
|
118
118
|
}
|
119
119
|
if (value) {
|
120
120
|
if (after && before && charAfter && charAfter === after[0] && !before.endsWith('\\' + charBefore)) {
|
121
|
-
|
121
|
+
of.record().peel(charBefore, charAfter).record();
|
122
122
|
return false;
|
123
123
|
}
|
124
124
|
return true;
|
@@ -130,25 +130,25 @@ export function canKeyDown(map, that) {
|
|
130
130
|
after.startsWith('\n' + lineMatchIndent + charAfter) && before.endsWith(charBefore + '\n' + lineMatchIndent)
|
131
131
|
) {
|
132
132
|
// Collapse bracket(s)
|
133
|
-
|
133
|
+
of.trim("", "").record();
|
134
134
|
return false;
|
135
135
|
}
|
136
136
|
}
|
137
137
|
// Outdent
|
138
138
|
if (lineBefore.endsWith(charIndent)) {
|
139
|
-
|
139
|
+
of.pull(charIndent).record();
|
140
140
|
return false;
|
141
141
|
}
|
142
142
|
if (after && before && !before.endsWith('\\' + charBefore)) {
|
143
143
|
if (charAfter === after[0] && charBefore === before.slice(-1)) {
|
144
144
|
// Peel pair
|
145
|
-
|
145
|
+
of.peel(charBefore, charAfter).record();
|
146
146
|
return false;
|
147
147
|
}
|
148
148
|
}
|
149
149
|
return true;
|
150
150
|
}
|
151
|
-
let {after, before, start, value} =
|
151
|
+
let {after, before, start, value} = of.$();
|
152
152
|
// Do nothing on escape
|
153
153
|
if ('\\' === (charBefore = before.slice(-1))) {
|
154
154
|
return true;
|
@@ -158,7 +158,7 @@ export function canKeyDown(map, that) {
|
|
158
158
|
if (!value && after && before && charAfter && key === charAfter) {
|
159
159
|
// Move to the next character
|
160
160
|
// `}|`
|
161
|
-
|
161
|
+
of.select(start + 1).record();
|
162
162
|
return false;
|
163
163
|
}
|
164
164
|
for (charBefore in charPairs) {
|
@@ -167,7 +167,7 @@ export function canKeyDown(map, that) {
|
|
167
167
|
if (key === charBefore && charAfter) {
|
168
168
|
// Wrap pair or selection
|
169
169
|
// `{|}` `{|aaa|}`
|
170
|
-
|
170
|
+
of.wrap(charBefore, charAfter).record();
|
171
171
|
return false;
|
172
172
|
}
|
173
173
|
// `|}`
|
@@ -175,7 +175,7 @@ export function canKeyDown(map, that) {
|
|
175
175
|
if (value) {
|
176
176
|
// Wrap selection
|
177
177
|
// `{|aaa|}`
|
178
|
-
|
178
|
+
of.record().wrap(charBefore, charAfter).record();
|
179
179
|
return false;
|
180
180
|
}
|
181
181
|
break;
|
@@ -184,27 +184,27 @@ export function canKeyDown(map, that) {
|
|
184
184
|
return true;
|
185
185
|
}
|
186
186
|
|
187
|
-
export function canKeyDownDent(map,
|
188
|
-
let charIndent =
|
187
|
+
export function canKeyDownDent(map, of) {
|
188
|
+
let charIndent = of.state.source.tab || of.state.tab || '\t',
|
189
189
|
{key, queue} = map,
|
190
190
|
keyValue = map + "";
|
191
191
|
// Indent with `⎈]`
|
192
192
|
if (CTRL_PREFIX + ']' === keyValue) {
|
193
|
-
|
193
|
+
of.push(charIndent).record();
|
194
194
|
return false;
|
195
195
|
}
|
196
196
|
// Outdent with `⎈[`
|
197
197
|
if (CTRL_PREFIX + '[' === keyValue) {
|
198
|
-
|
198
|
+
of.pull(charIndent).record();
|
199
199
|
return false;
|
200
200
|
}
|
201
201
|
return true;
|
202
202
|
}
|
203
203
|
|
204
|
-
export function canKeyDownEnter(map,
|
204
|
+
export function canKeyDownEnter(map, of) {
|
205
205
|
let {key, queue} = map;
|
206
206
|
if (queue.Control && queue.Enter) {
|
207
|
-
let {after, before, end, start, value} =
|
207
|
+
let {after, before, end, start, value} = of.$(),
|
208
208
|
lineAfter = after.split('\n').shift(),
|
209
209
|
lineBefore = before.split('\n').pop(),
|
210
210
|
lineMatch = lineBefore.match(/^(\s+)/),
|
@@ -212,37 +212,37 @@ export function canKeyDownEnter(map, that) {
|
|
212
212
|
if (before || after) {
|
213
213
|
if (queue.Shift) {
|
214
214
|
// Insert line over with `⎈⇧↵`
|
215
|
-
return
|
215
|
+
return of.select(start - toCount(lineBefore)).wrap(lineMatchIndent, '\n').insert(value).record(), false;
|
216
216
|
}
|
217
217
|
// Insert line below with `⎈↵`
|
218
|
-
return
|
218
|
+
return of.select(end + toCount(lineAfter)).wrap('\n' + lineMatchIndent, "").insert(value).record(), false;
|
219
219
|
}
|
220
220
|
}
|
221
221
|
return true;
|
222
222
|
}
|
223
223
|
|
224
|
-
export function canKeyDownHistory(map,
|
224
|
+
export function canKeyDownHistory(map, of) {
|
225
225
|
let keyValue = map + "";
|
226
226
|
// Redo with `⎈y`
|
227
227
|
if (CTRL_PREFIX + 'y' === keyValue) {
|
228
|
-
return
|
228
|
+
return of.redo(), false;
|
229
229
|
}
|
230
230
|
// Undo with `⎈z`
|
231
231
|
if (CTRL_PREFIX + 'z' === keyValue) {
|
232
|
-
return
|
232
|
+
return of.undo(), false;
|
233
233
|
}
|
234
234
|
return true;
|
235
235
|
}
|
236
236
|
|
237
|
-
export function canKeyDownMove(map,
|
237
|
+
export function canKeyDownMove(map, of) {
|
238
238
|
let {key, queue} = map,
|
239
239
|
keyValue = map + "";
|
240
240
|
if (!queue.Control) {
|
241
241
|
return true;
|
242
242
|
}
|
243
|
-
let {after, before, end, start, value} =
|
243
|
+
let {after, before, end, start, value} = of.$(),
|
244
244
|
charPair, charPairValue,
|
245
|
-
charPairs =
|
245
|
+
charPairs = of.state.source.pairs || {},
|
246
246
|
boundaries = [], m;
|
247
247
|
if (value) {
|
248
248
|
for (charPair in charPairs) {
|
@@ -256,17 +256,17 @@ export function canKeyDownMove(map, that) {
|
|
256
256
|
boundaries.push('[\\s\\S]'); // Last try!
|
257
257
|
if (CTRL_PREFIX + 'ArrowLeft' === keyValue) {
|
258
258
|
if (m = before.match(toPattern('(' + boundaries.join('|') + ')$', ""))) {
|
259
|
-
|
260
|
-
return
|
259
|
+
of.insert("").select(start - toCount(m[0])).insert(value);
|
260
|
+
return of.record(), false;
|
261
261
|
}
|
262
|
-
return
|
262
|
+
return of.select(), false;
|
263
263
|
}
|
264
264
|
if (CTRL_PREFIX + 'ArrowRight' === keyValue) {
|
265
265
|
if (m = after.match(toPattern('^(' + boundaries.join('|') + ')', ""))) {
|
266
|
-
|
267
|
-
return
|
266
|
+
of.insert("").select(end + toCount(m[0]) - toCount(value)).insert(value);
|
267
|
+
return of.record(), false;
|
268
268
|
}
|
269
|
-
return
|
269
|
+
return of.select(), false;
|
270
270
|
}
|
271
271
|
}
|
272
272
|
let lineAfter = after.split('\n').shift(),
|
@@ -279,56 +279,56 @@ export function canKeyDownMove(map, that) {
|
|
279
279
|
value = lineBefore + value + lineAfter;
|
280
280
|
if (CTRL_PREFIX + 'ArrowUp' === keyValue) {
|
281
281
|
if (!hasValue('\n', before)) {
|
282
|
-
return
|
282
|
+
return of.select(), false;
|
283
283
|
}
|
284
|
-
|
285
|
-
|
286
|
-
|
287
|
-
let $ =
|
284
|
+
of.insert("");
|
285
|
+
of.replace(/^([^\n]*?)(\n|$)/, '$2', 1);
|
286
|
+
of.replace(/(^|\n)([^\n]*?)$/, "", -1);
|
287
|
+
let $ = of.$();
|
288
288
|
before = $.before;
|
289
289
|
start = $.start;
|
290
290
|
lineBefore = before.split('\n').pop();
|
291
|
-
|
292
|
-
|
293
|
-
return
|
291
|
+
of.select(start = start - toCount(lineBefore)).wrap(value, '\n');
|
292
|
+
of.select(start, start + toCount(value));
|
293
|
+
return of.record(), false;
|
294
294
|
}
|
295
295
|
if (CTRL_PREFIX + 'ArrowDown' === keyValue) {
|
296
296
|
if (!hasValue('\n', after)) {
|
297
|
-
return
|
297
|
+
return of.select(), false;
|
298
298
|
}
|
299
|
-
|
300
|
-
|
301
|
-
|
302
|
-
let $ =
|
299
|
+
of.insert("");
|
300
|
+
of.replace(/^([^\n]*?)(\n|$)/, "", 1);
|
301
|
+
of.replace(/(^|\n)([^\n]*?)$/, '$1', -1);
|
302
|
+
let $ = of.$();
|
303
303
|
after = $.after;
|
304
304
|
end = $.end;
|
305
305
|
lineAfter = after.split('\n').shift();
|
306
|
-
|
306
|
+
of.select(end = end + toCount(lineAfter)).wrap('\n', value);
|
307
307
|
end += 1;
|
308
|
-
|
309
|
-
return
|
308
|
+
of.select(end, end + toCount(value));
|
309
|
+
return of.record(), false;
|
310
310
|
}
|
311
311
|
return true;
|
312
312
|
}
|
313
313
|
|
314
|
-
export function canKeyDownTab(map,
|
315
|
-
let charIndent =
|
314
|
+
export function canKeyDownTab(map, of) {
|
315
|
+
let charIndent = of.state.source.tab || of.state.tab || '\t',
|
316
316
|
keyValue = map + "";
|
317
317
|
// Indent with `⇥`
|
318
318
|
if ('Tab' === keyValue) {
|
319
|
-
return
|
319
|
+
return of.push(charIndent).record(), false;
|
320
320
|
}
|
321
321
|
// Outdent with `⇧+⇥`
|
322
322
|
if (SHIFT_PREFIX + 'Tab' === keyValue) {
|
323
|
-
return
|
323
|
+
return of.pull(charIndent).record(), false;
|
324
324
|
}
|
325
325
|
return true;
|
326
326
|
}
|
327
327
|
|
328
|
-
let bounce = debounce(
|
328
|
+
let bounce = debounce(of => of.record(), 100);
|
329
329
|
|
330
|
-
export function canKeyUp(map,
|
331
|
-
return bounce(
|
330
|
+
export function canKeyUp(map, of) {
|
331
|
+
return bounce(of), true;
|
332
332
|
}
|
333
333
|
|
334
334
|
export const state = defaults;
|
package/package.json
CHANGED