Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix: Fix undo/redo while action menu is open #6273

Merged
merged 5 commits into from
Aug 15, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
59 changes: 59 additions & 0 deletions e2e-tests/editor.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,65 @@ test('copy and paste block after editing new block #5962', async ({ page, block
await expect(page.locator('text="Typed block"')).toHaveCount(1);
})

test('undo and redo after starting an action should not destroy text #6267', async ({ page, block }) => {
await createRandomPage(page)

// Get one piece of undo state onto the stack
await block.mustFill('text1 ')
await page.waitForTimeout(550) // Wait for 500ms autosave period to expire

// Then type more, start an action prompt, and undo
await page.keyboard.type('text2 ')
for (const char of '[[') {
await page.keyboard.type(char)
}
await expect(page.locator(`[data-modal-name="page-search"]`)).toBeVisible()
if (IsMac) {
await page.keyboard.press('Meta+z')
} else {
await page.keyboard.press('Control+z')
}
await page.waitForTimeout(100)

// Should close the action menu when we undo the action prompt
await expect(page.locator(`[data-modal-name="page-search"]`)).not.toBeVisible()

// It should undo to the last saved state, and not erase the previous undo action too
await expect(page.locator('text="text1"')).toHaveCount(1)

// And it should keep what was undone as a redo action
if (IsMac) {
await page.keyboard.press('Meta+Shift+z')
} else {
await page.keyboard.press('Control+Shift+z')
}
await expect(page.locator('text="text2"')).toHaveCount(1)
})

test('undo after starting an action should close the action menu #6269', async ({ page, block }) => {
for (const [commandTrigger, modalName] of [['/', 'commands'], ['[[', 'page-search']]) {
await createRandomPage(page)

// Open the action modal
await block.mustType('text1 ')
await page.waitForTimeout(550)
for (const char of commandTrigger) {
await page.keyboard.type(char)
}
await expect(page.locator(`[data-modal-name="${modalName}"]`)).toBeVisible()

// Undo, removing "/today", and closing the action modal
if (IsMac) {
await page.keyboard.press('Meta+z')
} else {
await page.keyboard.press('Control+z')
}
await page.waitForTimeout(100)
await expect(page.locator('text="/today"')).toHaveCount(0)
await expect(page.locator(`[data-modal-name="${modalName}"]`)).not.toBeVisible()
}
})

test('#6266 moving cursor outside of brackets should close autocomplete menu', async ({ page, block, autocompleteMenu }) => {
for (const [commandTrigger, modalName] of [['[[', 'page-search'], ['((', 'block-search']]) {
// First, left arrow
Expand Down
2 changes: 2 additions & 0 deletions src/main/frontend/handler/history.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
[e]
(util/stop e)
(state/set-editor-op! :undo)
(state/clear-editor-action!)
(editor/save-current-block!)
(let [{:keys [editor-cursor]} (undo-redo/undo)]
(restore-cursor! editor-cursor))
Expand All @@ -30,6 +31,7 @@
[e]
(util/stop e)
(state/set-editor-op! :redo)
(state/clear-editor-action!)
(let [{:keys [editor-cursor]} (undo-redo/redo)]
(restore-cursor! editor-cursor))
(state/set-editor-op! nil))