rebuild hrm

This commit is contained in:
2026-04-13 09:30:59 +08:00
parent 44a98495ab
commit cd31c74da8
12034 changed files with 548007 additions and 451275 deletions

View File

@@ -338,7 +338,7 @@ export function replaceRange(tr: Transform, from: number, to: number, slice: Sli
if (fitsTrivially($from, $to, slice))
return tr.step(new ReplaceStep(from, to, slice))
let targetDepths = coveredDepths($from, tr.doc.resolve(to))
let targetDepths = coveredDepths($from, $to)
// Can't replace the whole document, so remove 0 if it's present
if (targetDepths[targetDepths.length - 1] == 0) targetDepths.pop()
// Negative numbers represent not expansion over the whole node at

View File

@@ -15,12 +15,14 @@ function canCut(node: Node, start: number, end: number) {
export function liftTarget(range: NodeRange): number | null {
let parent = range.parent
let content = parent.content.cutByIndex(range.startIndex, range.endIndex)
for (let depth = range.depth;; --depth) {
for (let depth = range.depth, contentBefore = 0, contentAfter = 0;; --depth) {
let node = range.$from.node(depth)
let index = range.$from.index(depth), endIndex = range.$to.indexAfter(depth)
let index = range.$from.index(depth) + contentBefore, endIndex = range.$to.indexAfter(depth) - contentAfter
if (depth < range.depth && node.canReplace(index, endIndex, content))
return depth
if (depth == 0 || node.type.spec.isolating || !canCut(node, index, endIndex)) break
if (index) contentBefore = 1
if (endIndex < node.childCount) contentAfter = 1
}
return null
}

View File

@@ -1,5 +1,4 @@
import {Node, NodeType, Mark, MarkType, ContentMatch, Slice, Fragment, NodeRange, Attrs} from "prosemirror-model"
import {Mapping} from "./map"
import {Step} from "./step"
import {addMark, removeMark, clearIncompatible} from "./mark"
@@ -66,6 +65,26 @@ export class Transform {
return this.steps.length > 0
}
/// Return a single range, in post-transform document positions,
/// that covers all content changed by this transform. Returns null
/// if no replacements are made. Note that this will ignore changes
/// that add/remove marks without replacing the underlying content.
changedRange() {
let from = 1e9, to = -1e9
for (let i = 0; i < this.mapping.maps.length; i++) {
let map = this.mapping.maps[i]
if (i) {
from = map.map(from, 1)
to = map.map(to, -1)
}
map.forEach((_f, _t, fromB, toB) => {
from = Math.min(from, fromB)
to = Math.max(to, toB)
})
}
return from == 1e9 ? null : {from, to}
}
/// @internal
addStep(step: Step, doc: Node) {
this.docs.push(this.doc)
@@ -206,7 +225,7 @@ export class Transform {
if (mark instanceof Mark) {
if (mark.isInSet(node.marks)) this.step(new RemoveNodeMarkStep(pos, mark))
} else {
let set = node.marks, found, steps: Step[] = []
let set = node.marks, found: Mark | undefined, steps: Step[] = []
while (found = mark.isInSet(set)) {
steps.push(new RemoveNodeMarkStep(pos, found))
set = found.removeFromSet(set)