Skip to content

Commit b9508b6

Browse files
committed
platform: trailing space on reference when inserting note
- added trailing space back in on `fr` and `xo`
1 parent af30790 commit b9508b6

File tree

4 files changed

+27
-10
lines changed

4 files changed

+27
-10
lines changed

libs/shared-react/src/nodes/usj/node-react-utils.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -539,7 +539,7 @@ describe("$insertNote()", () => {
539539

540540
// First should be fr with chapter:verse
541541
expect(charNodes[0].getMarker()).toBe("fr");
542-
expect(charNodes[0].getTextContent()).toBe("1:5");
542+
expect(charNodes[0].getTextContent()).toBe("1:5 ");
543543

544544
// Last should be ft with placeholder
545545
const ftNode = charNodes.find((node) => node.getMarker() === "ft");
@@ -624,7 +624,7 @@ describe("$insertNote()", () => {
624624

625625
const xoNode = charNodes.find((node) => node.getMarker() === "xo");
626626
expect(xoNode).toBeDefined();
627-
expect(xoNode?.getTextContent()).toBe("3:16");
627+
expect(xoNode?.getTextContent()).toBe("3:16 ");
628628

629629
const xtNode = charNodes.find((node) => node.getMarker() === "xt");
630630
expect(xtNode).toBeDefined();

libs/shared-react/src/nodes/usj/node-react.utils.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,7 @@ export function $createNoteChildren(
188188
case "ef":
189189
case "efe":
190190
if (chapterNum !== undefined && verseNum !== undefined) {
191-
children.push($createCharNode("fr").append($createTextNode(`${chapterNum}:${verseNum}`)));
191+
children.push($createCharNode("fr").append($createTextNode(`${chapterNum}:${verseNum} `)));
192192
}
193193
if (!selection.isCollapsed()) {
194194
const selectedText = selection.getTextContent().trim();
@@ -202,7 +202,7 @@ export function $createNoteChildren(
202202
case "x":
203203
case "ex":
204204
if (chapterNum !== undefined && verseNum !== undefined) {
205-
children.push($createCharNode("xo").append($createTextNode(`${chapterNum}:${verseNum}`)));
205+
children.push($createCharNode("xo").append($createTextNode(`${chapterNum}:${verseNum} `)));
206206
}
207207
if (!selection.isCollapsed()) {
208208
const selectedText = selection.getTextContent().trim();

packages/platform/src/editor/adaptors/usj-marker-action-utils.test.ts

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -236,22 +236,30 @@ describe("USJ Marker Action Utils", () => {
236236
});
237237

238238
describe("should insert a note", () => {
239+
const referenceCVText = `${reference.chapterNum}:${reference.verseNum} `;
240+
239241
it("of type footnote", () => {
240242
const { editor } = createBasicTestEnvironment(nodes, $defaultInitialEditorState);
241243
const markerAction = getUsjMarkerAction("f", expandedNoteKeyRef, undefined, undefined, {
242244
discrete: true,
243245
});
246+
// caret after the word "second"
244247
updateSelection(editor, secondVerseTextNode, 6);
245248

246249
markerAction.action({ editor, reference });
247250

248251
editor.getEditorState().read(() => {
249252
expect(secondVerseTextNode.getTextContent()).toBe("second");
250253
const insertedNode = secondVerseTextNode.getNextSibling();
251-
if (!$isNoteNode(insertedNode)) throw new Error("Inserted node is not a note");
254+
if (!$isNoteNode(insertedNode)) throw new Error("Expected a NoteNode");
252255
expect(insertedNode.getMarker()).toBe("f");
256+
257+
const frChar = insertedNode.getChildAtIndex(2);
258+
if (!$isCharNode(frChar)) throw new Error("Expected a CharNode");
259+
expect(frChar.getTextContent()).toBe(referenceCVText);
260+
253261
const tailTextNode = insertedNode.getNextSibling();
254-
if (!$isTextNode(tailTextNode)) throw new Error("Tail node is not text");
262+
if (!$isTextNode(tailTextNode)) throw new Error("Expected a TextNode");
255263
expect(tailTextNode.getTextContent()).toBe(" verse text ");
256264
});
257265
});
@@ -261,6 +269,7 @@ describe("USJ Marker Action Utils", () => {
261269
const markerAction = getUsjMarkerAction("fe", expandedNoteKeyRef, undefined, undefined, {
262270
discrete: true,
263271
});
272+
// caret after the word "second"
264273
updateSelection(editor, secondVerseTextNode, 6);
265274

266275
markerAction.action({ editor, reference });
@@ -281,6 +290,7 @@ describe("USJ Marker Action Utils", () => {
281290
const markerAction = getUsjMarkerAction("ef", expandedNoteKeyRef, undefined, undefined, {
282291
discrete: true,
283292
});
293+
// caret after the word "second"
284294
updateSelection(editor, secondVerseTextNode, 6);
285295

286296
markerAction.action({ editor, reference });
@@ -301,17 +311,23 @@ describe("USJ Marker Action Utils", () => {
301311
const markerAction = getUsjMarkerAction("x", expandedNoteKeyRef, undefined, undefined, {
302312
discrete: true,
303313
});
314+
// caret after the word "second"
304315
updateSelection(editor, secondVerseTextNode, 6);
305316

306317
markerAction.action({ editor, reference });
307318

308319
editor.getEditorState().read(() => {
309320
expect(secondVerseTextNode.getTextContent()).toBe("second");
310321
const insertedNode = secondVerseTextNode.getNextSibling();
311-
if (!$isNoteNode(insertedNode)) throw new Error("Inserted node is not a note");
322+
if (!$isNoteNode(insertedNode)) throw new Error("Expected a NoteNode");
312323
expect(insertedNode.getMarker()).toBe("x");
324+
325+
const xoChar = insertedNode.getChildAtIndex(2);
326+
if (!$isCharNode(xoChar)) throw new Error("Expected a CharNode");
327+
expect(xoChar.getTextContent()).toBe(referenceCVText);
328+
313329
const tailTextNode = insertedNode.getNextSibling();
314-
if (!$isTextNode(tailTextNode)) throw new Error("Tail node is not text");
330+
if (!$isTextNode(tailTextNode)) throw new Error("Expected a TextNode");
315331
expect(tailTextNode.getTextContent()).toBe(" verse text ");
316332
});
317333
});
@@ -321,6 +337,7 @@ describe("USJ Marker Action Utils", () => {
321337
const markerAction = getUsjMarkerAction("ex", expandedNoteKeyRef, undefined, undefined, {
322338
discrete: true,
323339
});
340+
// caret after the word "second"
324341
updateSelection(editor, secondVerseTextNode, 6);
325342

326343
markerAction.action({ editor, reference });

packages/platform/src/editor/adaptors/usj-marker-action.utils.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ const getFootnoteMarkerAction: (footnoteMarker: string) => UsjMarkerAction = (fo
6565
noteChildren.push({
6666
type: "char",
6767
marker: "fr",
68-
content: [`${chapterNum}:${verseNum}`],
68+
content: [`${chapterNum}:${verseNum} `],
6969
});
7070
if (currentEditor.noteText)
7171
noteChildren.push({
@@ -101,7 +101,7 @@ const getCrossReferenceMarkerAction: (crossReferenceMarker: string) => UsjMarker
101101
noteChildren.push({
102102
type: "char",
103103
marker: "xo",
104-
content: [`${chapterNum}:${verseNum}`],
104+
content: [`${chapterNum}:${verseNum} `],
105105
});
106106
if (currentEditor.noteText)
107107
noteChildren.push({

0 commit comments

Comments
 (0)