@sofereditor/core 0.5.0 → 0.6.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/dist/index.cjs CHANGED
@@ -1317,6 +1317,34 @@ function insertSlice(ctx, slice) {
1317
1317
  const tailDelta = sliceDelta(full, offset, deltaLength(full));
1318
1318
  targetText.delete(offset, targetText.length - offset);
1319
1319
  const blocks = slice.blocks;
1320
+ if (blocks.length === 1 && slice.blockLevel) {
1321
+ const originalType2 = ctx.doc.getBlockType(blockIndex);
1322
+ const originalAttrs2 = ctx.doc.getBlockAttrs(blockIndex);
1323
+ let hostIndex = blockIndex;
1324
+ if (offset === 0) {
1325
+ const blk = ctx.doc.blocks.get(blockIndex);
1326
+ blk.set("type", blocks[0].type);
1327
+ const am = blk.get("attrs");
1328
+ am.clear();
1329
+ for (const [k, v] of Object.entries(blocks[0].attrs)) {
1330
+ if (v !== void 0) am.set(k, v);
1331
+ }
1332
+ writeDeltaInto(targetText, 0, blocks[0].delta);
1333
+ } else {
1334
+ hostIndex = blockIndex + 1;
1335
+ const b = createBlock(blocks[0].type, "", blocks[0].attrs);
1336
+ ctx.doc.blocks.insert(hostIndex, [b]);
1337
+ writeDeltaInto(b.get("text"), 0, blocks[0].delta);
1338
+ }
1339
+ const caretPos = ctx.doc.getBlockText(hostIndex).length;
1340
+ if (tailDelta.length > 0) {
1341
+ const tb = createBlock(originalType2 ?? "paragraph", "", originalAttrs2);
1342
+ ctx.doc.blocks.insert(hostIndex + 1, [tb]);
1343
+ writeDeltaInto(tb.get("text"), 0, tailDelta);
1344
+ }
1345
+ ctx.setSelection(collapsedSelection({ blockIndex: hostIndex, offset: caretPos }));
1346
+ return;
1347
+ }
1320
1348
  if (blocks.length === 1) {
1321
1349
  const afterS0 = writeDeltaInto(targetText, offset, blocks[0].delta);
1322
1350
  writeDeltaInto(targetText, afterS0, tailDelta);