@taufik-nurrohman/text-editor.source 3.0.1 → 3.0.3
Sign up to get free protection for your applications and to get access to all the features.
- package/index.js +87 -44
- package/index.min.js +1 -1
- package/index.mjs +63 -37
- package/package.json +1 -1
package/index.js
CHANGED
@@ -33,19 +33,19 @@
|
|
33
33
|
var isArray = function isArray(x) {
|
34
34
|
return Array.isArray(x);
|
35
35
|
};
|
36
|
-
var isDefined = function isDefined(x) {
|
36
|
+
var isDefined$1 = function isDefined(x) {
|
37
37
|
return 'undefined' !== typeof x;
|
38
38
|
};
|
39
39
|
var isFunction = function isFunction(x) {
|
40
40
|
return 'function' === typeof x;
|
41
41
|
};
|
42
|
-
var isInstance = function isInstance(x, of) {
|
43
|
-
return x && isSet(of) && x instanceof of ;
|
42
|
+
var isInstance$1 = function isInstance(x, of) {
|
43
|
+
return x && isSet$1(of) && x instanceof of ;
|
44
44
|
};
|
45
45
|
var isInteger = function isInteger(x) {
|
46
46
|
return isNumber(x) && 0 === x % 1;
|
47
47
|
};
|
48
|
-
var isNull = function isNull(x) {
|
48
|
+
var isNull$1 = function isNull(x) {
|
49
49
|
return null === x;
|
50
50
|
};
|
51
51
|
var isNumber = function isNumber(x) {
|
@@ -58,10 +58,10 @@
|
|
58
58
|
if ('object' !== typeof x) {
|
59
59
|
return false;
|
60
60
|
}
|
61
|
-
return isPlain ? isInstance(x, Object) : true;
|
61
|
+
return isPlain ? isInstance$1(x, Object) : true;
|
62
62
|
};
|
63
|
-
var isSet = function isSet(x) {
|
64
|
-
return isDefined(x) && !isNull(x);
|
63
|
+
var isSet$1 = function isSet(x) {
|
64
|
+
return isDefined$1(x) && !isNull$1(x);
|
65
65
|
};
|
66
66
|
var toCount = function toCount(x) {
|
67
67
|
return x.length;
|
@@ -77,7 +77,7 @@
|
|
77
77
|
for (var i = 0, j = toCount(lot); i < j; ++i) {
|
78
78
|
for (var k in lot[i]) {
|
79
79
|
// Assign value
|
80
|
-
if (!isSet(out[k])) {
|
80
|
+
if (!isSet$1(out[k])) {
|
81
81
|
out[k] = lot[i][k];
|
82
82
|
continue;
|
83
83
|
}
|
@@ -116,6 +116,18 @@
|
|
116
116
|
var offEventDefault = function offEventDefault(e) {
|
117
117
|
return e && e.preventDefault();
|
118
118
|
};
|
119
|
+
var isDefined = function isDefined(x) {
|
120
|
+
return 'undefined' !== typeof x;
|
121
|
+
};
|
122
|
+
var isInstance = function isInstance(x, of) {
|
123
|
+
return x && isSet(of) && x instanceof of ;
|
124
|
+
};
|
125
|
+
var isNull = function isNull(x) {
|
126
|
+
return null === x;
|
127
|
+
};
|
128
|
+
var isSet = function isSet(x) {
|
129
|
+
return isDefined(x) && !isNull(x);
|
130
|
+
};
|
119
131
|
var isPattern = function isPattern(pattern) {
|
120
132
|
return isInstance(pattern, RegExp);
|
121
133
|
};
|
@@ -131,9 +143,9 @@
|
|
131
143
|
var bounce = debounce(function ($) {
|
132
144
|
return $.record();
|
133
145
|
}, 10);
|
146
|
+
var name = 'TextEditor.Source';
|
134
147
|
|
135
148
|
function onKeyDown(e) {
|
136
|
-
var _$$state$source, _$$state$source2;
|
137
149
|
var $ = this,
|
138
150
|
key = $.k(false).pop(),
|
139
151
|
// Capture the last key
|
@@ -144,8 +156,8 @@
|
|
144
156
|
}
|
145
157
|
var charAfter,
|
146
158
|
charBefore,
|
147
|
-
charIndent =
|
148
|
-
charPairs =
|
159
|
+
charIndent = $.state.tab || '\t',
|
160
|
+
charPairs = $.state.pairs || {},
|
149
161
|
charPairsValues = toObjectValues(charPairs);
|
150
162
|
if (isInteger(charIndent)) {
|
151
163
|
charIndent = ' '.repeat(charIndent);
|
@@ -339,27 +351,27 @@
|
|
339
351
|
|
340
352
|
function attach() {
|
341
353
|
var $ = this;
|
354
|
+
var $$ = $.constructor.prototype;
|
342
355
|
$.state = fromStates({
|
343
|
-
|
344
|
-
|
345
|
-
|
346
|
-
|
347
|
-
|
348
|
-
|
349
|
-
|
350
|
-
|
351
|
-
'<': '>'
|
352
|
-
}
|
356
|
+
pairs: {
|
357
|
+
'`': '`',
|
358
|
+
'(': ')',
|
359
|
+
'{': '}',
|
360
|
+
'[': ']',
|
361
|
+
'"': '"',
|
362
|
+
"'": "'",
|
363
|
+
'<': '>'
|
353
364
|
}
|
354
365
|
}, $.state);
|
355
|
-
|
366
|
+
!isFunction($$.alert) && ($$.alert = function (hint, then) {
|
356
367
|
W.alert && W.alert(hint);
|
357
|
-
return isFunction(then) && then.call(
|
358
|
-
};
|
359
|
-
|
360
|
-
return isFunction(then) && then.call(
|
361
|
-
};
|
362
|
-
|
368
|
+
return isFunction(then) && then.call(this, true);
|
369
|
+
});
|
370
|
+
!isFunction($$.confirm) && ($$.confirm = function (hint, then) {
|
371
|
+
return isFunction(then) && then.call(this, W.confirm && W.confirm(hint));
|
372
|
+
});
|
373
|
+
!isFunction($$.insertBlock) && ($$.insertBlock = function (value, mode) {
|
374
|
+
var $ = this;
|
363
375
|
var _$$$2 = $.$(),
|
364
376
|
after = _$$$2.after,
|
365
377
|
before = _$$$2.before,
|
@@ -378,8 +390,9 @@
|
|
378
390
|
return $.select(end + lineAfterCount).insert('\n', -1).push(lineMatchIndent).insert(value, 1, false);
|
379
391
|
}
|
380
392
|
return $.select(start - lineBeforeCount, end + lineAfterCount).insert(value, mode, true).wrap(lineMatchIndent, "");
|
381
|
-
};
|
382
|
-
|
393
|
+
});
|
394
|
+
!isFunction($$.peelBlock) && ($$.peelBlock = function (open, close, wrap) {
|
395
|
+
var $ = this;
|
383
396
|
var _$$$3 = $.$(),
|
384
397
|
after = _$$$3.after,
|
385
398
|
before = _$$$3.before,
|
@@ -396,23 +409,50 @@
|
|
396
409
|
return $.select(start - lineBeforeCount + (wrap ? 0 : openCount), end + lineAfterCount - (wrap ? 0 : closeCount)).peel(open, close, wrap);
|
397
410
|
}
|
398
411
|
return $.select(start, end);
|
399
|
-
};
|
400
|
-
|
401
|
-
return isFunction(then) && then.call(
|
402
|
-
};
|
403
|
-
|
412
|
+
});
|
413
|
+
!isFunction($$.prompt) && ($$.prompt = function (hint, value, then) {
|
414
|
+
return isFunction(then) && then.call(this, W.prompt ? W.prompt(hint, value) : false);
|
415
|
+
});
|
416
|
+
!isFunction($$.selectBlock) && ($$.selectBlock = function (withSpaces) {
|
417
|
+
if (withSpaces === void 0) {
|
418
|
+
withSpaces = true;
|
419
|
+
}
|
420
|
+
var $ = this;
|
404
421
|
var _$$$4 = $.$(),
|
405
422
|
after = _$$$4.after,
|
406
423
|
before = _$$$4.before,
|
407
424
|
end = _$$$4.end,
|
408
425
|
start = _$$$4.start,
|
426
|
+
value = _$$$4.value,
|
409
427
|
lineAfter = after.split('\n').shift(),
|
410
428
|
lineAfterCount = toCount(lineAfter),
|
411
429
|
lineBefore = before.split('\n').pop(),
|
412
430
|
lineBeforeCount = toCount(lineBefore);
|
413
|
-
|
414
|
-
|
415
|
-
|
431
|
+
if (!withSpaces) {
|
432
|
+
var lineAfterSpaces = /\s+$/.exec(lineAfter),
|
433
|
+
lineBeforeSpaces = /^\s+/.exec(lineBefore);
|
434
|
+
if (lineAfterSpaces) {
|
435
|
+
lineAfterCount -= toCount(lineAfterSpaces[0]);
|
436
|
+
}
|
437
|
+
if (lineBeforeSpaces) {
|
438
|
+
lineBeforeCount -= toCount(lineBeforeSpaces[0]);
|
439
|
+
}
|
440
|
+
}
|
441
|
+
$.select(start - lineBeforeCount, end + lineAfterCount);
|
442
|
+
if (!withSpaces) {
|
443
|
+
var s = $.$(),
|
444
|
+
m;
|
445
|
+
end = s.end;
|
446
|
+
start = s.start;
|
447
|
+
value = s.value;
|
448
|
+
if (m = /^(\s+)?[\s\S]+?(\s+)?$/.exec(value)) {
|
449
|
+
return $.select(start + toCount(m[1] || ""), end - toCount(m[2] || ""));
|
450
|
+
}
|
451
|
+
}
|
452
|
+
return $;
|
453
|
+
});
|
454
|
+
!isFunction($$.toggle) && ($$.toggle = function (open, close, wrap) {
|
455
|
+
var $ = this;
|
416
456
|
var _$$$5 = $.$(),
|
417
457
|
after = _$$$5.after,
|
418
458
|
before = _$$$5.before,
|
@@ -423,8 +463,9 @@
|
|
423
463
|
return $.peel(open, close, wrap);
|
424
464
|
}
|
425
465
|
return $.wrap(open, close, wrap);
|
426
|
-
};
|
427
|
-
|
466
|
+
});
|
467
|
+
!isFunction($$.toggleBlock) && ($$.toggleBlock = function (open, close, wrap) {
|
468
|
+
var $ = this;
|
428
469
|
var _$$$6 = $.$(),
|
429
470
|
after = _$$$6.after,
|
430
471
|
before = _$$$6.before,
|
@@ -437,8 +478,9 @@
|
|
437
478
|
return $.peelBlock(open, close, wrap);
|
438
479
|
}
|
439
480
|
return $.wrapBlock(open, close, wrap);
|
440
|
-
};
|
441
|
-
|
481
|
+
});
|
482
|
+
!isFunction($$.wrapBlock) && ($$.wrapBlock = function (open, close, wrap) {
|
483
|
+
var $ = this;
|
442
484
|
var _$$$7 = $.$(),
|
443
485
|
after = _$$$7.after,
|
444
486
|
before = _$$$7.before,
|
@@ -449,7 +491,7 @@
|
|
449
491
|
lineBefore = before.split('\n').pop(),
|
450
492
|
lineBeforeCount = toCount(lineBefore);
|
451
493
|
return $.select(start - lineBeforeCount, end + lineAfterCount).wrap(open, close, wrap);
|
452
|
-
};
|
494
|
+
});
|
453
495
|
return $.on('key.down', onKeyDown).record();
|
454
496
|
}
|
455
497
|
|
@@ -458,7 +500,8 @@
|
|
458
500
|
}
|
459
501
|
var index_js = {
|
460
502
|
attach: attach,
|
461
|
-
detach: detach
|
503
|
+
detach: detach,
|
504
|
+
name: name
|
462
505
|
};
|
463
506
|
return index_js;
|
464
507
|
}));
|
package/index.min.js
CHANGED
@@ -23,4 +23,4 @@
|
|
23
23
|
* SOFTWARE.
|
24
24
|
*
|
25
25
|
*/
|
26
|
-
!function(e,r){"object"==typeof exports&&"undefined"!=typeof module?module.exports=r():"function"==typeof define&&define.amd?define(r):((e="undefined"!=typeof globalThis?globalThis:e||self).TextEditor=e.TextEditor||{},e.TextEditor.Source=r())}(this,(function(){"use strict";var e,r,t,n=function(e,r){return-1!==r.indexOf(e)},i=function(e){return Array.isArray(e)},o=function(e){return"function"==typeof e},s=function(e
|
26
|
+
!function(e,r){"object"==typeof exports&&"undefined"!=typeof module?module.exports=r():"function"==typeof define&&define.amd?define(r):((e="undefined"!=typeof globalThis?globalThis:e||self).TextEditor=e.TextEditor||{},e.TextEditor.Source=r())}(this,(function(){"use strict";var e,r,t,n=function(e,r){return-1!==r.indexOf(e)},i=function(e){return Array.isArray(e)},o=function(e){return"function"==typeof e},s=function(e){return"number"==typeof e},c=function(e,r){return void 0===r&&(r=!0),"object"==typeof e&&(!r||function(e,r){return e&&l(r)&&e instanceof r}(e,Object))},l=function(e){return function(e){return void 0!==e}(e)&&!function(e){return null===e}(e)},f=function(e){return e.length},u=function e(){for(var r=arguments.length,t=Array(r),o=0;o<r;o++)t[o]=arguments[o];for(var s=t.shift(),u=0,a=f(t);u<a;++u)for(var p in t[u])if(l(s[p]))if(i(s[p])&&i(t[u][p])){s[p]=[].concat(s[p]);for(var d=0,h=f(t[u][p]);d<h;++d)n(t[u][p][d],s[p])||s[p].push(t[u][p][d])}else c(s[p])&&c(t[u][p])?s[p]=e({},s[p],t[u][p]):s[p]=t[u][p];else s[p]=t[u][p];return s},a=window,p=function(e){return e&&e.preventDefault()},d=function(e){return function(e){return void 0!==e}(e)&&!function(e){return null===e}(e)},h=function(e){return t=RegExp,(r=e)&&d(t)&&r instanceof t;var r,t},v=function(e,r){return h(e)?e:RegExp(e,d(r)?r:"g")},w="Control-",k="Shift-",$=(e=function(e){return e.record()},r=10,function(){var n=arguments,i=this;t&&clearTimeout(t),t=setTimeout((function(){return e.apply(i,n)}),r)});function m(e){var r=this,t=r.k(!1).pop(),i=r.k();if($(r),!e.defaultPrevented&&!r.keys[i]){var o,c,l=r.state.tab||"\t",u=r.state.pairs||{},a=Object.values(u);(function(e){return s(e)&&0==e%1})(l)&&(l=" ".repeat(l));var d=r.$(),h=d.after,m=d.before,b=d.end,g=d.start,x=d.value,y=h.split("\n").shift(),B=m.split("\n").pop(),E=/^\s+/.exec(B),A=E&&E[0]||"";if(w+k+"Enter"===i)return m||h?(p(e),r.select(g-f(B)).wrap(A,"\n").insert(x).record(),!1):void 0;if(w+"Enter"===i&&(m||h))return p(e),r.select(b+f(y)).wrap("\n"+A,"").insert(x).record(),!1;if("Alt-"!=i+"-"&&w!==i+"-"){if(" "===i)return o=u[c=m.slice(-1)],!x&&o&&c&&o===h[0]?(p(e),r.wrap(" "," ")):void 0;if("Backspace"===i||"Delete"===i){if(o=u[c=m.slice(-1)],"\\"===c)return;return x?h&&m&&o&&o===h[0]&&!m.endsWith("\\"+c)?(p(e),r.record().peel(c,o).record()):void 0:(o=u[c=m.trim().slice(-1)])&&c&&(h.startsWith(" "+o)&&m.endsWith(c+" ")||h.startsWith("\n"+A+o)&&m.endsWith(c+"\n"+A))?(p(e),r.trim("","").record()):"Delete"!==i&&B.endsWith(l)?(p(e),r.pull(l).record()):h&&m&&!m.endsWith("\\"+c)&&o===h[0]&&c===m.slice(-1)?(p(e),r.peel(c,o).record()):void 0}if("Enter"!==i&&k+"Enter"!==i){if("\\"!==(c=m.slice(-1))){if(o=n(h[0],a)?h[0]:u[c],!x&&h&&m&&o&&t===o)return p(e),r.select(g+1).record();for(c in u){if(o=u[c],t===c&&o)return p(e),r.wrap(c,o).record();if(t===o){if(x)return p(e),r.record().wrap(c,o).record();break}}var T,W,j,S=[];if(x){for(T in u)(W=u[T])&&S.push("(?:\\"+T+"(?:\\\\.|[^\\"+T+(W!==T?"\\"+W:"")+"])*\\"+W+")");if(S.push("\\w+"),S.push("\\s+"),S.push("[\\s\\S]"),w+"ArrowLeft"===i)return p(e),(j=v("("+S.join("|")+")$","").exec(m))?r.insert("").select(g-f(j[0])).insert(x).record():r.select();if(w+"ArrowRight"===i)return p(e),(j=h.match(v("^("+S.join("|")+")","")))?r.insert("").select(b+f(j[0])-f(x)).insert(x).record():r.select()}if(b+=f(y),g-=f(B),x=B+x+y,w+"ArrowUp"===i){if(p(e),!n("\n",m))return r.select();r.insert(""),r.replace(/^([^\n]*?)(\n|$)/,"$2",1),r.replace(/(^|\n)([^\n]*?)$/,"",-1);var D=r.$();return m=D.before,g=D.start,B=m.split("\n").pop(),r.select(g-=f(B)).wrap(x,"\n"),r.select(g,g+f(x)),r.record()}if(w+"ArrowDown"===i){if(p(e),!n("\n",h))return r.select();r.insert(""),r.replace(/^([^\n]*?)(\n|$)/,"",1),r.replace(/(^|\n)([^\n]*?)$/,"$1",-1);var O=r.$();return h=O.after,b=O.end,y=h.split("\n").shift(),r.select(b+=f(y)).wrap("\n",x),b+=1,r.select(b,b+f(x)),r.record()}}}else if(!x){if(h&&m&&(o=u[c=m.slice(-1)])&&o===h[0])return p(e),r.wrap("\n"+A+(c!==o?l:""),"\n"+A).record();if(A)return p(e),r.insert("\n"+A,-1).record()}}else p(e)}}var b={attach:function(){var e=this,r=e.constructor.prototype;return e.state=u({pairs:{"`":"`","(":")","{":"}","[":"]",'"':'"',"'":"'","<":">"}},e.state),!o(r.alert)&&(r.alert=function(e,r){return a.alert&&a.alert(e),o(r)&&r.call(this,!0)}),!o(r.confirm)&&(r.confirm=function(e,r){return o(r)&&r.call(this,a.confirm&&a.confirm(e))}),!o(r.insertBlock)&&(r.insertBlock=function(e,r){var t=this,n=t.$(),i=n.after,o=n.before,s=n.end,c=n.start,l=i.split("\n").shift(),u=f(l),a=o.split("\n").pop(),p=f(a),d=/^\s+/.exec(a),h=d&&d[0]||"";return-1===r?t.select(c-p).insert("\n",1).push(h).insert(e,1,!1):1===r?t.select(s+u).insert("\n",-1).push(h).insert(e,1,!1):t.select(c-p,s+u).insert(e,r,!0).wrap(h,"")}),!o(r.peelBlock)&&(r.peelBlock=function(e,r,t){var n=this,i=n.$(),o=i.after,s=i.before,c=i.end,l=i.start,u=i.value,a=f(r),p=o.split("\n").shift(),d=f(p),h=s.split("\n").pop(),v=f(h),w=f(e);return t&&r===u.slice(-a)&&e===u.slice(0,w)||r===p.slice(-a)&&e===h.slice(0,w)?n.select(l-v+(t?0:w),c+d-(t?0:a)).peel(e,r,t):n.select(l,c)}),!o(r.prompt)&&(r.prompt=function(e,r,t){return o(t)&&t.call(this,!!a.prompt&&a.prompt(e,r))}),!o(r.selectBlock)&&(r.selectBlock=function(e){void 0===e&&(e=!0);var r=this,t=r.$(),n=t.after,i=t.before,o=t.end,s=t.start,c=t.value,l=n.split("\n").shift(),u=f(l),a=i.split("\n").pop(),p=f(a);if(!e){var d=/\s+$/.exec(l),h=/^\s+/.exec(a);d&&(u-=f(d[0])),h&&(p-=f(h[0]))}if(r.select(s-p,o+u),!e){var v,w=r.$();if(o=w.end,s=w.start,c=w.value,v=/^(\s+)?[\s\S]+?(\s+)?$/.exec(c))return r.select(s+f(v[1]||""),o-f(v[2]||""))}return r}),!o(r.toggle)&&(r.toggle=function(e,r,t){var n=this,i=n.$(),o=i.after,s=i.before,c=i.value,l=f(r),u=f(e);return t&&r===c.slice(-l)&&e===c.slice(0,u)||r===o.slice(0,l)&&e===s.slice(-u)?n.peel(e,r,t):n.wrap(e,r,t)}),!o(r.toggleBlock)&&(r.toggleBlock=function(e,r,t){var n=this,i=n.$(),o=i.after,s=i.before,c=i.value,l=f(r),u=o.split("\n").shift(),a=s.split("\n").pop(),p=f(e);return t&&r===c.slice(-l)&&e===c.slice(0,p)||r===u.slice(-l)&&e===a.slice(0,p)?n.peelBlock(e,r,t):n.wrapBlock(e,r,t)}),!o(r.wrapBlock)&&(r.wrapBlock=function(e,r,t){var n=this.$(),i=n.after,o=n.before,s=n.end,c=n.start,l=i.split("\n").shift(),u=f(l),a=o.split("\n").pop(),p=f(a);return this.select(c-p,s+u).wrap(e,r,t)}),e.on("key.down",m).record()},detach:function(){return this.off("key.down",m)},name:"TextEditor.Source"};return b}));
|
package/index.mjs
CHANGED
@@ -12,6 +12,7 @@ const CTRL_PREFIX = 'Control-';
|
|
12
12
|
const SHIFT_PREFIX = 'Shift-';
|
13
13
|
|
14
14
|
const bounce = debounce($ => $.record(), 10);
|
15
|
+
const name = 'TextEditor.Source';
|
15
16
|
|
16
17
|
function onKeyDown(e) {
|
17
18
|
let $ = this,
|
@@ -23,8 +24,8 @@ function onKeyDown(e) {
|
|
23
24
|
}
|
24
25
|
let charAfter,
|
25
26
|
charBefore,
|
26
|
-
charIndent = $.state.
|
27
|
-
charPairs = $.state.
|
27
|
+
charIndent = $.state.tab || '\t',
|
28
|
+
charPairs = $.state.pairs || {},
|
28
29
|
charPairsValues = toObjectValues(charPairs);
|
29
30
|
if (isInteger(charIndent)) {
|
30
31
|
charIndent = ' '.repeat(charIndent);
|
@@ -214,28 +215,28 @@ function onKeyDown(e) {
|
|
214
215
|
}
|
215
216
|
|
216
217
|
function attach() {
|
217
|
-
|
218
|
+
const $ = this;
|
219
|
+
const $$ = $.constructor.prototype;
|
218
220
|
$.state = fromStates({
|
219
|
-
|
220
|
-
|
221
|
-
|
222
|
-
|
223
|
-
|
224
|
-
|
225
|
-
|
226
|
-
|
227
|
-
'<': '>'
|
228
|
-
}
|
221
|
+
pairs: {
|
222
|
+
'`': '`',
|
223
|
+
'(': ')',
|
224
|
+
'{': '}',
|
225
|
+
'[': ']',
|
226
|
+
'"': '"',
|
227
|
+
"'": "'",
|
228
|
+
'<': '>'
|
229
229
|
}
|
230
230
|
}, $.state);
|
231
|
-
|
231
|
+
!isFunction($$.alert) && ($$.alert = function (hint, then) {
|
232
232
|
W.alert && W.alert(hint);
|
233
|
-
return isFunction(then) && then.call(
|
234
|
-
};
|
235
|
-
|
236
|
-
return isFunction(then) && then.call(
|
237
|
-
};
|
238
|
-
|
233
|
+
return isFunction(then) && then.call(this, true);
|
234
|
+
});
|
235
|
+
!isFunction($$.confirm) && ($$.confirm = function (hint, then) {
|
236
|
+
return isFunction(then) && then.call(this, W.confirm && W.confirm(hint));
|
237
|
+
});
|
238
|
+
!isFunction($$.insertBlock) && ($$.insertBlock = function (value, mode) {
|
239
|
+
let $ = this;
|
239
240
|
let {after, before, end, start} = $.$(),
|
240
241
|
lineAfter = after.split('\n').shift(),
|
241
242
|
lineAfterCount = toCount(lineAfter),
|
@@ -250,8 +251,9 @@ function attach() {
|
|
250
251
|
return $.select(end + lineAfterCount).insert('\n', -1).push(lineMatchIndent).insert(value, 1, false);
|
251
252
|
}
|
252
253
|
return $.select(start - lineBeforeCount, end + lineAfterCount).insert(value, mode, true).wrap(lineMatchIndent, "");
|
253
|
-
};
|
254
|
-
|
254
|
+
});
|
255
|
+
!isFunction($$.peelBlock) && ($$.peelBlock = function (open, close, wrap) {
|
256
|
+
let $ = this;
|
255
257
|
let {after, before, end, start, value} = $.$(),
|
256
258
|
closeCount = toCount(close),
|
257
259
|
lineAfter = after.split('\n').shift(),
|
@@ -266,19 +268,41 @@ function attach() {
|
|
266
268
|
return $.select(start - lineBeforeCount + (wrap ? 0 : openCount), end + lineAfterCount - (wrap ? 0 : closeCount)).peel(open, close, wrap);
|
267
269
|
}
|
268
270
|
return $.select(start, end);
|
269
|
-
};
|
270
|
-
|
271
|
-
return isFunction(then) && then.call(
|
272
|
-
};
|
273
|
-
|
274
|
-
let
|
271
|
+
});
|
272
|
+
!isFunction($$.prompt) && ($$.prompt = function (hint, value, then) {
|
273
|
+
return isFunction(then) && then.call(this, W.prompt ? W.prompt(hint, value) : false);
|
274
|
+
});
|
275
|
+
!isFunction($$.selectBlock) && ($$.selectBlock = function (withSpaces = true) {
|
276
|
+
let $ = this;
|
277
|
+
let {after, before, end, start, value} = $.$(),
|
275
278
|
lineAfter = after.split('\n').shift(),
|
276
279
|
lineAfterCount = toCount(lineAfter),
|
277
280
|
lineBefore = before.split('\n').pop(),
|
278
281
|
lineBeforeCount = toCount(lineBefore);
|
279
|
-
|
280
|
-
|
281
|
-
|
282
|
+
if (!withSpaces) {
|
283
|
+
let lineAfterSpaces = /\s+$/.exec(lineAfter),
|
284
|
+
lineBeforeSpaces = /^\s+/.exec(lineBefore);
|
285
|
+
if (lineAfterSpaces) {
|
286
|
+
lineAfterCount -= toCount(lineAfterSpaces[0]);
|
287
|
+
}
|
288
|
+
if (lineBeforeSpaces) {
|
289
|
+
lineBeforeCount -= toCount(lineBeforeSpaces[0]);
|
290
|
+
}
|
291
|
+
}
|
292
|
+
$.select(start - lineBeforeCount, end + lineAfterCount);
|
293
|
+
if (!withSpaces) {
|
294
|
+
let s = $.$(), m;
|
295
|
+
end = s.end;
|
296
|
+
start = s.start;
|
297
|
+
value = s.value;
|
298
|
+
if (m = /^(\s+)?[\s\S]+?(\s+)?$/.exec(value)) {
|
299
|
+
return $.select(start + toCount(m[1] || ""), end - toCount(m[2] || ""));
|
300
|
+
}
|
301
|
+
}
|
302
|
+
return $;
|
303
|
+
});
|
304
|
+
!isFunction($$.toggle) && ($$.toggle = function (open, close, wrap) {
|
305
|
+
let $ = this;
|
282
306
|
let {after, before, value} = $.$(),
|
283
307
|
closeCount = toCount(close),
|
284
308
|
openCount = toCount(open);
|
@@ -289,8 +313,9 @@ function attach() {
|
|
289
313
|
return $.peel(open, close, wrap);
|
290
314
|
}
|
291
315
|
return $.wrap(open, close, wrap);
|
292
|
-
};
|
293
|
-
|
316
|
+
});
|
317
|
+
!isFunction($$.toggleBlock) && ($$.toggleBlock = function (open, close, wrap) {
|
318
|
+
let $ = this;
|
294
319
|
let {after, before, value} = $.$(),
|
295
320
|
closeCount = toCount(close),
|
296
321
|
lineAfter = after.split('\n').shift(),
|
@@ -303,15 +328,16 @@ function attach() {
|
|
303
328
|
return $.peelBlock(open, close, wrap);
|
304
329
|
}
|
305
330
|
return $.wrapBlock(open, close, wrap);
|
306
|
-
};
|
307
|
-
|
331
|
+
});
|
332
|
+
!isFunction($$.wrapBlock) && ($$.wrapBlock = function (open, close, wrap) {
|
333
|
+
let $ = this;
|
308
334
|
let {after, before, end, start} = $.$(),
|
309
335
|
lineAfter = after.split('\n').shift(),
|
310
336
|
lineAfterCount = toCount(lineAfter),
|
311
337
|
lineBefore = before.split('\n').pop(),
|
312
338
|
lineBeforeCount = toCount(lineBefore);
|
313
339
|
return $.select(start - lineBeforeCount, end + lineAfterCount).wrap(open, close, wrap);
|
314
|
-
};
|
340
|
+
});
|
315
341
|
return $.on('key.down', onKeyDown).record();
|
316
342
|
}
|
317
343
|
|
@@ -319,4 +345,4 @@ function detach() {
|
|
319
345
|
return this.off('key.down', onKeyDown);
|
320
346
|
}
|
321
347
|
|
322
|
-
export default {attach, detach};
|
348
|
+
export default {attach, detach, name};
|
package/package.json
CHANGED