@taufik-nurrohman/text-editor.source 2.2.5 → 2.2.7
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/LICENSE +1 -1
- package/index.js +131 -113
- package/index.min.js +2 -2
- package/package.json +1 -2
package/LICENSE
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
The MIT License (MIT)
|
2
2
|
|
3
|
-
Copyright ©
|
3
|
+
Copyright © 2023 Taufik Nurrohman <https://github.com/taufik-nurrohman>
|
4
4
|
|
5
5
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
6
|
of this software and associated documentation files (the “Software”), to deal
|
package/index.js
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
*
|
3
3
|
* The MIT License (MIT)
|
4
4
|
*
|
5
|
-
* Copyright ©
|
5
|
+
* Copyright © 2023 Taufik Nurrohman <https://github.com/taufik-nurrohman>
|
6
6
|
*
|
7
7
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
8
8
|
* of this software and associated documentation files (the “Software”), to deal
|
@@ -23,9 +23,9 @@
|
|
23
23
|
* SOFTWARE.
|
24
24
|
*
|
25
25
|
*/
|
26
|
-
(function (
|
27
|
-
typeof exports === 'object' && typeof module !== 'undefined' ?
|
28
|
-
})(this, function (exports) {
|
26
|
+
(function (g, f) {
|
27
|
+
typeof exports === 'object' && typeof module !== 'undefined' ? f(exports) : typeof define === 'function' && define.amd ? define(['exports'], f) : (g = typeof globalThis !== 'undefined' ? globalThis : g || self, f((g.TE = g.TE || {}, g.TE.Source = {})));
|
28
|
+
})(this, (function (exports) {
|
29
29
|
'use strict';
|
30
30
|
var hasValue = function hasValue(x, data) {
|
31
31
|
return -1 !== data.indexOf(x);
|
@@ -36,8 +36,8 @@
|
|
36
36
|
var isDefined = function isDefined(x) {
|
37
37
|
return 'undefined' !== typeof x;
|
38
38
|
};
|
39
|
-
var isInstance = function isInstance(x, of
|
40
|
-
return x && isSet$1(
|
39
|
+
var isInstance = function isInstance(x, of) {
|
40
|
+
return x && isSet$1(of) && x instanceof of ;
|
41
41
|
};
|
42
42
|
var isNull = function isNull(x) {
|
43
43
|
return null === x;
|
@@ -72,11 +72,12 @@
|
|
72
72
|
var toPattern = function toPattern(pattern, opt) {
|
73
73
|
if (isPattern(pattern)) {
|
74
74
|
return pattern;
|
75
|
-
}
|
75
|
+
}
|
76
|
+
// No need to escape `/` in the pattern string
|
76
77
|
pattern = pattern.replace(/\//g, '\\/');
|
77
78
|
return new RegExp(pattern, isSet$1(opt) ? opt : 'g');
|
78
79
|
};
|
79
|
-
|
80
|
+
var pairs = {
|
80
81
|
'`': '`',
|
81
82
|
'(': ')',
|
82
83
|
'{': '}',
|
@@ -87,31 +88,38 @@
|
|
87
88
|
};
|
88
89
|
|
89
90
|
function promisify(type, lot) {
|
90
|
-
return new Promise((resolve, reject)
|
91
|
-
|
91
|
+
return new Promise(function (resolve, reject) {
|
92
|
+
var r = W[type].apply(W, lot);
|
92
93
|
return r ? resolve(r) : reject(r);
|
93
94
|
});
|
94
95
|
}
|
95
|
-
|
96
|
+
var defaults = {
|
96
97
|
source: {
|
97
|
-
pairs,
|
98
|
+
pairs: pairs,
|
98
99
|
type: null
|
99
100
|
}
|
100
101
|
};
|
101
|
-
['alert', 'confirm', 'prompt'].forEach(type
|
102
|
-
defaults.source[type] = (
|
102
|
+
['alert', 'confirm', 'prompt'].forEach(function (type) {
|
103
|
+
defaults.source[type] = function () {
|
104
|
+
for (var _len = arguments.length, lot = new Array(_len), _key = 0; _key < _len; _key++) {
|
105
|
+
lot[_key] = arguments[_key];
|
106
|
+
}
|
107
|
+
return promisify(type, lot);
|
108
|
+
};
|
103
109
|
});
|
104
|
-
|
105
|
-
that.toggle = function (open, close, wrap, tidy
|
110
|
+
var that = {};
|
111
|
+
that.toggle = function (open, close, wrap, tidy) {
|
112
|
+
if (tidy === void 0) {
|
113
|
+
tidy = false;
|
114
|
+
}
|
106
115
|
if (!close && "" !== close) {
|
107
116
|
close = open;
|
108
117
|
}
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
} = t.$(),
|
118
|
+
var t = this,
|
119
|
+
_t$$ = t.$(),
|
120
|
+
after = _t$$.after,
|
121
|
+
before = _t$$.before,
|
122
|
+
value = _t$$.value,
|
115
123
|
closeCount = toCount(close),
|
116
124
|
openCount = toCount(open);
|
117
125
|
if (wrap && close === value.slice(-closeCount) && open === value.slice(0, openCount) || close === after.slice(0, closeCount) && open === before.slice(-openCount)) {
|
@@ -130,47 +138,44 @@
|
|
130
138
|
}
|
131
139
|
return t.wrap(open, close, wrap);
|
132
140
|
};
|
133
|
-
|
134
|
-
|
141
|
+
var CTRL_PREFIX = 'Control-';
|
142
|
+
var SHIFT_PREFIX = 'Shift-';
|
135
143
|
|
136
144
|
function canKeyDown(map, that) {
|
137
|
-
|
145
|
+
var charAfter,
|
138
146
|
charBefore,
|
139
147
|
charIndent = that.state.source.tab || that.state.tab || '\t',
|
140
148
|
charPairs = that.state.source.pairs || {},
|
141
149
|
charPairsValues = toObjectValues(charPairs),
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
keyValue = map + ""; // Do nothing
|
150
|
+
key = map.key,
|
151
|
+
queue = map.queue,
|
152
|
+
keyValue = map + "";
|
153
|
+
// Do nothing
|
147
154
|
if (queue.Alt || queue.Control) {
|
148
155
|
return true;
|
149
156
|
}
|
150
157
|
if (' ' === keyValue) {
|
151
|
-
|
152
|
-
after,
|
153
|
-
before,
|
154
|
-
value
|
155
|
-
|
156
|
-
charAfter
|
157
|
-
if (!value && charAfter && charBefore && charAfter === after[0]) {
|
158
|
+
var _that$$ = that.$(),
|
159
|
+
_after = _that$$.after,
|
160
|
+
_before = _that$$.before,
|
161
|
+
_value = _that$$.value;
|
162
|
+
charAfter = charPairs[charBefore = _before.slice(-1)];
|
163
|
+
if (!_value && charAfter && charBefore && charAfter === _after[0]) {
|
158
164
|
that.wrap(' ', ' ');
|
159
165
|
return false;
|
160
166
|
}
|
161
167
|
return true;
|
162
168
|
}
|
163
169
|
if ('Enter' === keyValue) {
|
164
|
-
|
165
|
-
after,
|
166
|
-
before,
|
167
|
-
value
|
168
|
-
|
169
|
-
lineBefore = before.split('\n').pop(),
|
170
|
+
var _that$$2 = that.$(),
|
171
|
+
_after2 = _that$$2.after,
|
172
|
+
_before2 = _that$$2.before,
|
173
|
+
_value2 = _that$$2.value,
|
174
|
+
lineBefore = _before2.split('\n').pop(),
|
170
175
|
lineMatch = lineBefore.match(/^(\s+)/),
|
171
176
|
lineMatchIndent = lineMatch && lineMatch[1] || "";
|
172
|
-
if (!
|
173
|
-
if (
|
177
|
+
if (!_value2) {
|
178
|
+
if (_after2 && _before2 && (charAfter = charPairs[charBefore = _before2.slice(-1)]) && charAfter === _after2[0]) {
|
174
179
|
that.wrap('\n' + lineMatchIndent + (charBefore !== charAfter ? charIndent : ""), '\n' + lineMatchIndent).record();
|
175
180
|
return false;
|
176
181
|
}
|
@@ -182,40 +187,41 @@
|
|
182
187
|
return true;
|
183
188
|
}
|
184
189
|
if ('Backspace' === keyValue) {
|
185
|
-
|
186
|
-
after,
|
187
|
-
before,
|
188
|
-
value
|
189
|
-
|
190
|
-
|
191
|
-
|
192
|
-
|
193
|
-
|
194
|
-
|
190
|
+
var _that$$3 = that.$(),
|
191
|
+
_after3 = _that$$3.after,
|
192
|
+
_before3 = _that$$3.before,
|
193
|
+
_value3 = _that$$3.value;
|
194
|
+
_after3.split('\n')[0];
|
195
|
+
var _lineBefore = _before3.split('\n').pop(),
|
196
|
+
_lineMatch = _lineBefore.match(/^(\s+)/),
|
197
|
+
_lineMatchIndent = _lineMatch && _lineMatch[1] || "";
|
198
|
+
charAfter = charPairs[charBefore = _before3.slice(-1)];
|
199
|
+
// Do nothing on escape
|
195
200
|
if ('\\' === charBefore) {
|
196
201
|
return true;
|
197
202
|
}
|
198
|
-
if (
|
199
|
-
if (
|
203
|
+
if (_value3) {
|
204
|
+
if (_after3 && _before3 && charAfter && charAfter === _after3[0] && !_before3.endsWith('\\' + charBefore)) {
|
200
205
|
that.record().peel(charBefore, charAfter).record();
|
201
206
|
return false;
|
202
207
|
}
|
203
208
|
return true;
|
204
209
|
}
|
205
|
-
charAfter = charPairs[charBefore =
|
210
|
+
charAfter = charPairs[charBefore = _before3.trim().slice(-1)];
|
206
211
|
if (charAfter && charBefore) {
|
207
|
-
if (
|
212
|
+
if (_after3.startsWith(' ' + charAfter) && _before3.endsWith(charBefore + ' ') || _after3.startsWith('\n' + _lineMatchIndent + charAfter) && _before3.endsWith(charBefore + '\n' + _lineMatchIndent)) {
|
208
213
|
// Collapse bracket(s)
|
209
214
|
that.trim("", "").record();
|
210
215
|
return false;
|
211
216
|
}
|
212
|
-
}
|
213
|
-
|
217
|
+
}
|
218
|
+
// Outdent
|
219
|
+
if (_lineBefore.endsWith(charIndent)) {
|
214
220
|
that.pull(charIndent).record();
|
215
221
|
return false;
|
216
222
|
}
|
217
|
-
if (
|
218
|
-
if (charAfter ===
|
223
|
+
if (_after3 && _before3 && !_before3.endsWith('\\' + charBefore)) {
|
224
|
+
if (charAfter === _after3[0] && charBefore === _before3.slice(-1)) {
|
219
225
|
// Peel pair
|
220
226
|
that.peel(charBefore, charAfter).record();
|
221
227
|
return false;
|
@@ -223,16 +229,17 @@
|
|
223
229
|
}
|
224
230
|
return true;
|
225
231
|
}
|
226
|
-
|
227
|
-
after,
|
228
|
-
before,
|
229
|
-
start,
|
230
|
-
value
|
231
|
-
|
232
|
+
var _that$$4 = that.$(),
|
233
|
+
after = _that$$4.after,
|
234
|
+
before = _that$$4.before,
|
235
|
+
start = _that$$4.start,
|
236
|
+
value = _that$$4.value;
|
237
|
+
// Do nothing on escape
|
232
238
|
if ('\\' === (charBefore = before.slice(-1))) {
|
233
239
|
return true;
|
234
240
|
}
|
235
|
-
charAfter = hasValue(after[0], charPairsValues) ? after[0] : charPairs[charBefore];
|
241
|
+
charAfter = hasValue(after[0], charPairsValues) ? after[0] : charPairs[charBefore];
|
242
|
+
// `|}`
|
236
243
|
if (!value && after && before && charAfter && key === charAfter) {
|
237
244
|
// Move to the next character
|
238
245
|
// `}|`
|
@@ -240,13 +247,15 @@
|
|
240
247
|
return false;
|
241
248
|
}
|
242
249
|
for (charBefore in charPairs) {
|
243
|
-
charAfter = charPairs[charBefore];
|
250
|
+
charAfter = charPairs[charBefore];
|
251
|
+
// `{|`
|
244
252
|
if (key === charBefore && charAfter) {
|
245
253
|
// Wrap pair or selection
|
246
254
|
// `{|}` `{|aaa|}`
|
247
255
|
that.wrap(charBefore, charAfter).record();
|
248
256
|
return false;
|
249
|
-
}
|
257
|
+
}
|
258
|
+
// `|}`
|
250
259
|
if (key === charAfter) {
|
251
260
|
if (value) {
|
252
261
|
// Wrap selection
|
@@ -261,12 +270,16 @@
|
|
261
270
|
}
|
262
271
|
|
263
272
|
function canKeyDownDent(map, that) {
|
264
|
-
|
265
|
-
|
273
|
+
var charIndent = that.state.source.tab || that.state.tab || '\t';
|
274
|
+
map.key;
|
275
|
+
map.queue;
|
276
|
+
var keyValue = map + "";
|
277
|
+
// Indent with `⎈]`
|
266
278
|
if (CTRL_PREFIX + ']' === keyValue) {
|
267
279
|
that.push(charIndent).record();
|
268
280
|
return false;
|
269
|
-
}
|
281
|
+
}
|
282
|
+
// Outdent with `⎈[`
|
270
283
|
if (CTRL_PREFIX + '[' === keyValue) {
|
271
284
|
that.pull(charIndent).record();
|
272
285
|
return false;
|
@@ -275,18 +288,15 @@
|
|
275
288
|
}
|
276
289
|
|
277
290
|
function canKeyDownEnter(map, that) {
|
278
|
-
|
279
|
-
|
280
|
-
queue
|
281
|
-
} = map;
|
291
|
+
map.key;
|
292
|
+
var queue = map.queue;
|
282
293
|
if (queue.Control && queue.Enter) {
|
283
|
-
|
284
|
-
after,
|
285
|
-
before,
|
286
|
-
end,
|
287
|
-
start,
|
288
|
-
value
|
289
|
-
} = that.$(),
|
294
|
+
var _that$$5 = that.$(),
|
295
|
+
after = _that$$5.after,
|
296
|
+
before = _that$$5.before,
|
297
|
+
end = _that$$5.end,
|
298
|
+
start = _that$$5.start,
|
299
|
+
value = _that$$5.value,
|
290
300
|
lineAfter = after.split('\n').shift(),
|
291
301
|
lineBefore = before.split('\n').pop(),
|
292
302
|
lineMatch = lineBefore.match(/^(\s+)/),
|
@@ -295,7 +305,8 @@
|
|
295
305
|
if (queue.Shift) {
|
296
306
|
// Insert line over with `⎈⇧↵`
|
297
307
|
return that.select(start - toCount(lineBefore)).wrap(lineMatchIndent, '\n').insert(value).record(), false;
|
298
|
-
}
|
308
|
+
}
|
309
|
+
// Insert line below with `⎈↵`
|
299
310
|
return that.select(end + toCount(lineAfter)).wrap('\n' + lineMatchIndent, "").insert(value).record(), false;
|
300
311
|
}
|
301
312
|
}
|
@@ -303,10 +314,12 @@
|
|
303
314
|
}
|
304
315
|
|
305
316
|
function canKeyDownHistory(map, that) {
|
306
|
-
|
317
|
+
var keyValue = map + "";
|
318
|
+
// Redo with `⎈y`
|
307
319
|
if (CTRL_PREFIX + 'y' === keyValue) {
|
308
320
|
return that.redo(), false;
|
309
|
-
}
|
321
|
+
}
|
322
|
+
// Undo with `⎈z`
|
310
323
|
if (CTRL_PREFIX + 'z' === keyValue) {
|
311
324
|
return that.undo(), false;
|
312
325
|
}
|
@@ -314,21 +327,18 @@
|
|
314
327
|
}
|
315
328
|
|
316
329
|
function canKeyDownMove(map, that) {
|
317
|
-
|
318
|
-
|
319
|
-
|
320
|
-
} = map,
|
321
|
-
keyValue = map + "";
|
330
|
+
map.key;
|
331
|
+
var queue = map.queue,
|
332
|
+
keyValue = map + "";
|
322
333
|
if (!queue.Control) {
|
323
334
|
return true;
|
324
335
|
}
|
325
|
-
|
326
|
-
after,
|
327
|
-
before,
|
328
|
-
end,
|
329
|
-
start,
|
330
|
-
value
|
331
|
-
} = that.$(),
|
336
|
+
var _that$$6 = that.$(),
|
337
|
+
after = _that$$6.after,
|
338
|
+
before = _that$$6.before,
|
339
|
+
end = _that$$6.end,
|
340
|
+
start = _that$$6.start,
|
341
|
+
value = _that$$6.value,
|
332
342
|
charPair,
|
333
343
|
charPairValue,
|
334
344
|
charPairs = that.state.source.pairs || {},
|
@@ -359,10 +369,11 @@
|
|
359
369
|
return that.select(), false;
|
360
370
|
}
|
361
371
|
}
|
362
|
-
|
372
|
+
var lineAfter = after.split('\n').shift(),
|
363
373
|
lineBefore = before.split('\n').pop(),
|
364
374
|
lineMatch = lineBefore.match(/^(\s+)/);
|
365
|
-
lineMatch && lineMatch[1] || "";
|
375
|
+
lineMatch && lineMatch[1] || "";
|
376
|
+
// Force to select the current line if there is no selection
|
366
377
|
end += toCount(lineAfter);
|
367
378
|
start -= toCount(lineBefore);
|
368
379
|
value = lineBefore + value + lineAfter;
|
@@ -373,7 +384,7 @@
|
|
373
384
|
that.insert("");
|
374
385
|
that.replace(/^([^\n]*?)(\n|$)/, '$2', 1);
|
375
386
|
that.replace(/(^|\n)([^\n]*?)$/, "", -1);
|
376
|
-
|
387
|
+
var $ = that.$();
|
377
388
|
before = $.before;
|
378
389
|
start = $.start;
|
379
390
|
lineBefore = before.split('\n').pop();
|
@@ -388,9 +399,9 @@
|
|
388
399
|
that.insert("");
|
389
400
|
that.replace(/^([^\n]*?)(\n|$)/, "", 1);
|
390
401
|
that.replace(/(^|\n)([^\n]*?)$/, '$1', -1);
|
391
|
-
|
392
|
-
after = $.after;
|
393
|
-
end = $.end;
|
402
|
+
var _$ = that.$();
|
403
|
+
after = _$.after;
|
404
|
+
end = _$.end;
|
394
405
|
lineAfter = after.split('\n').shift();
|
395
406
|
that.select(end = end + toCount(lineAfter)).wrap('\n', value);
|
396
407
|
end += 1;
|
@@ -401,22 +412,26 @@
|
|
401
412
|
}
|
402
413
|
|
403
414
|
function canKeyDownTab(map, that) {
|
404
|
-
|
405
|
-
keyValue = map + "";
|
415
|
+
var charIndent = that.state.source.tab || that.state.tab || '\t',
|
416
|
+
keyValue = map + "";
|
417
|
+
// Indent with `⇥`
|
406
418
|
if ('Tab' === keyValue) {
|
407
419
|
return that.push(charIndent).record(), false;
|
408
|
-
}
|
420
|
+
}
|
421
|
+
// Outdent with `⇧+⇥`
|
409
422
|
if (SHIFT_PREFIX + 'Tab' === keyValue) {
|
410
423
|
return that.pull(charIndent).record(), false;
|
411
424
|
}
|
412
425
|
return true;
|
413
426
|
}
|
414
|
-
|
427
|
+
var bounce = debounce(function (that) {
|
428
|
+
return that.record();
|
429
|
+
}, 100);
|
415
430
|
|
416
431
|
function canKeyUp(map, that) {
|
417
432
|
return bounce(that), true;
|
418
433
|
}
|
419
|
-
|
434
|
+
var state = defaults;
|
420
435
|
exports.canKeyDown = canKeyDown;
|
421
436
|
exports.canKeyDownDent = canKeyDownDent;
|
422
437
|
exports.canKeyDownEnter = canKeyDownEnter;
|
@@ -426,4 +441,7 @@
|
|
426
441
|
exports.canKeyUp = canKeyUp;
|
427
442
|
exports.state = state;
|
428
443
|
exports.that = that;
|
429
|
-
|
444
|
+
Object.defineProperty(exports, '__esModule', {
|
445
|
+
value: true
|
446
|
+
});
|
447
|
+
}));
|
package/index.min.js
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
*
|
3
3
|
* The MIT License (MIT)
|
4
4
|
*
|
5
|
-
* Copyright ©
|
5
|
+
* Copyright © 2023 Taufik Nurrohman <https://github.com/taufik-nurrohman>
|
6
6
|
*
|
7
7
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
8
8
|
* of this software and associated documentation files (the “Software”), to deal
|
@@ -23,4 +23,4 @@
|
|
23
23
|
* SOFTWARE.
|
24
24
|
*
|
25
25
|
*/
|
26
|
-
!function(e,
|
26
|
+
!function(e,r){"object"==typeof exports&&"undefined"!=typeof module?r(exports):"function"==typeof define&&define.amd?define(["exports"],r):r(((e="undefined"!=typeof globalThis?globalThis:e||self).TE=e.TE||{},e.TE.Source={}))}(this,(function(e){"use strict";var r=function(e,r){return-1!==r.indexOf(e)},t=function(e){return function(e){return void 0!==e}(e)&&!function(e){return null===e}(e)},n=function(e){return e.length},i=window,o=function(e){return n=RegExp,(r=e)&&t(n)&&r instanceof n;var r,n},a=function(e,r){return o(e)?e:(e=e.replace(/\//g,"\\/"),RegExp(e,t(r)?r:"g"))};function s(e,r){return new Promise((function(t,n){var o=i[e].apply(i,r);return o?t(o):n(o)}))}var u={source:{pairs:{"`":"`","(":")","{":"}","[":"]",'"':'"',"'":"'","<":">"},type:null}};["alert","confirm","prompt"].forEach((function(e){u.source[e]=function(){for(var r=arguments.length,t=Array(r),n=0;n<r;n++)t[n]=arguments[n];return s(e,t)}}));var c={};c.toggle=function(e,r,t,i){void 0===i&&(i=!1),r||""===r||(r=e);var o=this,a=o.$(),s=a.after,u=a.before,c=a.value,f=n(r),l=n(e);return t&&r===c.slice(-f)&&e===c.slice(0,l)||r===s.slice(0,f)&&e===u.slice(-l)?o.peel(e,r,t):(!1!==i&&("string"==typeof i?i=[i,i]:function(e){return Array.isArray(e)}(i)||(i=["",""]),isSet(i[1])||(i[1]=i[0]),o.trim(i[0],i[1])),o.wrap(e,r,t))};var f="Control-";var l,p,d,v=(l=function(e){return e.record()},p=100,function(){var e=arguments,r=this;d&&clearTimeout(d),d=setTimeout((function(){return l.apply(r,e)}),p)});var h=u;e.canKeyDown=function(e,t){var n,i,o=t.state.source.tab||t.state.tab||"\t",a=t.state.source.pairs||{},s=Object.values(a),u=e.key,c=e.queue,f=e+"";if(c.Alt||c.Control)return!0;if(" "===f){var l=t.$(),p=l.after,d=l.before,v=l.value;return n=a[i=d.slice(-1)],!(!v&&n&&i&&n===p[0])||(t.wrap(" "," "),!1)}if("Enter"===f){var h=t.$(),y=h.after,w=h.before,b=h.value,m=w.split("\n").pop().match(/^(\s+)/),$=m&&m[1]||"";if(!b){if(y&&w&&(n=a[i=w.slice(-1)])&&n===y[0])return t.wrap("\n"+$+(i!==n?o:""),"\n"+$).record(),!1;if($)return t.insert("\n"+$,-1).record(),!1}return!0}if("Backspace"===f){var g=t.$(),T=g.after,E=g.before,A=g.value;T.split("\n")[0];var D=E.split("\n").pop(),K=D.match(/^(\s+)/),W=K&&K[1]||"";return n=a[i=E.slice(-1)],"\\"===i?!0:A?!(T&&E&&n&&n===T[0]&&!E.endsWith("\\"+i))||(t.record().peel(i,n).record(),!1):(n=a[i=E.trim().slice(-1)])&&i&&(T.startsWith(" "+n)&&E.endsWith(i+" ")||T.startsWith("\n"+W+n)&&E.endsWith(i+"\n"+W))?(t.trim("","").record(),!1):D.endsWith(o)?(t.pull(o).record(),!1):!(T&&E&&!E.endsWith("\\"+i)&&n===T[0]&&i===E.slice(-1))||(t.peel(i,n).record(),!1)}var k=t.$(),x=k.after,j=k.before,S=k.start,q=k.value;if("\\"===(i=j.slice(-1)))return!0;if(n=r(x[0],s)?x[0]:a[i],!q&&x&&j&&n&&u===n)return t.select(S+1).record(),!1;for(i in a){if(n=a[i],u===i&&n)return t.wrap(i,n).record(),!1;if(u===n){if(q)return t.record().wrap(i,n).record(),!1;break}}return!0},e.canKeyDownDent=function(e,r){var t=r.state.source.tab||r.state.tab||"\t";e.key,e.queue;var n=e+"";return f+"]"===n?(r.push(t).record(),!1):f+"["!==n||(r.pull(t).record(),!1)},e.canKeyDownEnter=function(e,r){e.key;var t=e.queue;if(t.Control&&t.Enter){var i=r.$(),o=i.after,a=i.before,s=i.end,u=i.start,c=i.value,f=o.split("\n").shift(),l=a.split("\n").pop(),p=l.match(/^(\s+)/),d=p&&p[1]||"";if(a||o)return t.Shift?(r.select(u-n(l)).wrap(d,"\n").insert(c).record(),!1):(r.select(s+n(f)).wrap("\n"+d,"").insert(c).record(),!1)}return!0},e.canKeyDownHistory=function(e,r){var t=e+"";return f+"y"===t?(r.redo(),!1):f+"z"!==t||(r.undo(),!1)},e.canKeyDownMove=function(e,t){e.key;var i=e+"";if(!e.queue.Control)return!0;var o,s,u,c=t.$(),l=c.after,p=c.before,d=c.end,v=c.start,h=c.value,y=t.state.source.pairs||{},w=[];if(h){for(o in y)(s=y[o])&&w.push("(?:\\"+o+"(?:\\\\.|[^\\"+o+(s!==o?"\\"+s:"")+"])*\\"+s+")");if(w.push("\\w+"),w.push("\\s+"),w.push("[\\s\\S]"),f+"ArrowLeft"===i)return(u=p.match(a("("+w.join("|")+")$","")))?(t.insert("").select(v-n(u[0])).insert(h),t.record(),!1):(t.select(),!1);if(f+"ArrowRight"===i)return(u=l.match(a("^("+w.join("|")+")","")))?(t.insert("").select(d+n(u[0])-n(h)).insert(h),t.record(),!1):(t.select(),!1)}var b=l.split("\n").shift(),m=p.split("\n").pop(),$=m.match(/^(\s+)/);if($&&$[1],d+=n(b),v-=n(m),h=m+h+b,f+"ArrowUp"===i){if(!r("\n",p))return t.select(),!1;t.insert(""),t.replace(/^([^\n]*?)(\n|$)/,"$2",1),t.replace(/(^|\n)([^\n]*?)$/,"",-1);var g=t.$();return p=g.before,v=g.start,m=p.split("\n").pop(),t.select(v-=n(m)).wrap(h,"\n"),t.select(v,v+n(h)),t.record(),!1}if(f+"ArrowDown"===i){if(!r("\n",l))return t.select(),!1;t.insert(""),t.replace(/^([^\n]*?)(\n|$)/,"",1),t.replace(/(^|\n)([^\n]*?)$/,"$1",-1);var T=t.$();return l=T.after,d=T.end,b=l.split("\n").shift(),t.select(d+=n(b)).wrap("\n",h),d+=1,t.select(d,d+n(h)),t.record(),!1}return!0},e.canKeyDownTab=function(e,r){var t=r.state.source.tab||r.state.tab||"\t",n=e+"";return"Tab"===n?(r.push(t).record(),!1):"Shift-Tab"!==n||(r.pull(t).record(),!1)},e.canKeyUp=function(e,r){return v(r),!0},e.state=h,e.that=c,Object.defineProperty(e,"__esModule",{value:!0})}));
|