@inshapardaz/likhari-react 0.1.18-dev.148 → 0.1.18-dev.150

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.
@@ -39,13 +39,17 @@ export declare function $deletePoetryCouplet(): boolean;
39
39
  */
40
40
  export declare function $deletePoetryOnBackspace(): boolean;
41
41
  /**
42
- * Enter at the end of a couplet's last misra would otherwise land inside
43
- * ParagraphNode's own insertNewAfter — which inserts the new paragraph as a
44
- * sibling of the misra, i.e. still inside the couplet (or, for two-column,
45
- * inside its LayoutItemNode) — trapping the caret with no way to add a line
46
- * after the block. Handled here instead: a plain paragraph after the whole
47
- * couplet, focused. Returns false (let normal Enter handling proceed) for
48
- * every other caret position, including earlier in the couplet.
42
+ * A couplet is always exactly two misras — Enter must never grow it past
43
+ * that. Pressed anywhere in the first misra, Enter moves the caret to the
44
+ * second (the line already exists; nothing is inserted). Pressed anywhere
45
+ * in the second (the last), Enter exits: ParagraphNode's own
46
+ * insertNewAfter would otherwise insert the new paragraph as a sibling of
47
+ * the misra — i.e. still inside the couplet, growing it to three lines
48
+ * and, on the next Enter, four, and so on — so that's handled here
49
+ * instead, reusing or creating a plain paragraph after the whole couplet.
50
+ * Intercepts Enter at *any* caret position inside the couplet (not just
51
+ * at an edge) specifically to prevent that growth; returns false only
52
+ * when the selection isn't inside a couplet at all.
49
53
  */
50
54
  export declare function $exitPoetryOnEnter(): boolean;
51
55
  //# sourceMappingURL=poetryActions.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"poetryActions.d.ts","sourceRoot":"","sources":["../../src/blocks/poetryActions.ts"],"names":[],"mappings":"AACA,OAAO,EAA4F,KAAK,aAAa,EAAE,MAAM,SAAS,CAAC;AAEvI,OAAO,EAA8C,KAAK,WAAW,EAAE,KAAK,YAAY,EAAE,KAAK,eAAe,EAAE,MAAM,cAAc,CAAC;AAErI;wCACwC;AACxC,wBAAgB,mBAAmB,CAAC,IAAI,EAAE,eAAe,GAAG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BtF;AAED;;oEAEoE;AACpE,wBAAgB,oBAAoB,IAAI,OAAO,CAK9C;AAED;;;;;;;;GAQG;AACH,wBAAgB,wBAAwB,IAAI,OAAO,CAoBlD;AAED;;;;;;;;;;;;GAYG;AACH,wBAAgB,kBAAkB,IAAI,OAAO,CAyB5C"}
@@ -134,13 +134,17 @@ export function $deletePoetryOnBackspace() {
134
134
  return true;
135
135
  }
136
136
  /**
137
- * Enter at the end of a couplet's last misra would otherwise land inside
138
- * ParagraphNode's own insertNewAfter — which inserts the new paragraph as a
139
- * sibling of the misra, i.e. still inside the couplet (or, for two-column,
140
- * inside its LayoutItemNode) — trapping the caret with no way to add a line
141
- * after the block. Handled here instead: a plain paragraph after the whole
142
- * couplet, focused. Returns false (let normal Enter handling proceed) for
143
- * every other caret position, including earlier in the couplet.
137
+ * A couplet is always exactly two misras — Enter must never grow it past
138
+ * that. Pressed anywhere in the first misra, Enter moves the caret to the
139
+ * second (the line already exists; nothing is inserted). Pressed anywhere
140
+ * in the second (the last), Enter exits: ParagraphNode's own
141
+ * insertNewAfter would otherwise insert the new paragraph as a sibling of
142
+ * the misra — i.e. still inside the couplet, growing it to three lines
143
+ * and, on the next Enter, four, and so on — so that's handled here
144
+ * instead, reusing or creating a plain paragraph after the whole couplet.
145
+ * Intercepts Enter at *any* caret position inside the couplet (not just
146
+ * at an edge) specifically to prevent that growth; returns false only
147
+ * when the selection isn't inside a couplet at all.
144
148
  */
145
149
  export function $exitPoetryOnEnter() {
146
150
  const selection = $getSelection();
@@ -150,16 +154,16 @@ export function $exitPoetryOnEnter() {
150
154
  if (!couplet)
151
155
  return false;
152
156
  const misras = $getMisraParagraphs(couplet);
153
- const lastMisra = misras[misras.length - 1];
154
- if (!lastMisra)
155
- return false;
156
- const anchor = selection.anchor;
157
- const lastDesc = lastMisra.getLastDescendant();
158
- const isAtEnd = lastDesc ? anchor.key === lastDesc.getKey() && anchor.offset === lastDesc.getTextContentSize() : anchor.key === lastMisra.getKey();
159
- if (!isAtEnd)
160
- return false;
161
- // $ensureTrailingParagraph already guarantees one after every couplet —
162
- // reuse it rather than stacking a new empty paragraph on repeated Enters.
157
+ const anchorNode = selection.anchor.getNode();
158
+ const misraIndex = misras.findIndex((m) => m.getKey() === anchorNode.getKey() || m.isParentOf(anchorNode));
159
+ if (misraIndex !== -1 && misraIndex < misras.length - 1) {
160
+ misras[misraIndex + 1].selectEnd();
161
+ return true;
162
+ }
163
+ // On the last misra (or misraIndex === -1, e.g. the caret landed on the
164
+ // couplet's shadow-root boundary itself) — exit. $ensureTrailingParagraph
165
+ // already guarantees a paragraph after every couplet; reuse it rather
166
+ // than stacking a new empty one on repeated Enters.
163
167
  const existing = couplet.getNextSibling();
164
168
  const paragraph = $isParagraphNode(existing) ? existing : $createParagraphNode();
165
169
  if (paragraph !== existing)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@inshapardaz/likhari-react",
3
- "version": "0.1.18-dev.148",
3
+ "version": "0.1.18-dev.150",
4
4
  "description": "React implementation of the Likhari editor, built on @lexical/react.",
5
5
  "license": "MIT",
6
6
  "repository": {