@nerd-bible/wordgard 0.6.2-beta1 → 0.6.2-beta3
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/dist/editor.js +52 -46
- package/dist/set.d.ts +3 -2
- package/dist/set.js +5 -4
- package/package.json +1 -1
package/dist/editor.js
CHANGED
|
@@ -517,7 +517,6 @@ const globalDecoFacets = [tagShape, tagWidget, tagWrapper, tagAttribute, markSha
|
|
|
517
517
|
function findChangedRanges(prevState, prevDeco, state, deco, sections) {
|
|
518
518
|
let result = [];
|
|
519
519
|
let globalChange = globalDecoFacets.some(facet => prevState.facet(facet) !== state.facet(facet));
|
|
520
|
-
let shapeChanges = [];
|
|
521
520
|
for (let i = 0, posA = 0, posB = 0; i < sections.length;) {
|
|
522
521
|
let len = sections[i++], ins = sections[i++];
|
|
523
522
|
if (ins == -1 && globalChange) {
|
|
@@ -540,11 +539,6 @@ function findChangedRanges(prevState, prevDeco, state, deco, sections) {
|
|
|
540
539
|
compareDecoSet(prevDeco.points, deco.points, (a, b) => {
|
|
541
540
|
(a || PointSet.empty).compareRange(posA, b || PointSet.empty, posB, len, (pos, val) => {
|
|
542
541
|
add(pos, Math.min(pos + (val instanceof WidgetDecoration ? 0 : 1), endB));
|
|
543
|
-
if (val instanceof ShapeDecoration && !globalChange) {
|
|
544
|
-
let idx = findAbove(shapeChanges, 0, pos - 1);
|
|
545
|
-
if (idx == shapeChanges.length || shapeChanges[idx] != pos)
|
|
546
|
-
shapeChanges.splice(idx, 0, pos);
|
|
547
|
-
}
|
|
548
542
|
});
|
|
549
543
|
});
|
|
550
544
|
let joined = joinRanges(ranges), pos = posB, end = pos + len, j = 0;
|
|
@@ -573,34 +567,8 @@ function findChangedRanges(prevState, prevDeco, state, deco, sections) {
|
|
|
573
567
|
addSection(result, len, ins);
|
|
574
568
|
}
|
|
575
569
|
}
|
|
576
|
-
if (shapeChanges.length)
|
|
577
|
-
return addAtomicityChanges(result, prevState, shapeChanges);
|
|
578
570
|
return result;
|
|
579
571
|
}
|
|
580
|
-
function addAtomicityChanges(changes, prev, nodes) {
|
|
581
|
-
let added = [];
|
|
582
|
-
let scan = prev.doc.resolve(0), sectionPos = 0, sectionI = 0, off = 0;
|
|
583
|
-
for (let posB of nodes) {
|
|
584
|
-
while (posB >= sectionPos) {
|
|
585
|
-
let len = changes[sectionI++], ins = changes[sectionI++];
|
|
586
|
-
if (ins < 0) {
|
|
587
|
-
sectionPos += len;
|
|
588
|
-
}
|
|
589
|
-
else {
|
|
590
|
-
sectionPos += ins;
|
|
591
|
-
off += len - ins;
|
|
592
|
-
}
|
|
593
|
-
}
|
|
594
|
-
let posA = posB - off;
|
|
595
|
-
if (scan.pos < posA)
|
|
596
|
-
scan = scan.advance(posA - scan.pos);
|
|
597
|
-
let node = scan.nodeAfter;
|
|
598
|
-
if (!node)
|
|
599
|
-
continue;
|
|
600
|
-
added.push(posA, posA + node.length);
|
|
601
|
-
}
|
|
602
|
-
return added.length ? addUpdated(changes, added) : changes;
|
|
603
|
-
}
|
|
604
572
|
class SpanIterator {
|
|
605
573
|
ranges;
|
|
606
574
|
points;
|
|
@@ -756,7 +724,7 @@ class DecoIterator {
|
|
|
756
724
|
let pos = this.pos.advance(from - this.pos.pos), started = inclusiveStart;
|
|
757
725
|
let atomParent;
|
|
758
726
|
for (let p = pos.parent; p; p = p.parent)
|
|
759
|
-
if (this.state.isAtom(p.node.type))
|
|
727
|
+
if (!p.node.isDoc && (this.state.isAtom(p.node.type) || this.hasAtomShape(p.before)))
|
|
760
728
|
atomParent = p;
|
|
761
729
|
let pendingDeco = [], pendingPos = -1;
|
|
762
730
|
let pendingShape = null, pendingShapeSet = null;
|
|
@@ -892,6 +860,15 @@ class DecoIterator {
|
|
|
892
860
|
}
|
|
893
861
|
return shape;
|
|
894
862
|
}
|
|
863
|
+
atomCache = new Map();
|
|
864
|
+
hasAtomShape(pos) {
|
|
865
|
+
let has = this.atomCache.get(pos);
|
|
866
|
+
if (has == null) {
|
|
867
|
+
has = this.pointSets.some(s => s.at(pos, d => d instanceof ShapeDecoration && !d.shape.hasContent));
|
|
868
|
+
this.atomCache.set(pos, has);
|
|
869
|
+
}
|
|
870
|
+
return has;
|
|
871
|
+
}
|
|
895
872
|
}
|
|
896
873
|
function compareSetPrec(setA, setB, array) {
|
|
897
874
|
if (setA != setB)
|
|
@@ -1563,8 +1540,7 @@ class DocTile extends CompositeTile {
|
|
|
1563
1540
|
builder.update(0, true);
|
|
1564
1541
|
}
|
|
1565
1542
|
else if (ins == -1) {
|
|
1566
|
-
builder.keep(len, !startCovered, i == changes.length);
|
|
1567
|
-
startCovered = false;
|
|
1543
|
+
startCovered = builder.keep(len, !startCovered, i == changes.length);
|
|
1568
1544
|
}
|
|
1569
1545
|
else if (ins == -2) {
|
|
1570
1546
|
builder.update(len, !startCovered);
|
|
@@ -2043,11 +2019,9 @@ class ContentUpdate {
|
|
|
2043
2019
|
if (span) {
|
|
2044
2020
|
this.new = span;
|
|
2045
2021
|
}
|
|
2046
|
-
else {
|
|
2047
|
-
this.
|
|
2048
|
-
|
|
2049
|
-
this.new.addChild(inner);
|
|
2050
|
-
this.new = inner;
|
|
2022
|
+
else if (!tile.isNodeInner) { let copy = this.copyEltStructure(tile);
|
|
2023
|
+
this.new.addChild(copy);
|
|
2024
|
+
this.new = copy.contentTile;
|
|
2051
2025
|
}
|
|
2052
2026
|
},
|
|
2053
2027
|
leave: tile => {
|
|
@@ -2071,7 +2045,8 @@ class ContentUpdate {
|
|
|
2071
2045
|
}
|
|
2072
2046
|
},
|
|
2073
2047
|
skip: (tile, from, to) => {
|
|
2074
|
-
if (
|
|
2048
|
+
if (tile.isNodeInner) ;
|
|
2049
|
+
else if (!(tile instanceof TextTile)) {
|
|
2075
2050
|
if (!from && to == tile.length) {
|
|
2076
2051
|
this.reused.set(tile, 1);
|
|
2077
2052
|
this.new.addChild(tile);
|
|
@@ -2113,6 +2088,20 @@ class ContentUpdate {
|
|
|
2113
2088
|
};
|
|
2114
2089
|
}
|
|
2115
2090
|
keep(len, includeStart, includeEnd) {
|
|
2091
|
+
if (!!this.partialNode != (this.old.tile.isAtom && !this.old.tile.isText)) {
|
|
2092
|
+
let dist = Math.min(len, this.partialNode
|
|
2093
|
+
? this.state.doc.nodeAt(this.posB - this.partialNode.length).length - this.partialNode.length
|
|
2094
|
+
: this.old.tile.length - this.old.index);
|
|
2095
|
+
this.replace(dist, dist, includeStart);
|
|
2096
|
+
if (dist == len)
|
|
2097
|
+
return true;
|
|
2098
|
+
includeStart = false;
|
|
2099
|
+
len -= dist;
|
|
2100
|
+
}
|
|
2101
|
+
this.keepCheckEnd(len, includeStart, includeEnd);
|
|
2102
|
+
return includeEnd;
|
|
2103
|
+
}
|
|
2104
|
+
keepCheckEnd(len, includeStart, includeEnd) {
|
|
2116
2105
|
let cut = [], end = this.posB + len;
|
|
2117
2106
|
if (this.deco.endWidgets)
|
|
2118
2107
|
for (let nw = this.new, { tile, index, parent } = this.old, pos = this.posB; pos < end;) {
|
|
@@ -2387,6 +2376,16 @@ class ContentUpdate {
|
|
|
2387
2376
|
return tile;
|
|
2388
2377
|
}
|
|
2389
2378
|
}
|
|
2379
|
+
copyEltStructure(tile) {
|
|
2380
|
+
this.reused.set(tile, 2);
|
|
2381
|
+
let copy = EltTile.of(tile.elt, tile.tag, tile.flags, tile.boundary * 2, tile.dom);
|
|
2382
|
+
if (tile.isNodeOuter)
|
|
2383
|
+
for (let child of tile.children)
|
|
2384
|
+
if (child.isNodeInner) {
|
|
2385
|
+
copy.addChild((child.flags & 1024) ? this.copyEltStructure(child) : child);
|
|
2386
|
+
}
|
|
2387
|
+
return copy;
|
|
2388
|
+
}
|
|
2390
2389
|
ensureHackNode() {
|
|
2391
2390
|
let tile = this.new;
|
|
2392
2391
|
if (!tile.isPlotContent)
|
|
@@ -3390,7 +3389,14 @@ class DOMObserver {
|
|
|
3390
3389
|
return null;
|
|
3391
3390
|
}
|
|
3392
3391
|
else if (tile.dom == record.target) {
|
|
3393
|
-
|
|
3392
|
+
if (!tile.isNodeInner)
|
|
3393
|
+
return [tile.posBefore, tile.posAfter];
|
|
3394
|
+
while (tile.parent && tile.isNodeInner)
|
|
3395
|
+
tile = tile.parent;
|
|
3396
|
+
if (tile.isDoc)
|
|
3397
|
+
return null;
|
|
3398
|
+
let nodePos = tile.posBefore;
|
|
3399
|
+
return [nodePos, nodePos + 1];
|
|
3394
3400
|
}
|
|
3395
3401
|
else {
|
|
3396
3402
|
return childRange(tile, record);
|
|
@@ -3906,7 +3912,7 @@ class InputState {
|
|
|
3906
3912
|
return;
|
|
3907
3913
|
if (slice) {
|
|
3908
3914
|
wg.dispatch({
|
|
3909
|
-
changes: { from, to, insert: slice, fit: true },
|
|
3915
|
+
changes: { correct: { from, to, insert: slice, fit: true }, local: true },
|
|
3910
3916
|
selection: isSel ? (cx, changes) => GardSelection.near(cx, changes.mapPos(to, 1), -1) : undefined,
|
|
3911
3917
|
userEvent: "input.paste",
|
|
3912
3918
|
scrollIntoView: isSel
|
|
@@ -4442,10 +4448,10 @@ const baseHandlers = {
|
|
|
4442
4448
|
let dropPos = wg.posAtCoords({ x: event.clientX, y: event.clientY }).pos;
|
|
4443
4449
|
let { draggedContent } = wg.inputState;
|
|
4444
4450
|
let del = draggedContent && dragMovesSelection(wg, event)
|
|
4445
|
-
? { from: draggedContent.from, to: draggedContent.to } : null;
|
|
4446
|
-
if (wg.state.facet(dropHandler).some(f => f(wg, event, dropPos, del, slice)))
|
|
4451
|
+
? { correct: { from: draggedContent.from, to: draggedContent.to }, local: true } : null;
|
|
4452
|
+
if (wg.state.facet(dropHandler).some(f => f(wg, event, dropPos, del ? del.correct : null, slice)))
|
|
4447
4453
|
return true;
|
|
4448
|
-
let ins = { from: dropPos, insert: slice, fit: true };
|
|
4454
|
+
let ins = { correct: { from: dropPos, insert: slice, fit: true }, local: true };
|
|
4449
4455
|
let changes = ChangeSet.create(wg.state.doc, del ? [del, ins] : ins);
|
|
4450
4456
|
wg.focus();
|
|
4451
4457
|
wg.dispatch({
|
package/dist/set.d.ts
CHANGED
|
@@ -195,9 +195,10 @@ declare class PointSet<T extends PointSet.Value> implements Set<T> {
|
|
|
195
195
|
/**
|
|
196
196
|
Get the value at the given position, if any. If there's multiple
|
|
197
197
|
values at that position, the one with the lowest side is
|
|
198
|
-
returned.
|
|
198
|
+
returned. If a predicate is given, only points that satisfy it
|
|
199
|
+
are returned.
|
|
199
200
|
*/
|
|
200
|
-
at(pos: number): T | undefined;
|
|
201
|
+
at(pos: number, pred?: (value: T) => boolean): T | undefined;
|
|
201
202
|
/**
|
|
202
203
|
Adjust the points for a set of document changes. Returns a new
|
|
203
204
|
set with the adjusted points. May delete points when the content
|
package/dist/set.js
CHANGED
|
@@ -556,15 +556,16 @@ class PointSet {
|
|
|
556
556
|
cursors.push(set.cursor(from, side));
|
|
557
557
|
return cursors.length == 0 ? PointSet.empty.cursor() : cursors.length == 1 ? cursors[0] : new HeapCursor(cmpCursor, cursors);
|
|
558
558
|
}
|
|
559
|
-
at(pos) {
|
|
559
|
+
at(pos, pred) {
|
|
560
560
|
for (let chunk of this.chunks) {
|
|
561
561
|
if (chunk.start > pos)
|
|
562
562
|
break;
|
|
563
563
|
if (chunk.end < pos)
|
|
564
564
|
continue;
|
|
565
|
-
let index = findAbove(chunk.pos, 0, pos - chunk.start - 1);
|
|
566
|
-
|
|
567
|
-
|
|
565
|
+
for (let index = findAbove(chunk.pos, 0, pos - chunk.start - 1); index < chunk.pos.length && chunk.pos[index] + chunk.start == pos; index++) {
|
|
566
|
+
if (!pred || pred(chunk.value[index]))
|
|
567
|
+
return chunk.value[index];
|
|
568
|
+
}
|
|
568
569
|
}
|
|
569
570
|
return undefined;
|
|
570
571
|
}
|