mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-07-18 02:26:21 +08:00
fix(editor): prevent cursor jumping to title when pressing backspace on the begin of edgeless note (#12410)
Close [BS-3492](https://linear.app/affine-design/issue/BS-3492/白板上的note,在开头按退格键,光标会到page-block的title上) ### Before https://github.com/user-attachments/assets/334504f2-30f3-4ce2-ba60-a2688a811b53 ### After https://github.com/user-attachments/assets/be26be6c-6cfc-4f69-82b7-1127e0d10a1a <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit - **Bug Fixes** - Improved behavior when deleting a note block to ensure the cursor focus does not incorrectly jump to the page title after pressing backspace. - **Tests** - Added a new test to verify that focus remains within the note block after deletion, preventing unwanted cursor movement to the page title. - Introduced a utility to check if the document title is focused during tests. <!-- end of auto-generated comment: release notes by coderabbit.ai -->
This commit is contained in:
@@ -69,6 +69,14 @@ export function locateDocTitle(page: Page, editorIndex = 0) {
|
||||
return locateEditorContainer(page, editorIndex).locator('doc-title');
|
||||
}
|
||||
|
||||
export function isDocTitleFocused(page: Page, editorIndex = 0) {
|
||||
return locateDocTitle(page, editorIndex)
|
||||
.locator('.inline-editor')
|
||||
.evaluate(inlineEditor => {
|
||||
return document.activeElement === inlineEditor;
|
||||
});
|
||||
}
|
||||
|
||||
export async function focusDocTitle(page: Page, editorIndex = 0) {
|
||||
await locateDocTitle(page, editorIndex).locator('.inline-editor').focus();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user