diff --git a/src/components/Dialog/DictionaryManageDialog.vue b/src/components/Dialog/DictionaryManageDialog.vue index 3775064df5..40ec440c65 100644 --- a/src/components/Dialog/DictionaryManageDialog.vue +++ b/src/components/Dialog/DictionaryManageDialog.vue @@ -123,6 +123,7 @@ class="word-input" dense :disable="uiLocked" + @focus="clearSurfaceInputSelection()" @blur="setSurface(surface)" @keydown.enter="yomiFocus" > @@ -130,7 +131,11 @@ ref="surfaceContextMenu" :header="surfaceContextMenuHeader" :menudata="surfaceContextMenudata" - @beforeShow="readyForSurfaceContextMenu" + @beforeShow=" + readyForSurfaceContextMenu(); + startSurfaceContextMenuOperation(); + " + @beforeHide="endSurfaceContextMenuOperation()" /> @@ -143,6 +148,7 @@ dense :error="!isOnlyHiraOrKana" :disable="uiLocked" + @focus="clearYomiInputSelection()" @blur="setYomi(yomi)" @keydown.enter="setYomiWhenEnter" > @@ -153,7 +159,11 @@ ref="yomiContextMenu" :header="yomiContextMenuHeader" :menudata="yomiContextMenudata" - @beforeShow="readyForYomiContextMenu" + @beforeShow=" + readyForYomiContextMenu(); + startYomiContextMenuOperation(); + " + @beforeHide="endYomiContextMenuOperation()" /> @@ -687,6 +697,9 @@ const { contextMenuHeader: surfaceContextMenuHeader, contextMenudata: surfaceContextMenudata, readyForContextMenu: readyForSurfaceContextMenu, + clearInputSelection: clearSurfaceInputSelection, + startContextMenuOperation: startSurfaceContextMenuOperation, + endContextMenuOperation: endSurfaceContextMenuOperation, } = useRightClickContextMenu(surfaceInput, surface, ref("surface")); const { @@ -694,6 +707,9 @@ const { contextMenuHeader: yomiContextMenuHeader, contextMenudata: yomiContextMenudata, readyForContextMenu: readyForYomiContextMenu, + clearInputSelection: clearYomiInputSelection, + startContextMenuOperation: startYomiContextMenuOperation, + endContextMenuOperation: endYomiContextMenuOperation, } = useRightClickContextMenu(yomiInput, yomi, ref("yomi")); diff --git a/src/composables/useRightClickContextMenu.ts b/src/composables/useRightClickContextMenu.ts index ab24912136..d3c75e0fd5 100644 --- a/src/composables/useRightClickContextMenu.ts +++ b/src/composables/useRightClickContextMenu.ts @@ -19,6 +19,12 @@ export function useRightClickContextMenu( ) { const inputSelection = new SelectionHelperForQInput(qInputRef); + /** + * コンテキストメニューの開閉によりFocusやBlurが発生する可能性のある間は`true` + * no-focusを付けた場合と付けてない場合でタイミングが異なるため、両方に対応 + */ + const willFocusOrBlur = ref(false); + const contextMenu = ref>(); const contextMenuHeader = ref(""); @@ -70,17 +76,17 @@ export function useRightClickContextMenu( label: "切り取り", onClick: async () => { contextMenu.value?.hide(); - handleCut(); + await handleCut(); }, disableWhenUiLocked: false, }, { type: "button", label: "コピー", - onClick: () => { + onClick: async () => { contextMenu.value?.hide(); if (inputSelection) { - navigator.clipboard.writeText(inputSelection.getAsString()); + await navigator.clipboard.writeText(inputSelection.getAsString()); } }, disableWhenUiLocked: false, @@ -116,7 +122,7 @@ export function useRightClickContextMenu( inputField.value, ); await nextTick(); - navigator.clipboard.writeText(text); + await navigator.clipboard.writeText(text); inputSelection.setCursorPosition(start); }; @@ -148,10 +154,29 @@ export function useRightClickContextMenu( ); }; + const clearInputSelection = () => { + console.log(willFocusOrBlur); + if (!willFocusOrBlur.value) { + inputSelection.toEmpty(); + } + }; + + const startContextMenuOperation = () => { + willFocusOrBlur.value = true; + }; + + const endContextMenuOperation = async () => { + await nextTick(); + willFocusOrBlur.value = false; + }; + return { contextMenu, contextMenuHeader, contextMenudata, readyForContextMenu, + clearInputSelection, + startContextMenuOperation, + endContextMenuOperation, }; }