@vishu1301/script-writing 1.4.8 → 1.4.9

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
@@ -975,6 +975,8 @@ function changeBlockType(blocks, id, newType) {
975
975
  if (newType === "PARENTHETICAL") {
976
976
  const cleanText = currentBlock.text.replace(/[()]/g, "");
977
977
  newBlock.text = `(${cleanText})`;
978
+ } else if (currentBlock.type === "PARENTHETICAL") {
979
+ newBlock.text = currentBlock.text.replace(/[()]/g, "");
978
980
  } else {
979
981
  newBlock.text = currentBlock.text;
980
982
  }
@@ -1352,12 +1354,18 @@ function useScreenplayEditor(options) {
1352
1354
  setTimeout(() => {
1353
1355
  const el = refs.current[focusedBlockId];
1354
1356
  if (el) {
1355
- el.focus();
1356
- const currentBlock = blocks.find((b) => b.id === focusedBlockId);
1357
- if (currentBlock) {
1357
+ setBlocks((currentBlocks) => {
1358
+ const currentBlock = currentBlocks.find(
1359
+ (b) => b.id === focusedBlockId
1360
+ );
1361
+ if (currentBlock && el.innerText !== currentBlock.text) {
1362
+ el.innerText = currentBlock.text;
1363
+ }
1364
+ el.focus();
1358
1365
  const pos = newType === "PARENTHETICAL" ? el.innerText.length - 1 : el.innerText.length;
1359
1366
  setCaretPosition(el, Math.max(0, pos));
1360
- }
1367
+ return currentBlocks;
1368
+ });
1361
1369
  }
1362
1370
  }, 10);
1363
1371
  },
@@ -1416,12 +1424,19 @@ function useScreenplayEditor(options) {
1416
1424
  setTimeout(() => {
1417
1425
  const el = refs.current[id];
1418
1426
  if (el) {
1419
- el.focus();
1420
- if (newType === "PARENTHETICAL") {
1421
- setCaretPosition(el, 1);
1422
- } else {
1423
- setCaretPosition(el, el.innerText.length);
1424
- }
1427
+ setBlocks((currentBlocks) => {
1428
+ const currentBlock = currentBlocks.find((b) => b.id === id);
1429
+ if (currentBlock && el.innerText !== currentBlock.text) {
1430
+ el.innerText = currentBlock.text;
1431
+ }
1432
+ el.focus();
1433
+ if (newType === "PARENTHETICAL") {
1434
+ setCaretPosition(el, 1);
1435
+ } else {
1436
+ setCaretPosition(el, el.innerText.length);
1437
+ }
1438
+ return currentBlocks;
1439
+ });
1425
1440
  }
1426
1441
  }, 10);
1427
1442
  };