@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.js CHANGED
@@ -949,6 +949,8 @@ function changeBlockType(blocks, id, newType) {
949
949
  if (newType === "PARENTHETICAL") {
950
950
  const cleanText = currentBlock.text.replace(/[()]/g, "");
951
951
  newBlock.text = `(${cleanText})`;
952
+ } else if (currentBlock.type === "PARENTHETICAL") {
953
+ newBlock.text = currentBlock.text.replace(/[()]/g, "");
952
954
  } else {
953
955
  newBlock.text = currentBlock.text;
954
956
  }
@@ -1326,12 +1328,18 @@ function useScreenplayEditor(options) {
1326
1328
  setTimeout(() => {
1327
1329
  const el = refs.current[focusedBlockId];
1328
1330
  if (el) {
1329
- el.focus();
1330
- const currentBlock = blocks.find((b) => b.id === focusedBlockId);
1331
- if (currentBlock) {
1331
+ setBlocks((currentBlocks) => {
1332
+ const currentBlock = currentBlocks.find(
1333
+ (b) => b.id === focusedBlockId
1334
+ );
1335
+ if (currentBlock && el.innerText !== currentBlock.text) {
1336
+ el.innerText = currentBlock.text;
1337
+ }
1338
+ el.focus();
1332
1339
  const pos = newType === "PARENTHETICAL" ? el.innerText.length - 1 : el.innerText.length;
1333
1340
  setCaretPosition(el, Math.max(0, pos));
1334
- }
1341
+ return currentBlocks;
1342
+ });
1335
1343
  }
1336
1344
  }, 10);
1337
1345
  },
@@ -1390,12 +1398,19 @@ function useScreenplayEditor(options) {
1390
1398
  setTimeout(() => {
1391
1399
  const el = refs.current[id];
1392
1400
  if (el) {
1393
- el.focus();
1394
- if (newType === "PARENTHETICAL") {
1395
- setCaretPosition(el, 1);
1396
- } else {
1397
- setCaretPosition(el, el.innerText.length);
1398
- }
1401
+ setBlocks((currentBlocks) => {
1402
+ const currentBlock = currentBlocks.find((b) => b.id === id);
1403
+ if (currentBlock && el.innerText !== currentBlock.text) {
1404
+ el.innerText = currentBlock.text;
1405
+ }
1406
+ el.focus();
1407
+ if (newType === "PARENTHETICAL") {
1408
+ setCaretPosition(el, 1);
1409
+ } else {
1410
+ setCaretPosition(el, el.innerText.length);
1411
+ }
1412
+ return currentBlocks;
1413
+ });
1399
1414
  }
1400
1415
  }, 10);
1401
1416
  };