Skip to content

Commit e8621df

Browse files
jkcsmatthewlipski
andauthored
fix: Unexpected getSelection (#1030)
* fix: Unexpected getSelection * clear * Updated test * Fixed tests --------- Co-authored-by: matthewlipski <[email protected]>
1 parent 5700f90 commit e8621df

File tree

2 files changed

+14
-4
lines changed

2 files changed

+14
-4
lines changed

packages/core/src/editor/BlockNoteEditor.ts

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -724,9 +724,16 @@ export class BlockNoteEditor<
724724
return true;
725725
}
726726

727+
// Fixed the block pos and size
728+
// all block is wrapped with a blockContent wrapper
729+
// and blockContent wrapper pos = inner block pos - 1
730+
// blockContent wrapper end = inner block pos + nodeSize + 1
731+
// need to add 1 to start and -1 to end
732+
const end = pos + node.nodeSize - 1;
733+
const start = pos + 1;
727734
if (
728-
pos + node.nodeSize < this._tiptapEditor.state.selection.from ||
729-
pos > this._tiptapEditor.state.selection.to
735+
end <= this._tiptapEditor.state.selection.from ||
736+
start >= this._tiptapEditor.state.selection.to
730737
) {
731738
return true;
732739
}

tests/src/end-to-end/textalignment/textAlignment.test.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ test.describe("Check Text Alignment Functionality", () => {
2121
await page.keyboard.press("ArrowUp");
2222
await page.keyboard.press("ArrowUp");
2323
await page.keyboard.press("Control+ArrowLeft");
24-
await page.keyboard.press("Control+Shift+ArrowRight");
24+
await page.keyboard.press("Control+Shift+ArrowDown");
2525

2626
await page.locator(ALIGN_TEXT_RIGHT_BUTTON_SELECTOR).click();
2727
await page.waitForTimeout(350);
@@ -42,10 +42,12 @@ test.describe("Check Text Alignment Functionality", () => {
4242
await insertHeading(page, 2);
4343
await insertHeading(page, 3);
4444

45+
await page.keyboard.press("ArrowUp");
4546
await page.keyboard.press("ArrowUp");
4647
await page.keyboard.press("ArrowUp");
4748
await page.keyboard.press("Control+ArrowLeft");
48-
await page.keyboard.press("Control+Shift+ArrowUp");
49+
await page.keyboard.press("Control+Shift+ArrowDown");
50+
await page.keyboard.press("Control+Shift+ArrowDown");
4951

5052
await page.locator(ALIGN_TEXT_RIGHT_BUTTON_SELECTOR).click();
5153
await page.waitForTimeout(350);
@@ -54,6 +56,7 @@ test.describe("Check Text Alignment Functionality", () => {
5456
// Waits for formatting toolbar animation to finish.
5557
await page.waitForTimeout(500);
5658
await page.keyboard.press("ArrowLeft");
59+
await page.pause();
5760

5861
expect(await page.screenshot()).toMatchSnapshot(
5962
"alignTextMultipleBlocks.png"

0 commit comments

Comments
 (0)