Skip to content

Commit 3084094

Browse files
committed
Reorder less eagerly
1 parent 6182c7b commit 3084094

2 files changed

Lines changed: 13 additions & 2 deletions

File tree

.yarn/versions/49353831.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
releases:
2+
"@pitter-patter/shuffle": patch

packages/shuffle/src/transform/reorder.ts

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,11 +62,20 @@ export function findGap(doc: Node, pos: number, nodeType: NodeType) {
6262
const $pos = doc.resolve(pos);
6363

6464
let d = $pos.depth;
65-
while (!$pos.node(d).isTextblock && d > 0) {
65+
while (!$pos.node(d).isBlock && d > 0) {
6666
d--;
6767
}
6868

69-
const start = d === 0 ? pos : $pos.before(d);
69+
if (d === 0) {
70+
return pos;
71+
}
72+
73+
const textblock = $pos.node(d);
74+
const textblockPos = $pos.before(d);
75+
76+
const isInFirstHalf = pos <= textblockPos + textblock.nodeSize / 2;
77+
78+
const start = isInFirstHalf ? textblockPos : $pos.after(d);
7079

7180
const gap = start ? insertPoint(doc, start, nodeType) : start;
7281

0 commit comments

Comments
 (0)