Position the cursor at the beginning of the next block when a block is deleted

This also changes the behavior when blocks are moved.
Add tests for the deleteBlock command.
This commit is contained in:
Jonatan Heyman
2025-01-09 14:04:02 +01:00
parent 03ec7a4867
commit 52a6c444eb
5 changed files with 127 additions and 8 deletions

View File

@ -0,0 +1,44 @@
import {expect, test} from "@playwright/test";
import {HeynotePage} from "./test-utils.js";
import { AUTO_SAVE_INTERVAL } from "../src/common/constants.js"
import { NoteFormat } from "../src/common/note-format.js"
let heynotePage
test.beforeEach(async ({page}) => {
heynotePage = new HeynotePage(page)
await heynotePage.goto()
expect((await heynotePage.getBlocks()).length).toBe(1)
await heynotePage.setContent(`
∞∞∞text
Block A
∞∞∞markdown
Block B
∞∞∞text
Block C`)
await page.waitForTimeout(100)
})
test("delete first block", async ({page}) => {
await heynotePage.setCursorPosition(10)
await page.locator("body").press(heynotePage.agnosticKey("Mod+Shift+D"))
await page.waitForTimeout(50)
expect(await heynotePage.getCursorPosition()).toBe(13)
})
test("delete middle block", async ({page}) => {
await heynotePage.setCursorPosition(32)
await page.locator("body").press(heynotePage.agnosticKey("Mod+Shift+D"))
await page.waitForTimeout(50)
expect(await heynotePage.getCursorPosition()).toBe(25)
})
test("delete last block", async ({page}) => {
await heynotePage.setCursorPosition(52)
await page.locator("body").press(heynotePage.agnosticKey("Mod+Shift+D"))
await page.waitForTimeout(50)
expect(await heynotePage.getCursorPosition()).toBe(36)
})