mirror of
https://github.com/heyman/heynote.git
synced 2025-07-23 08:15:42 +02:00
This is a work in progress revamp of the key binding system. It implements a system, built on top of CodeMirror's key binding system, for defining key bindings. The system uses a dumb "KeyShortcut" -> "Command" mapping with a set of default keys (which will be different if Heynote's Emacs mode is used) that can be overridden by user key bindings. The key bindings are *displayed* in the Settings, and it's possible to set user defined key bindings in Heynote's config file, but it's not yet possible to define custom key bindings in the UI. Previously we Heynote on a bunch of default key bindings from CodeMirror (some of which was not "block aware"). This is no longer the case, and because of this, it's quite likely that there are key bindings that was previously working that is now missing (if so, these can easily be added later).
99 lines
3.6 KiB
JavaScript
99 lines
3.6 KiB
JavaScript
import { test, expect } from "@playwright/test";
|
|
import { HeynotePage } from "./test-utils.js";
|
|
|
|
let heynotePage, modifierKey
|
|
|
|
test.beforeEach(async ({ page, browserName }) => {
|
|
heynotePage = new HeynotePage(page)
|
|
await heynotePage.goto()
|
|
modifierKey = heynotePage.isMac ? "Meta" : "Control"
|
|
|
|
if (browserName !== "chromium") {
|
|
// This test only works in Chromium due to accessing the clipboard
|
|
test.skip()
|
|
}
|
|
await page.locator("css=.status-block.settings").click()
|
|
await page.locator("css=li.tab-keyboard-bindings").click()
|
|
//await page.locator("css=li.tab-editing").click()
|
|
await page.locator("css=select.keymap").selectOption("emacs")
|
|
if (heynotePage.isMac) {
|
|
await page.locator("css=select.metaKey").selectOption("alt")
|
|
}
|
|
await page.locator("body").press("Escape")
|
|
});
|
|
|
|
async function clearBuffer() {
|
|
await heynotePage.setContent(`
|
|
∞∞∞text
|
|
`)
|
|
}
|
|
|
|
|
|
test("test emacs copy/pase/cut key bindings", async ({ page }) => {
|
|
await page.locator("body").pressSequentially("test")
|
|
await page.locator("body").press("Control+Space")
|
|
await page.locator("body").press("Control+A")
|
|
await page.locator("body").press("Alt+W")
|
|
expect(await heynotePage.getBlockContent(0)).toBe("test")
|
|
await page.locator("body").press("Control+Y")
|
|
expect(await heynotePage.getBlockContent(0)).toBe("testtest")
|
|
|
|
await page.locator("body").press("Control+E")
|
|
await page.locator("body").press("Control+Space")
|
|
await page.locator("body").press("Control+A")
|
|
await page.locator("body").press("Control+W")
|
|
expect(await heynotePage.getBlockContent(0)).toBe("")
|
|
await page.locator("body").press("Control+Y")
|
|
await page.locator("body").press("Control+Y")
|
|
expect(await heynotePage.getBlockContent(0)).toBe("testtesttesttest")
|
|
})
|
|
|
|
|
|
// The following tests doesn't really test anything specific to the Emacs key bindings, but triggering
|
|
// Copy/Paste by keyboard shortcuts is not possible in Playwright, so we test this functionality using
|
|
// the Emacs key bindings
|
|
|
|
test("copy current line", async ({ page }) => {
|
|
await page.locator("body").pressSequentially("test line! ")
|
|
await page.keyboard.press("Alt+W")
|
|
await page.keyboard.press("Alt+W")
|
|
await clearBuffer()
|
|
expect(await heynotePage.getBlockContent(0)).toBe("")
|
|
await page.locator("body").press("Control+Y")
|
|
await page.locator("body").press("Control+Y")
|
|
expect(await heynotePage.getBlockContent(0)).toBe("test line! test line! ")
|
|
})
|
|
|
|
test("copy current multiple cursors", async ({ page }) => {
|
|
await heynotePage.setContent(`
|
|
∞∞∞text
|
|
line 1
|
|
line 2`)
|
|
await page.keyboard.press("Control+A")
|
|
await page.keyboard.press(`${modifierKey}+Alt+ArrowUp`)
|
|
await page.locator("body").pressSequentially("test")
|
|
await page.keyboard.press("Alt+W")
|
|
await clearBuffer()
|
|
expect(await heynotePage.getBlockContent(0)).toBe("")
|
|
await page.keyboard.press("Control+Y")
|
|
//await page.waitForTimeout(100);
|
|
expect(await heynotePage.getBlockContent(0)).toBe(`testline 1\ntestline 2`)
|
|
})
|
|
|
|
test("copy current multiple cursors on same line", async ({ page }) => {
|
|
await heynotePage.setContent(`
|
|
∞∞∞text
|
|
test`)
|
|
await page.keyboard.press("Control+A")
|
|
await page.keyboard.press(`${modifierKey}+Alt+ArrowDown`)
|
|
await page.locator("body").pressSequentially("1")
|
|
expect(await heynotePage.getBlockContent(0)).toBe("1test1")
|
|
await page.keyboard.press("Alt+W")
|
|
|
|
await clearBuffer()
|
|
expect(await heynotePage.getBlockContent(0)).toBe("")
|
|
|
|
await page.keyboard.press("Control+Y")
|
|
expect(await heynotePage.getBlockContent(0)).toBe("1test1")
|
|
})
|