From 0c1325fbc5a96e053d0a5bcd315e087f15191d91 Mon Sep 17 00:00:00 2001 From: Vanessa Date: Mon, 15 Apr 2024 22:12:56 +0800 Subject: [PATCH] :art: fix https://github.com/siyuan-note/siyuan/issues/10958 --- app/src/boot/globalEvent/keydown.ts | 2 ++ app/src/protyle/gutter/index.ts | 6 ++++-- app/src/protyle/header/openTitleMenu.ts | 3 +++ 3 files changed, 9 insertions(+), 2 deletions(-) diff --git a/app/src/boot/globalEvent/keydown.ts b/app/src/boot/globalEvent/keydown.ts index 690957c36..f8d4df7e6 100644 --- a/app/src/boot/globalEvent/keydown.ts +++ b/app/src/boot/globalEvent/keydown.ts @@ -328,6 +328,7 @@ const editKeydown = (app: App, event: KeyboardEvent) => { srcIDs: sourceIds, avID, }]); + focusByRange(range) }); } else { const selectElement: Element[] = []; @@ -362,6 +363,7 @@ const editKeydown = (app: App, event: KeyboardEvent) => { srcIDs: sourceIds, avID, }]); + focusByRange(range) }); } event.preventDefault(); diff --git a/app/src/protyle/gutter/index.ts b/app/src/protyle/gutter/index.ts index 84f368bdf..b0c3e22f8 100644 --- a/app/src/protyle/gutter/index.ts +++ b/app/src/protyle/gutter/index.ts @@ -811,6 +811,7 @@ export class Gutter { }); } }).element); + const range = getSelection().rangeCount > 0 ? getSelection().getRangeAt(0) : undefined window.siyuan.menus.menu.append(new MenuItem({ label: window.siyuan.languages.addToDatabase, accelerator: window.siyuan.config.keymap.general.addToDatabase.custom, @@ -838,7 +839,7 @@ export class Gutter { srcIDs: sourceIds, avID, }]); - focusBlock(selectsElement[0]); + focusByRange(range); }); } }).element); @@ -1278,6 +1279,7 @@ export class Gutter { }); } }).element); + const range = getSelection().rangeCount > 0 ? getSelection().getRangeAt(0) : undefined window.siyuan.menus.menu.append(new MenuItem({ label: window.siyuan.languages.addToDatabase, accelerator: window.siyuan.config.keymap.general.addToDatabase.custom, @@ -1302,7 +1304,7 @@ export class Gutter { srcIDs: sourceIds, avID, }]); - focusBlock(nodeElement); + focusByRange(range); }); } }).element); diff --git a/app/src/protyle/header/openTitleMenu.ts b/app/src/protyle/header/openTitleMenu.ts index e366d1f44..8b16b5edf 100644 --- a/app/src/protyle/header/openTitleMenu.ts +++ b/app/src/protyle/header/openTitleMenu.ts @@ -23,6 +23,7 @@ import {genImportMenu} from "../../menus/navigation"; import {transferBlockRef} from "../../menus/block"; import {openSearchAV} from "../render/av/relation"; import {transaction} from "../wysiwyg/transaction"; +import {focusByRange} from "../util/selection"; export const openTitleMenu = (protyle: IProtyle, position: IPosition) => { hideTooltip(); @@ -44,6 +45,7 @@ export const openTitleMenu = (protyle: IProtyle, position: IPosition) => { }).element); if (!protyle.disabled) { window.siyuan.menus.menu.append(movePathToMenu([protyle.path])); + const range = getSelection().rangeCount > 0 ? getSelection().getRangeAt(0) : undefined window.siyuan.menus.menu.append(new MenuItem({ label: window.siyuan.languages.addToDatabase, accelerator: window.siyuan.config.keymap.general.addToDatabase.custom, @@ -68,6 +70,7 @@ export const openTitleMenu = (protyle: IProtyle, position: IPosition) => { srcIDs: sourceIds, avID, }]); + focusByRange(range); }); } }).element);