@uiw/react-codemirror 4.11.5 → 4.12.1
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/README.md +57 -3
- package/cjs/index.d.ts +8 -1
- package/cjs/index.js +4 -2
- package/cjs/index.js.map +3 -2
- package/cjs/useCodeMirror.js +6 -9
- package/cjs/useCodeMirror.js.map +8 -5
- package/dist/mdeditor.js +118 -67
- package/dist/mdeditor.min.js +1 -1
- package/esm/index.d.ts +8 -1
- package/esm/index.js +5 -3
- package/esm/index.js.map +3 -2
- package/esm/useCodeMirror.js +7 -6
- package/esm/useCodeMirror.js.map +8 -5
- package/package.json +4 -2
- package/src/index.tsx +10 -1
- package/src/useCodeMirror.ts +8 -5
package/dist/mdeditor.js
CHANGED
|
@@ -612,6 +612,10 @@ class dist_Tree {
|
|
|
612
612
|
/// position. If 1, it'll move into nodes that start at the
|
|
613
613
|
/// position. With 0, it'll only enter nodes that cover the position
|
|
614
614
|
/// from both sides.
|
|
615
|
+
///
|
|
616
|
+
/// Note that this will not enter
|
|
617
|
+
/// [overlays](#common.MountedTree.overlay), and you often want
|
|
618
|
+
/// [`resolveInner`](#common.Tree.resolveInner) instead.
|
|
615
619
|
resolve(pos, side = 0) {
|
|
616
620
|
let node = resolveNode(CachedNode.get(this) || this.topNode, pos, side, false);
|
|
617
621
|
CachedNode.set(this, node);
|
|
@@ -2094,14 +2098,14 @@ function enterFragments(mounts, ranges) {
|
|
|
2094
2098
|
for (let i = 0, pos = from;; i++) {
|
|
2095
2099
|
let last = i == changes.length, end = last ? to : changes[i].from;
|
|
2096
2100
|
if (end > pos)
|
|
2097
|
-
result.push(new TreeFragment(pos, end, mount.tree, -startPos, frag.from >= pos, frag.to <= end));
|
|
2101
|
+
result.push(new TreeFragment(pos, end, mount.tree, -startPos, frag.from >= pos || frag.openStart, frag.to <= end || frag.openEnd));
|
|
2098
2102
|
if (last)
|
|
2099
2103
|
break;
|
|
2100
2104
|
pos = changes[i].to;
|
|
2101
2105
|
}
|
|
2102
2106
|
}
|
|
2103
2107
|
else {
|
|
2104
|
-
result.push(new TreeFragment(from, to, mount.tree, -startPos, frag.from >= startPos, frag.to <= endPos));
|
|
2108
|
+
result.push(new TreeFragment(from, to, mount.tree, -startPos, frag.from >= startPos || frag.openStart, frag.to <= endPos || frag.openEnd));
|
|
2105
2109
|
}
|
|
2106
2110
|
}
|
|
2107
2111
|
return result;
|
|
@@ -6899,7 +6903,8 @@ class SearchCursor {
|
|
|
6899
6903
|
[`.normalize("NFKD")`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/normalize)
|
|
6900
6904
|
(when supported).
|
|
6901
6905
|
*/
|
|
6902
|
-
constructor(text, query, from = 0, to = text.length, normalize) {
|
|
6906
|
+
constructor(text, query, from = 0, to = text.length, normalize, test) {
|
|
6907
|
+
this.test = test;
|
|
6903
6908
|
/**
|
|
6904
6909
|
The current match (only holds a meaningful value after
|
|
6905
6910
|
[`next`](https://codemirror.net/6/docs/ref/#search.SearchCursor.next) has been called and when
|
|
@@ -6993,6 +6998,8 @@ class SearchCursor {
|
|
|
6993
6998
|
else
|
|
6994
6999
|
this.matches.push(1, pos);
|
|
6995
7000
|
}
|
|
7001
|
+
if (match && this.test && !this.test(match.from, match.to, this.buffer, this.bufferPos))
|
|
7002
|
+
match = null;
|
|
6996
7003
|
return match;
|
|
6997
7004
|
}
|
|
6998
7005
|
}
|
|
@@ -7030,6 +7037,7 @@ class RegExpCursor {
|
|
|
7030
7037
|
if (/\\[sWDnr]|\n|\r|\[\^/.test(query))
|
|
7031
7038
|
return new MultilineRegExpCursor(text, query, options, from, to);
|
|
7032
7039
|
this.re = new RegExp(query, baseFlags + ((options === null || options === void 0 ? void 0 : options.ignoreCase) ? "i" : ""));
|
|
7040
|
+
this.test = options === null || options === void 0 ? void 0 : options.test;
|
|
7033
7041
|
this.iter = text.iter();
|
|
7034
7042
|
let startLine = text.lineAt(from);
|
|
7035
7043
|
this.curLineStart = startLine.from;
|
|
@@ -7067,7 +7075,7 @@ class RegExpCursor {
|
|
|
7067
7075
|
this.matchPos = toCharEnd(this.text, to + (from == to ? 1 : 0));
|
|
7068
7076
|
if (from == this.curLine.length)
|
|
7069
7077
|
this.nextLine();
|
|
7070
|
-
if (from < to || from > this.value.to) {
|
|
7078
|
+
if ((from < to || from > this.value.to) && (!this.test || this.test(from, to, match))) {
|
|
7071
7079
|
this.value = { from, to, match };
|
|
7072
7080
|
return this;
|
|
7073
7081
|
}
|
|
@@ -7120,6 +7128,7 @@ class MultilineRegExpCursor {
|
|
|
7120
7128
|
this.value = empty;
|
|
7121
7129
|
this.matchPos = toCharEnd(text, from);
|
|
7122
7130
|
this.re = new RegExp(query, baseFlags + ((options === null || options === void 0 ? void 0 : options.ignoreCase) ? "i" : ""));
|
|
7131
|
+
this.test = options === null || options === void 0 ? void 0 : options.test;
|
|
7123
7132
|
this.flat = FlattenedDoc.get(text, from, this.chunkEnd(from + 5000 /* Base */));
|
|
7124
7133
|
}
|
|
7125
7134
|
chunkEnd(pos) {
|
|
@@ -7134,24 +7143,23 @@ class MultilineRegExpCursor {
|
|
|
7134
7143
|
this.re.lastIndex = off + 1;
|
|
7135
7144
|
match = this.re.exec(this.flat.text);
|
|
7136
7145
|
}
|
|
7137
|
-
// If a match goes almost to the end of a noncomplete chunk, try
|
|
7138
|
-
// again, since it'll likely be able to match more
|
|
7139
|
-
if (match && this.flat.to < this.to && match.index + match[0].length > this.flat.text.length - 10)
|
|
7140
|
-
match = null;
|
|
7141
7146
|
if (match) {
|
|
7142
7147
|
let from = this.flat.from + match.index, to = from + match[0].length;
|
|
7143
|
-
|
|
7144
|
-
|
|
7145
|
-
|
|
7146
|
-
|
|
7147
|
-
|
|
7148
|
-
|
|
7149
|
-
this.done = true;
|
|
7148
|
+
// If a match goes almost to the end of a noncomplete chunk, try
|
|
7149
|
+
// again, since it'll likely be able to match more
|
|
7150
|
+
if ((this.flat.to >= this.to || match.index + match[0].length <= this.flat.text.length - 10) &&
|
|
7151
|
+
(!this.test || this.test(from, to, match))) {
|
|
7152
|
+
this.value = { from, to, match };
|
|
7153
|
+
this.matchPos = toCharEnd(this.text, to + (from == to ? 1 : 0));
|
|
7150
7154
|
return this;
|
|
7151
7155
|
}
|
|
7152
|
-
// Grow the flattened doc
|
|
7153
|
-
this.flat = FlattenedDoc.get(this.text, this.flat.from, this.chunkEnd(this.flat.from + this.flat.text.length * 2));
|
|
7154
7156
|
}
|
|
7157
|
+
if (this.flat.to == this.to) {
|
|
7158
|
+
this.done = true;
|
|
7159
|
+
return this;
|
|
7160
|
+
}
|
|
7161
|
+
// Grow the flattened doc
|
|
7162
|
+
this.flat = FlattenedDoc.get(this.text, this.flat.from, this.chunkEnd(this.flat.from + this.flat.text.length * 2));
|
|
7155
7163
|
}
|
|
7156
7164
|
}
|
|
7157
7165
|
}
|
|
@@ -7427,13 +7435,13 @@ const selectNextOccurrence = ({ state, dispatch }) => {
|
|
|
7427
7435
|
|
|
7428
7436
|
const searchConfigFacet = /*@__PURE__*/state_.Facet.define({
|
|
7429
7437
|
combine(configs) {
|
|
7430
|
-
|
|
7431
|
-
|
|
7432
|
-
|
|
7433
|
-
|
|
7434
|
-
|
|
7435
|
-
createPanel:
|
|
7436
|
-
};
|
|
7438
|
+
return (0,state_.combineConfig)(configs, {
|
|
7439
|
+
top: false,
|
|
7440
|
+
caseSensitive: false,
|
|
7441
|
+
literal: false,
|
|
7442
|
+
wholeWord: false,
|
|
7443
|
+
createPanel: view => new SearchPanel(view)
|
|
7444
|
+
});
|
|
7437
7445
|
}
|
|
7438
7446
|
});
|
|
7439
7447
|
/**
|
|
@@ -7460,13 +7468,15 @@ class SearchQuery {
|
|
|
7460
7468
|
this.replace = config.replace || "";
|
|
7461
7469
|
this.valid = !!this.search && (!this.regexp || validRegExp(this.search));
|
|
7462
7470
|
this.unquoted = this.literal ? this.search : this.search.replace(/\\([nrt\\])/g, (_, ch) => ch == "n" ? "\n" : ch == "r" ? "\r" : ch == "t" ? "\t" : "\\");
|
|
7471
|
+
this.wholeWord = !!config.wholeWord;
|
|
7463
7472
|
}
|
|
7464
7473
|
/**
|
|
7465
7474
|
Compare this query to another query.
|
|
7466
7475
|
*/
|
|
7467
7476
|
eq(other) {
|
|
7468
7477
|
return this.search == other.search && this.replace == other.replace &&
|
|
7469
|
-
this.caseSensitive == other.caseSensitive && this.regexp == other.regexp
|
|
7478
|
+
this.caseSensitive == other.caseSensitive && this.regexp == other.regexp &&
|
|
7479
|
+
this.wholeWord == other.wholeWord;
|
|
7470
7480
|
}
|
|
7471
7481
|
/**
|
|
7472
7482
|
@internal
|
|
@@ -7476,10 +7486,13 @@ class SearchQuery {
|
|
|
7476
7486
|
}
|
|
7477
7487
|
/**
|
|
7478
7488
|
Get a search cursor for this query, searching through the given
|
|
7479
|
-
range in the given
|
|
7489
|
+
range in the given state.
|
|
7480
7490
|
*/
|
|
7481
|
-
getCursor(
|
|
7482
|
-
|
|
7491
|
+
getCursor(state, from = 0, to) {
|
|
7492
|
+
let st = state.doc ? state : state_.EditorState.create({ doc: state });
|
|
7493
|
+
if (to == null)
|
|
7494
|
+
to = st.doc.length;
|
|
7495
|
+
return this.regexp ? regexpCursor(this, st, from, to) : stringCursor(this, st, from, to);
|
|
7483
7496
|
}
|
|
7484
7497
|
}
|
|
7485
7498
|
class QueryType {
|
|
@@ -7487,25 +7500,37 @@ class QueryType {
|
|
|
7487
7500
|
this.spec = spec;
|
|
7488
7501
|
}
|
|
7489
7502
|
}
|
|
7490
|
-
function stringCursor(spec,
|
|
7491
|
-
return new SearchCursor(doc, spec.unquoted, from, to, spec.caseSensitive ? undefined : x => x.toLowerCase());
|
|
7503
|
+
function stringCursor(spec, state, from, to) {
|
|
7504
|
+
return new SearchCursor(state.doc, spec.unquoted, from, to, spec.caseSensitive ? undefined : x => x.toLowerCase(), spec.wholeWord ? stringWordTest(state.doc, state.charCategorizer(state.selection.main.head)) : undefined);
|
|
7505
|
+
}
|
|
7506
|
+
function stringWordTest(doc, categorizer) {
|
|
7507
|
+
return (from, to, buf, bufPos) => {
|
|
7508
|
+
if (bufPos > from || bufPos + buf.length < to) {
|
|
7509
|
+
bufPos = Math.max(0, from - 2);
|
|
7510
|
+
buf = doc.sliceString(bufPos, Math.min(doc.length, to + 2));
|
|
7511
|
+
}
|
|
7512
|
+
return categorizer(charAfter(buf, from - bufPos)) != state_.CharCategory.Word ||
|
|
7513
|
+
categorizer(charBefore(buf, to - bufPos)) != state_.CharCategory.Word ||
|
|
7514
|
+
(categorizer(charBefore(buf, from - bufPos)) != state_.CharCategory.Word &&
|
|
7515
|
+
categorizer(charAfter(buf, to - bufPos)) != state_.CharCategory.Word);
|
|
7516
|
+
};
|
|
7492
7517
|
}
|
|
7493
7518
|
class StringQuery extends QueryType {
|
|
7494
7519
|
constructor(spec) {
|
|
7495
7520
|
super(spec);
|
|
7496
7521
|
}
|
|
7497
|
-
nextMatch(
|
|
7498
|
-
let cursor = stringCursor(this.spec,
|
|
7522
|
+
nextMatch(state, curFrom, curTo) {
|
|
7523
|
+
let cursor = stringCursor(this.spec, state, curTo, state.doc.length).nextOverlapping();
|
|
7499
7524
|
if (cursor.done)
|
|
7500
|
-
cursor = stringCursor(this.spec,
|
|
7525
|
+
cursor = stringCursor(this.spec, state, 0, curFrom).nextOverlapping();
|
|
7501
7526
|
return cursor.done ? null : cursor.value;
|
|
7502
7527
|
}
|
|
7503
7528
|
// Searching in reverse is, rather than implementing inverted search
|
|
7504
7529
|
// cursor, done by scanning chunk after chunk forward.
|
|
7505
|
-
prevMatchInRange(
|
|
7530
|
+
prevMatchInRange(state, from, to) {
|
|
7506
7531
|
for (let pos = to;;) {
|
|
7507
7532
|
let start = Math.max(from, pos - 10000 /* ChunkSize */ - this.spec.unquoted.length);
|
|
7508
|
-
let cursor = stringCursor(this.spec,
|
|
7533
|
+
let cursor = stringCursor(this.spec, state, start, pos), range = null;
|
|
7509
7534
|
while (!cursor.nextOverlapping().done)
|
|
7510
7535
|
range = cursor.value;
|
|
7511
7536
|
if (range)
|
|
@@ -7515,13 +7540,13 @@ class StringQuery extends QueryType {
|
|
|
7515
7540
|
pos -= 10000 /* ChunkSize */;
|
|
7516
7541
|
}
|
|
7517
7542
|
}
|
|
7518
|
-
prevMatch(
|
|
7519
|
-
return this.prevMatchInRange(
|
|
7520
|
-
this.prevMatchInRange(
|
|
7543
|
+
prevMatch(state, curFrom, curTo) {
|
|
7544
|
+
return this.prevMatchInRange(state, 0, curFrom) ||
|
|
7545
|
+
this.prevMatchInRange(state, curTo, state.doc.length);
|
|
7521
7546
|
}
|
|
7522
7547
|
getReplacement(_result) { return this.spec.replace; }
|
|
7523
|
-
matchAll(
|
|
7524
|
-
let cursor = stringCursor(this.spec,
|
|
7548
|
+
matchAll(state, limit) {
|
|
7549
|
+
let cursor = stringCursor(this.spec, state, 0, state.doc.length), ranges = [];
|
|
7525
7550
|
while (!cursor.next().done) {
|
|
7526
7551
|
if (ranges.length >= limit)
|
|
7527
7552
|
return null;
|
|
@@ -7529,26 +7554,42 @@ class StringQuery extends QueryType {
|
|
|
7529
7554
|
}
|
|
7530
7555
|
return ranges;
|
|
7531
7556
|
}
|
|
7532
|
-
highlight(
|
|
7533
|
-
let cursor = stringCursor(this.spec,
|
|
7557
|
+
highlight(state, from, to, add) {
|
|
7558
|
+
let cursor = stringCursor(this.spec, state, Math.max(0, from - this.spec.unquoted.length), Math.min(to + this.spec.unquoted.length, state.doc.length));
|
|
7534
7559
|
while (!cursor.next().done)
|
|
7535
7560
|
add(cursor.value.from, cursor.value.to);
|
|
7536
7561
|
}
|
|
7537
7562
|
}
|
|
7538
|
-
function regexpCursor(spec,
|
|
7539
|
-
return new RegExpCursor(doc, spec.search,
|
|
7563
|
+
function regexpCursor(spec, state, from, to) {
|
|
7564
|
+
return new RegExpCursor(state.doc, spec.search, {
|
|
7565
|
+
ignoreCase: !spec.caseSensitive,
|
|
7566
|
+
test: spec.wholeWord ? regexpWordTest(state.charCategorizer(state.selection.main.head)) : undefined
|
|
7567
|
+
}, from, to);
|
|
7568
|
+
}
|
|
7569
|
+
function charBefore(str, index) {
|
|
7570
|
+
return str.slice((0,state_.findClusterBreak)(str, index, false), index);
|
|
7571
|
+
}
|
|
7572
|
+
function charAfter(str, index) {
|
|
7573
|
+
return str.slice(index, (0,state_.findClusterBreak)(str, index));
|
|
7574
|
+
}
|
|
7575
|
+
function regexpWordTest(categorizer) {
|
|
7576
|
+
return (_from, _to, match) => !match[0].length ||
|
|
7577
|
+
categorizer(charAfter(match.input, match.index)) != state_.CharCategory.Word ||
|
|
7578
|
+
categorizer(charBefore(match.input, match.index + match[0].length)) != state_.CharCategory.Word ||
|
|
7579
|
+
(categorizer(charBefore(match.input, match.index)) != state_.CharCategory.Word &&
|
|
7580
|
+
categorizer(charAfter(match.input, match.index + match[0].length)) != state_.CharCategory.Word);
|
|
7540
7581
|
}
|
|
7541
7582
|
class RegExpQuery extends QueryType {
|
|
7542
|
-
nextMatch(
|
|
7543
|
-
let cursor = regexpCursor(this.spec,
|
|
7583
|
+
nextMatch(state, curFrom, curTo) {
|
|
7584
|
+
let cursor = regexpCursor(this.spec, state, curTo, state.doc.length).next();
|
|
7544
7585
|
if (cursor.done)
|
|
7545
|
-
cursor = regexpCursor(this.spec,
|
|
7586
|
+
cursor = regexpCursor(this.spec, state, 0, curFrom).next();
|
|
7546
7587
|
return cursor.done ? null : cursor.value;
|
|
7547
7588
|
}
|
|
7548
|
-
prevMatchInRange(
|
|
7589
|
+
prevMatchInRange(state, from, to) {
|
|
7549
7590
|
for (let size = 1;; size++) {
|
|
7550
7591
|
let start = Math.max(from, to - size * 10000 /* ChunkSize */);
|
|
7551
|
-
let cursor = regexpCursor(this.spec,
|
|
7592
|
+
let cursor = regexpCursor(this.spec, state, start, to), range = null;
|
|
7552
7593
|
while (!cursor.next().done)
|
|
7553
7594
|
range = cursor.value;
|
|
7554
7595
|
if (range && (start == from || range.from > start + 10))
|
|
@@ -7557,9 +7598,9 @@ class RegExpQuery extends QueryType {
|
|
|
7557
7598
|
return null;
|
|
7558
7599
|
}
|
|
7559
7600
|
}
|
|
7560
|
-
prevMatch(
|
|
7561
|
-
return this.prevMatchInRange(
|
|
7562
|
-
this.prevMatchInRange(
|
|
7601
|
+
prevMatch(state, curFrom, curTo) {
|
|
7602
|
+
return this.prevMatchInRange(state, 0, curFrom) ||
|
|
7603
|
+
this.prevMatchInRange(state, curTo, state.doc.length);
|
|
7563
7604
|
}
|
|
7564
7605
|
getReplacement(result) {
|
|
7565
7606
|
return this.spec.replace.replace(/\$([$&\d+])/g, (m, i) => i == "$" ? "$"
|
|
@@ -7567,8 +7608,8 @@ class RegExpQuery extends QueryType {
|
|
|
7567
7608
|
: i != "0" && +i < result.match.length ? result.match[i]
|
|
7568
7609
|
: m);
|
|
7569
7610
|
}
|
|
7570
|
-
matchAll(
|
|
7571
|
-
let cursor = regexpCursor(this.spec,
|
|
7611
|
+
matchAll(state, limit) {
|
|
7612
|
+
let cursor = regexpCursor(this.spec, state, 0, state.doc.length), ranges = [];
|
|
7572
7613
|
while (!cursor.next().done) {
|
|
7573
7614
|
if (ranges.length >= limit)
|
|
7574
7615
|
return null;
|
|
@@ -7576,8 +7617,8 @@ class RegExpQuery extends QueryType {
|
|
|
7576
7617
|
}
|
|
7577
7618
|
return ranges;
|
|
7578
7619
|
}
|
|
7579
|
-
highlight(
|
|
7580
|
-
let cursor = regexpCursor(this.spec,
|
|
7620
|
+
highlight(state, from, to, add) {
|
|
7621
|
+
let cursor = regexpCursor(this.spec, state, Math.max(0, from - 250 /* HighlightMargin */), Math.min(to + 250 /* HighlightMargin */, state.doc.length));
|
|
7581
7622
|
while (!cursor.next().done)
|
|
7582
7623
|
add(cursor.value.from, cursor.value.to);
|
|
7583
7624
|
}
|
|
@@ -7646,7 +7687,7 @@ const searchHighlighter = /*@__PURE__*/view_.ViewPlugin.fromClass(class {
|
|
|
7646
7687
|
let { from, to } = ranges[i];
|
|
7647
7688
|
while (i < l - 1 && to > ranges[i + 1].from - 2 * 250 /* HighlightMargin */)
|
|
7648
7689
|
to = ranges[++i].to;
|
|
7649
|
-
query.highlight(view.state
|
|
7690
|
+
query.highlight(view.state, from, to, (from, to) => {
|
|
7650
7691
|
let selected = view.state.selection.ranges.some(r => r.from == from && r.to == to);
|
|
7651
7692
|
builder.add(from, to, selected ? selectedMatchMark : matchMark);
|
|
7652
7693
|
});
|
|
@@ -7670,7 +7711,7 @@ end.
|
|
|
7670
7711
|
*/
|
|
7671
7712
|
const findNext = /*@__PURE__*/searchCommand((view, { query }) => {
|
|
7672
7713
|
let { to } = view.state.selection.main;
|
|
7673
|
-
let next = query.nextMatch(view.state
|
|
7714
|
+
let next = query.nextMatch(view.state, to, to);
|
|
7674
7715
|
if (!next)
|
|
7675
7716
|
return false;
|
|
7676
7717
|
view.dispatch({
|
|
@@ -7688,7 +7729,7 @@ of the document to start searching at the end again.
|
|
|
7688
7729
|
*/
|
|
7689
7730
|
const findPrevious = /*@__PURE__*/searchCommand((view, { query }) => {
|
|
7690
7731
|
let { state } = view, { from } = state.selection.main;
|
|
7691
|
-
let range = query.prevMatch(state
|
|
7732
|
+
let range = query.prevMatch(state, from, from);
|
|
7692
7733
|
if (!range)
|
|
7693
7734
|
return false;
|
|
7694
7735
|
view.dispatch({
|
|
@@ -7703,7 +7744,7 @@ const findPrevious = /*@__PURE__*/searchCommand((view, { query }) => {
|
|
|
7703
7744
|
Select all instances of the search query.
|
|
7704
7745
|
*/
|
|
7705
7746
|
const selectMatches = /*@__PURE__*/searchCommand((view, { query }) => {
|
|
7706
|
-
let ranges = query.matchAll(view.state
|
|
7747
|
+
let ranges = query.matchAll(view.state, 1000);
|
|
7707
7748
|
if (!ranges || !ranges.length)
|
|
7708
7749
|
return false;
|
|
7709
7750
|
view.dispatch({
|
|
@@ -7741,7 +7782,7 @@ const replaceNext = /*@__PURE__*/searchCommand((view, { query }) => {
|
|
|
7741
7782
|
let { state } = view, { from, to } = state.selection.main;
|
|
7742
7783
|
if (state.readOnly)
|
|
7743
7784
|
return false;
|
|
7744
|
-
let next = query.nextMatch(state
|
|
7785
|
+
let next = query.nextMatch(state, from, from);
|
|
7745
7786
|
if (!next)
|
|
7746
7787
|
return false;
|
|
7747
7788
|
let changes = [], selection, replacement;
|
|
@@ -7749,7 +7790,7 @@ const replaceNext = /*@__PURE__*/searchCommand((view, { query }) => {
|
|
|
7749
7790
|
if (next.from == from && next.to == to) {
|
|
7750
7791
|
replacement = state.toText(query.getReplacement(next));
|
|
7751
7792
|
changes.push({ from: next.from, to: next.to, insert: replacement });
|
|
7752
|
-
next = query.nextMatch(state
|
|
7793
|
+
next = query.nextMatch(state, next.from, next.to);
|
|
7753
7794
|
announce.push(view_.EditorView.announce.of(state.phrase("replaced match on line $", state.doc.lineAt(from).number) + "."));
|
|
7754
7795
|
}
|
|
7755
7796
|
if (next) {
|
|
@@ -7772,7 +7813,7 @@ replacement.
|
|
|
7772
7813
|
const replaceAll = /*@__PURE__*/searchCommand((view, { query }) => {
|
|
7773
7814
|
if (view.state.readOnly)
|
|
7774
7815
|
return false;
|
|
7775
|
-
let changes = query.matchAll(view.state
|
|
7816
|
+
let changes = query.matchAll(view.state, 1e9).map(match => {
|
|
7776
7817
|
let { from, to } = match;
|
|
7777
7818
|
return { from, to, insert: query.getReplacement(match) };
|
|
7778
7819
|
});
|
|
@@ -7790,7 +7831,7 @@ function createSearchPanel(view) {
|
|
|
7790
7831
|
return view.state.facet(searchConfigFacet).createPanel(view);
|
|
7791
7832
|
}
|
|
7792
7833
|
function defaultQuery(state, fallback) {
|
|
7793
|
-
var _a, _b, _c;
|
|
7834
|
+
var _a, _b, _c, _d;
|
|
7794
7835
|
let sel = state.selection.main;
|
|
7795
7836
|
let selText = sel.empty || sel.to > sel.from + 100 ? "" : state.sliceDoc(sel.from, sel.to);
|
|
7796
7837
|
if (fallback && !selText)
|
|
@@ -7800,6 +7841,7 @@ function defaultQuery(state, fallback) {
|
|
|
7800
7841
|
search: ((_a = fallback === null || fallback === void 0 ? void 0 : fallback.literal) !== null && _a !== void 0 ? _a : config.literal) ? selText : selText.replace(/\n/g, "\\n"),
|
|
7801
7842
|
caseSensitive: (_b = fallback === null || fallback === void 0 ? void 0 : fallback.caseSensitive) !== null && _b !== void 0 ? _b : config.caseSensitive,
|
|
7802
7843
|
literal: (_c = fallback === null || fallback === void 0 ? void 0 : fallback.literal) !== null && _c !== void 0 ? _c : config.literal,
|
|
7844
|
+
wholeWord: (_d = fallback === null || fallback === void 0 ? void 0 : fallback.wholeWord) !== null && _d !== void 0 ? _d : config.wholeWord
|
|
7803
7845
|
});
|
|
7804
7846
|
}
|
|
7805
7847
|
/**
|
|
@@ -7895,6 +7937,12 @@ class SearchPanel {
|
|
|
7895
7937
|
checked: query.regexp,
|
|
7896
7938
|
onchange: this.commit
|
|
7897
7939
|
});
|
|
7940
|
+
this.wordField = crelt("input", {
|
|
7941
|
+
type: "checkbox",
|
|
7942
|
+
name: "word",
|
|
7943
|
+
checked: query.wholeWord,
|
|
7944
|
+
onchange: this.commit
|
|
7945
|
+
});
|
|
7898
7946
|
function button(name, onclick, content) {
|
|
7899
7947
|
return crelt("button", { class: "cm-button", name, onclick, type: "button" }, content);
|
|
7900
7948
|
}
|
|
@@ -7905,6 +7953,7 @@ class SearchPanel {
|
|
|
7905
7953
|
button("select", () => selectMatches(view), [phrase(view, "all")]),
|
|
7906
7954
|
crelt("label", null, [this.caseField, phrase(view, "match case")]),
|
|
7907
7955
|
crelt("label", null, [this.reField, phrase(view, "regexp")]),
|
|
7956
|
+
crelt("label", null, [this.wordField, phrase(view, "by word")]),
|
|
7908
7957
|
...view.state.readOnly ? [] : [
|
|
7909
7958
|
crelt("br"),
|
|
7910
7959
|
this.replaceField,
|
|
@@ -7924,7 +7973,8 @@ class SearchPanel {
|
|
|
7924
7973
|
search: this.searchField.value,
|
|
7925
7974
|
caseSensitive: this.caseField.checked,
|
|
7926
7975
|
regexp: this.reField.checked,
|
|
7927
|
-
|
|
7976
|
+
wholeWord: this.wordField.checked,
|
|
7977
|
+
replace: this.replaceField.value,
|
|
7928
7978
|
});
|
|
7929
7979
|
if (!query.eq(this.query)) {
|
|
7930
7980
|
this.query = query;
|
|
@@ -7957,6 +8007,7 @@ class SearchPanel {
|
|
|
7957
8007
|
this.replaceField.value = query.replace;
|
|
7958
8008
|
this.caseField.checked = query.caseSensitive;
|
|
7959
8009
|
this.reField.checked = query.regexp;
|
|
8010
|
+
this.wordField.checked = query.wholeWord;
|
|
7960
8011
|
}
|
|
7961
8012
|
mount() {
|
|
7962
8013
|
this.searchField.select();
|
|
@@ -10669,12 +10720,12 @@ var theme_one_dark_ = __webpack_require__(362);
|
|
|
10669
10720
|
;// CONCATENATED MODULE: ./src/utils.ts
|
|
10670
10721
|
var getStatistics=function getStatistics(view){return{line:view.state.doc.lineAt(view.state.selection.main.from),lineCount:view.state.doc.lines,lineBreak:view.state.lineBreak,length:view.state.doc.length,readOnly:view.state.readOnly,tabSize:view.state.tabSize,selection:view.state.selection,selectionAsSingle:view.state.selection.asSingle().main,ranges:view.state.selection.ranges,selectionCode:view.state.sliceDoc(view.state.selection.main.from,view.state.selection.main.to),selections:view.state.selection.ranges.map(function(r){return view.state.sliceDoc(r.from,r.to);}),selectedText:view.state.selection.ranges.some(function(r){return!r.empty;})};};
|
|
10671
10722
|
;// CONCATENATED MODULE: ./src/useCodeMirror.ts
|
|
10672
|
-
function useCodeMirror(props){var value=props.value,selection=props.selection,onChange=props.onChange,onStatistics=props.onStatistics,onCreateEditor=props.onCreateEditor,onUpdate=props.onUpdate,_props$extensions=props.extensions,extensions=_props$extensions===void 0?[]:_props$extensions,autoFocus=props.autoFocus,_props$theme=props.theme,theme=_props$theme===void 0?'light':_props$theme,_props$height=props.height,height=_props$height===void 0?'':_props$height,_props$minHeight=props.minHeight,minHeight=_props$minHeight===void 0?'':_props$minHeight,_props$maxHeight=props.maxHeight,maxHeight=_props$maxHeight===void 0?'':_props$maxHeight,_props$placeholder=props.placeholder,placeholderStr=_props$placeholder===void 0?'':_props$placeholder,_props$width=props.width,width=_props$width===void 0?'':_props$width,_props$minWidth=props.minWidth,minWidth=_props$minWidth===void 0?'':_props$minWidth,_props$maxWidth=props.maxWidth,maxWidth=_props$maxWidth===void 0?'':_props$maxWidth,_props$editable=props.editable,editable=_props$editable===void 0?true:_props$editable,_props$readOnly=props.readOnly,readOnly=_props$readOnly===void 0?false:_props$readOnly,_props$indentWithTab=props.indentWithTab,defaultIndentWithTab=_props$indentWithTab===void 0?true:_props$indentWithTab,_props$basicSetup=props.basicSetup,defaultBasicSetup=_props$basicSetup===void 0?true:_props$basicSetup,root=props.root;var _useState=(0,external_root_React_commonjs2_react_commonjs_react_amd_react_.useState)(),_useState2=_slicedToArray(_useState,2),container=_useState2[0],setContainer=_useState2[1];var _useState3=(0,external_root_React_commonjs2_react_commonjs_react_amd_react_.useState)(),_useState4=_slicedToArray(_useState3,2),view=_useState4[0],setView=_useState4[1];var _useState5=(0,external_root_React_commonjs2_react_commonjs_react_amd_react_.useState)(),_useState6=_slicedToArray(_useState5,2),state=_useState6[0],setState=_useState6[1];var defaultLightThemeOption=view_.EditorView.theme({'&':{backgroundColor:'#fff'}},{dark:false});var defaultThemeOption=view_.EditorView.theme({'&':{height:height,minHeight:minHeight,maxHeight:maxHeight,width:width,minWidth:minWidth,maxWidth:maxWidth}});var
|
|
10723
|
+
function useCodeMirror(props){var value=props.value,selection=props.selection,onChange=props.onChange,onStatistics=props.onStatistics,onCreateEditor=props.onCreateEditor,onUpdate=props.onUpdate,_props$extensions=props.extensions,extensions=_props$extensions===void 0?[]:_props$extensions,autoFocus=props.autoFocus,_props$theme=props.theme,theme=_props$theme===void 0?'light':_props$theme,_props$height=props.height,height=_props$height===void 0?'':_props$height,_props$minHeight=props.minHeight,minHeight=_props$minHeight===void 0?'':_props$minHeight,_props$maxHeight=props.maxHeight,maxHeight=_props$maxHeight===void 0?'':_props$maxHeight,_props$placeholder=props.placeholder,placeholderStr=_props$placeholder===void 0?'':_props$placeholder,_props$width=props.width,width=_props$width===void 0?'':_props$width,_props$minWidth=props.minWidth,minWidth=_props$minWidth===void 0?'':_props$minWidth,_props$maxWidth=props.maxWidth,maxWidth=_props$maxWidth===void 0?'':_props$maxWidth,_props$editable=props.editable,editable=_props$editable===void 0?true:_props$editable,_props$readOnly=props.readOnly,readOnly=_props$readOnly===void 0?false:_props$readOnly,_props$indentWithTab=props.indentWithTab,defaultIndentWithTab=_props$indentWithTab===void 0?true:_props$indentWithTab,_props$basicSetup=props.basicSetup,defaultBasicSetup=_props$basicSetup===void 0?true:_props$basicSetup,root=props.root,initialState=props.initialState;var _useState=(0,external_root_React_commonjs2_react_commonjs_react_amd_react_.useState)(),_useState2=_slicedToArray(_useState,2),container=_useState2[0],setContainer=_useState2[1];var _useState3=(0,external_root_React_commonjs2_react_commonjs_react_amd_react_.useState)(),_useState4=_slicedToArray(_useState3,2),view=_useState4[0],setView=_useState4[1];var _useState5=(0,external_root_React_commonjs2_react_commonjs_react_amd_react_.useState)(),_useState6=_slicedToArray(_useState5,2),state=_useState6[0],setState=_useState6[1];var defaultLightThemeOption=view_.EditorView.theme({'&':{backgroundColor:'#fff'}},{dark:false});var defaultThemeOption=view_.EditorView.theme({'&':{height:height,minHeight:minHeight,maxHeight:maxHeight,width:width,minWidth:minWidth,maxWidth:maxWidth}});var updateListener=view_.EditorView.updateListener.of(function(vu){if(vu.docChanged&&typeof onChange==='function'){var doc=vu.state.doc;var _value=doc.toString();onChange(_value,vu);}onStatistics&&onStatistics(getStatistics(vu));});var getExtensions=[updateListener,defaultThemeOption];if(defaultIndentWithTab){getExtensions.unshift(view_.keymap.of([indentWithTab]));}if(defaultBasicSetup){if(typeof defaultBasicSetup==='boolean'){getExtensions.unshift(basicSetup());}else{getExtensions.unshift(basicSetup(defaultBasicSetup));}}if(placeholderStr){getExtensions.unshift((0,view_.placeholder)(placeholderStr));}switch(theme){case'light':getExtensions.push(defaultLightThemeOption);break;case'dark':getExtensions.push(theme_one_dark_.oneDark);break;default:getExtensions.push(theme);break;}if(editable===false){getExtensions.push(view_.EditorView.editable.of(false));}if(readOnly){getExtensions.push(state_.EditorState.readOnly.of(true));}if(onUpdate&&typeof onUpdate==='function'){getExtensions.push(view_.EditorView.updateListener.of(onUpdate));}getExtensions=getExtensions.concat(extensions);(0,external_root_React_commonjs2_react_commonjs_react_amd_react_.useEffect)(function(){if(container&&!state){var config={doc:value,selection:selection,extensions:getExtensions};var stateCurrent=initialState?state_.EditorState.fromJSON(initialState.json,config,initialState.fields):state_.EditorState.create(config);setState(stateCurrent);if(!view){var viewCurrent=new view_.EditorView({state:stateCurrent,parent:container,root:root});setView(viewCurrent);onCreateEditor&&onCreateEditor(viewCurrent,stateCurrent);}}return function(){if(view){setState(undefined);setView(undefined);}};},[container,state]);(0,external_root_React_commonjs2_react_commonjs_react_amd_react_.useEffect)(function(){return setContainer(props.container);},[props.container]);(0,external_root_React_commonjs2_react_commonjs_react_amd_react_.useEffect)(function(){return function(){if(view){view.destroy();setView(undefined);}};},[view]);(0,external_root_React_commonjs2_react_commonjs_react_amd_react_.useEffect)(function(){if(autoFocus&&view){view.focus();}},[autoFocus,view]);(0,external_root_React_commonjs2_react_commonjs_react_amd_react_.useEffect)(function(){if(view){view.dispatch({effects:state_.StateEffect.reconfigure.of(getExtensions)});}// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
10673
10724
|
},[theme,extensions,height,minHeight,maxHeight,width,minWidth,maxWidth,placeholderStr,editable,readOnly,defaultIndentWithTab,defaultBasicSetup,onChange,onUpdate]);(0,external_root_React_commonjs2_react_commonjs_react_amd_react_.useEffect)(function(){var currentValue=view?view.state.doc.toString():'';if(view&&value!==currentValue){view.dispatch({changes:{from:0,to:currentValue.length,insert:value||''}});}},[value,view]);return{state:state,setState:setState,view:view,setView:setView,container:container,setContainer:setContainer};}
|
|
10674
10725
|
// EXTERNAL MODULE: ../node_modules/react/jsx-runtime.js
|
|
10675
10726
|
var jsx_runtime = __webpack_require__(605);
|
|
10676
10727
|
;// CONCATENATED MODULE: ./src/index.tsx
|
|
10677
|
-
var _excluded=["className","value","selection","extensions","onChange","onStatistics","onCreateEditor","onUpdate","autoFocus","theme","height","minHeight","maxHeight","width","minWidth","maxWidth","basicSetup","placeholder","indentWithTab","editable","readOnly","root"];var ReactCodeMirror=/*#__PURE__*/(0,external_root_React_commonjs2_react_commonjs_react_amd_react_.forwardRef)(function(props,ref){var className=props.className,_props$value=props.value,value=_props$value===void 0?'':_props$value,selection=props.selection,_props$extensions=props.extensions,extensions=_props$extensions===void 0?[]:_props$extensions,onChange=props.onChange,onStatistics=props.onStatistics,onCreateEditor=props.onCreateEditor,onUpdate=props.onUpdate,autoFocus=props.autoFocus,_props$theme=props.theme,theme=_props$theme===void 0?'light':_props$theme,height=props.height,minHeight=props.minHeight,maxHeight=props.maxHeight,width=props.width,minWidth=props.minWidth,maxWidth=props.maxWidth,basicSetup=props.basicSetup,placeholder=props.placeholder,indentWithTab=props.indentWithTab,editable=props.editable,readOnly=props.readOnly,root=props.root,other=_objectWithoutProperties(props,_excluded);var editor=(0,external_root_React_commonjs2_react_commonjs_react_amd_react_.useRef)(null);var _useCodeMirror=useCodeMirror({container:editor.current,root:root,value:value,autoFocus:autoFocus,theme:theme,height:height,minHeight:minHeight,maxHeight:maxHeight,width:width,minWidth:minWidth,maxWidth:maxWidth,basicSetup:basicSetup,placeholder:placeholder,indentWithTab:indentWithTab,editable:editable,readOnly:readOnly,selection:selection,onChange:onChange,onStatistics:onStatistics,onCreateEditor:onCreateEditor,onUpdate:onUpdate,extensions:extensions}),state=_useCodeMirror.state,view=_useCodeMirror.view,container=_useCodeMirror.container,setContainer=_useCodeMirror.setContainer;(0,external_root_React_commonjs2_react_commonjs_react_amd_react_.useImperativeHandle)(ref,function(){return{editor:editor.current,state:state,view:view};},[editor,container,state,view]);// check type of value
|
|
10728
|
+
var _excluded=["className","value","selection","extensions","onChange","onStatistics","onCreateEditor","onUpdate","autoFocus","theme","height","minHeight","maxHeight","width","minWidth","maxWidth","basicSetup","placeholder","indentWithTab","editable","readOnly","root","initialState"];var ReactCodeMirror=/*#__PURE__*/(0,external_root_React_commonjs2_react_commonjs_react_amd_react_.forwardRef)(function(props,ref){var className=props.className,_props$value=props.value,value=_props$value===void 0?'':_props$value,selection=props.selection,_props$extensions=props.extensions,extensions=_props$extensions===void 0?[]:_props$extensions,onChange=props.onChange,onStatistics=props.onStatistics,onCreateEditor=props.onCreateEditor,onUpdate=props.onUpdate,autoFocus=props.autoFocus,_props$theme=props.theme,theme=_props$theme===void 0?'light':_props$theme,height=props.height,minHeight=props.minHeight,maxHeight=props.maxHeight,width=props.width,minWidth=props.minWidth,maxWidth=props.maxWidth,basicSetup=props.basicSetup,placeholder=props.placeholder,indentWithTab=props.indentWithTab,editable=props.editable,readOnly=props.readOnly,root=props.root,initialState=props.initialState,other=_objectWithoutProperties(props,_excluded);var editor=(0,external_root_React_commonjs2_react_commonjs_react_amd_react_.useRef)(null);var _useCodeMirror=useCodeMirror({container:editor.current,root:root,value:value,autoFocus:autoFocus,theme:theme,height:height,minHeight:minHeight,maxHeight:maxHeight,width:width,minWidth:minWidth,maxWidth:maxWidth,basicSetup:basicSetup,placeholder:placeholder,indentWithTab:indentWithTab,editable:editable,readOnly:readOnly,selection:selection,onChange:onChange,onStatistics:onStatistics,onCreateEditor:onCreateEditor,onUpdate:onUpdate,extensions:extensions,initialState:initialState}),state=_useCodeMirror.state,view=_useCodeMirror.view,container=_useCodeMirror.container,setContainer=_useCodeMirror.setContainer;(0,external_root_React_commonjs2_react_commonjs_react_amd_react_.useImperativeHandle)(ref,function(){return{editor:editor.current,state:state,view:view};},[editor,container,state,view]);// check type of value
|
|
10678
10729
|
if(typeof value!=='string'){throw new Error("value must be typeof string but got ".concat(typeof value));}var defaultClassNames=typeof theme==='string'?"cm-theme-".concat(theme):'cm-theme';return/*#__PURE__*/(0,jsx_runtime.jsx)("div",_objectSpread2({ref:editor,className:"".concat(defaultClassNames).concat(className?" ".concat(className):'')},other));});ReactCodeMirror.displayName='CodeMirror';/* harmony default export */ const src = (ReactCodeMirror);
|
|
10679
10730
|
})();
|
|
10680
10731
|
|