Skip to content

Commit 351fd02

Browse files
committed
fix(files): cancel renaming on enter if no file name changes
Signed-off-by: skjnldsv <skjnldsv@protonmail.com>
1 parent ad045d6 commit 351fd02

File tree

2 files changed

+43
-0
lines changed

2 files changed

+43
-0
lines changed

apps/files/src/components/FileEntry/FileEntryName.vue

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -241,6 +241,10 @@ export default defineComponent({
241241
}
242242
243243
const oldName = this.source.basename
244+
if (newName === oldName) {
245+
this.stopRenaming()
246+
return
247+
}
244248
245249
try {
246250
const status = await this.renamingStore.rename()

cypress/e2e/files/files-renaming.cy.ts

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,4 +143,43 @@ describe('files: Rename nodes', { testIsolation: true }, () => {
143143
.findByRole('textbox', { name: 'Filename' })
144144
.should('not.exist')
145145
})
146+
147+
it('cancel renaming on esc press', () => {
148+
// All are visible by default
149+
getRowForFile('file.txt').should('be.visible')
150+
151+
triggerActionForFile('file.txt', 'rename')
152+
153+
getRowForFile('file.txt')
154+
.findByRole('textbox', { name: 'Filename' })
155+
.should('be.visible')
156+
.type('{selectAll}other.txt')
157+
.should(haveValidity(''))
158+
.type('{esc}')
159+
160+
// See it is not renamed
161+
getRowForFile('other.txt').should('not.exist')
162+
getRowForFile('file.txt')
163+
.should('be.visible')
164+
.find('input[type="text"]')
165+
.should('not.exist')
166+
})
167+
168+
it('cancel on enter if no new name is entered', () => {
169+
// All are visible by default
170+
getRowForFile('file.txt').should('be.visible')
171+
172+
triggerActionForFile('file.txt', 'rename')
173+
174+
getRowForFile('file.txt')
175+
.findByRole('textbox', { name: 'Filename' })
176+
.should('be.visible')
177+
.type('{enter}')
178+
179+
// See it is not renamed
180+
getRowForFile('file.txt')
181+
.should('be.visible')
182+
.find('input[type="text"]')
183+
.should('not.exist')
184+
})
146185
})

0 commit comments

Comments
 (0)