Skip to content

Commit a0b71f2

Browse files
authored
Merge pull request #370 from DisciplinedSoftware/fix/esc-exits-edit-and-selects-node
fix: pressing ESC while editing a node exits edit and selects the node
2 parents 2eb9181 + 75df18b commit a0b71f2

2 files changed

Lines changed: 17 additions & 0 deletions

File tree

src/utils/dom.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -210,6 +210,11 @@ export const editTopic = function (this: MindElixirInstance, el: Topic) {
210210
e.preventDefault()
211211
div.blur()
212212
this.container.focus()
213+
} else if (key === 'Escape') {
214+
e.preventDefault()
215+
div.textContent = originalContent // Discard edits
216+
div.blur()
217+
this.container.focus()
213218
}
214219
})
215220

tests/interaction.spec.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,18 @@ test('Clear and reset', async ({ page, me }) => {
4646
await me.toHaveScreenshot()
4747
})
4848

49+
test('ESC cancels edit and discards changes', async ({ page, me }) => {
50+
await me.dblclick(topic)
51+
await expect(page.locator('#input-box')).toBeVisible()
52+
await page.keyboard.insertText('changes to discard')
53+
await page.keyboard.press('Escape')
54+
await expect(page.locator('#input-box')).toBeHidden()
55+
// Original topic text is preserved
56+
await expect(page.getByText(topic)).toBeVisible()
57+
// Node should remain selected
58+
await expect(page.locator('.selected')).toHaveText(topic)
59+
})
60+
4961
test('Remove Node', async ({ page, me }) => {
5062
await me.click(childTopic)
5163
await page.keyboard.press('Delete')

0 commit comments

Comments
 (0)