prosemirror-transform 1.3.4 → 1.4.0
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/CHANGELOG.md +6 -0
- package/dist/index.es.js +13 -5
- package/dist/index.es.js.map +1 -1
- package/dist/index.js +13 -5
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
- package/src/map.js +2 -0
- package/src/replace.js +11 -5
package/package.json
CHANGED
package/src/map.js
CHANGED
package/src/replace.js
CHANGED
|
@@ -335,6 +335,10 @@ function invalidMarks(type, fragment, start) {
|
|
|
335
335
|
return false
|
|
336
336
|
}
|
|
337
337
|
|
|
338
|
+
function definesContent(type) {
|
|
339
|
+
return type.spec.defining || type.spec.definingForContent
|
|
340
|
+
}
|
|
341
|
+
|
|
338
342
|
// :: (number, number, Slice) → this
|
|
339
343
|
// Replace a range of the document with a given slice, using `from`,
|
|
340
344
|
// `to`, and the slice's [`openStart`](#model.Slice.openStart) property
|
|
@@ -342,9 +346,9 @@ function invalidMarks(type, fragment, start) {
|
|
|
342
346
|
// grow the replaced area or close open nodes in the slice in order to
|
|
343
347
|
// get a fit that is more in line with WYSIWYG expectations, by
|
|
344
348
|
// dropping fully covered parent nodes of the replaced region when
|
|
345
|
-
// they are marked [non-defining](#model.NodeSpec.
|
|
349
|
+
// they are marked [non-defining as context](#model.NodeSpec.definingAsContext), or
|
|
346
350
|
// including an open parent node from the slice that _is_ marked as
|
|
347
|
-
// [defining](#model.NodeSpec.
|
|
351
|
+
// [defining its content](#model.NodeSpec.definingForContent).
|
|
348
352
|
//
|
|
349
353
|
// This is the method, for example, to handle paste. The similar
|
|
350
354
|
// [`replace`](#transform.Transform.replace) method is a more
|
|
@@ -371,7 +375,7 @@ Transform.prototype.replaceRange = function(from, to, slice) {
|
|
|
371
375
|
// cross a defining node.
|
|
372
376
|
for (let d = $from.depth, pos = $from.pos - 1; d > 0; d--, pos--) {
|
|
373
377
|
let spec = $from.node(d).type.spec
|
|
374
|
-
if (spec.defining || spec.isolating) break
|
|
378
|
+
if (spec.defining || spec.definingAsContext || spec.isolating) break
|
|
375
379
|
if (targetDepths.indexOf(d) > -1) preferredTarget = d
|
|
376
380
|
else if ($from.before(d) == pos) targetDepths.splice(1, 0, -d)
|
|
377
381
|
}
|
|
@@ -388,10 +392,12 @@ Transform.prototype.replaceRange = function(from, to, slice) {
|
|
|
388
392
|
}
|
|
389
393
|
// Back up if the node directly above openStart, or the node above
|
|
390
394
|
// that separated only by a non-defining textblock node, is defining.
|
|
391
|
-
if (preferredDepth > 0 && leftNodes[preferredDepth - 1].type
|
|
395
|
+
if (preferredDepth > 0 && definesContent(leftNodes[preferredDepth - 1].type) &&
|
|
392
396
|
$from.node(preferredTargetIndex).type != leftNodes[preferredDepth - 1].type)
|
|
393
397
|
preferredDepth -= 1
|
|
394
|
-
else if (preferredDepth >= 2 &&
|
|
398
|
+
else if (preferredDepth >= 2 &&
|
|
399
|
+
leftNodes[preferredDepth - 1].isTextblock &&
|
|
400
|
+
definesContent(leftNodes[preferredDepth - 2].type) &&
|
|
395
401
|
$from.node(preferredTargetIndex).type != leftNodes[preferredDepth - 2].type)
|
|
396
402
|
preferredDepth -= 2
|
|
397
403
|
|