From 8a639b8f6360fa734b2fcf79629f99951a30590b Mon Sep 17 00:00:00 2001 From: sapphi-red Date: Fri, 30 Apr 2021 16:47:52 +0900 Subject: [PATCH] =?UTF-8?q?=E8=A3=9C=E5=AE=8C=E5=80=99=E8=A3=9C=E3=81=8C?= =?UTF-8?q?=E8=A1=A8=E7=A4=BA=E3=81=95=E3=82=8C=E3=81=A6=E3=81=84=E3=81=AA?= =?UTF-8?q?=E3=81=84=E3=81=A8=E3=81=8D=E3=81=AB=E8=A3=9C=E5=AE=8C=E3=81=8C?= =?UTF-8?q?=E3=81=A7=E3=81=8D=E3=81=A6=E3=81=84=E3=81=9F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Main/MainView/MessageInput/use/wordSuggester.ts | 12 +++++++++--- .../MainView/MessageInput/use/wordSuggestionList.ts | 10 ++++++++-- 2 files changed, 17 insertions(+), 5 deletions(-) diff --git a/src/components/Main/MainView/MessageInput/use/wordSuggester.ts b/src/components/Main/MainView/MessageInput/use/wordSuggester.ts index d1fea15a8..570ddb850 100644 --- a/src/components/Main/MainView/MessageInput/use/wordSuggester.ts +++ b/src/components/Main/MainView/MessageInput/use/wordSuggester.ts @@ -12,6 +12,12 @@ export type WordOrConfirmedPart = text: string } +/** + * 補完を表示する最小の文字数 + * 3なら`@ab`のときは表示されて`@a`では表示されない + */ +const MIN_LENGTH = 3 + const useWordSuggester = ( textareaRef: ComputedRef, value: WritableComputedRef @@ -47,7 +53,7 @@ const useWordSuggester = ( selectedCandidateIndex, prevCandidateText, nextCandidateText - } = useWordSuggesterList(target, currentInputWord) + } = useWordSuggesterList(target, currentInputWord, MIN_LENGTH) const { insertText } = useInsertText(value, textareaRef, target) const insertTextAndMoveTarget = (text: string) => { @@ -59,7 +65,7 @@ const useWordSuggester = ( const updateTarget = () => { if (!textareaRef.value) return target.value = getCurrentWord(textareaRef.value, value.value) - if (target.value.divided || target.value.word.length < 3) { + if (target.value.divided || target.value.word.length < MIN_LENGTH) { isSuggesterShown.value = false return } @@ -73,6 +79,7 @@ const useWordSuggester = ( const onKeyDown = (e: KeyboardEvent) => { if (e.isComposing) return + if (!isSuggesterShown.value) return // Tabによるフォーカスの移動を防止するため、長押しで連続移動できるようにするためにkeyDownで行う必要がある if (e.key === 'Tab') { @@ -91,7 +98,6 @@ const useWordSuggester = ( return } - if (!isSuggesterShown.value) return if (e.key === 'ArrowUp') { e.preventDefault() insertTextAndMoveTarget(prevCandidateText.value) diff --git a/src/components/Main/MainView/MessageInput/use/wordSuggestionList.ts b/src/components/Main/MainView/MessageInput/use/wordSuggestionList.ts index 6cd8bfe7c..5f4c0ab91 100644 --- a/src/components/Main/MainView/MessageInput/use/wordSuggestionList.ts +++ b/src/components/Main/MainView/MessageInput/use/wordSuggestionList.ts @@ -78,13 +78,19 @@ const useCandidateTree = () => { return tree } +/** + * @param minLength 補完が利用できるようになる最小の文字数 + */ const useWordSuggestionList = ( target: Ref, - currentInputWord: Ref + currentInputWord: Ref, + minLength: number ) => { const tree = useCandidateTree() const candidates = computed(() => - tree.value.search(target.value.word.replaceAll('@', '@')) + target.value.word.length >= minLength + ? tree.value.search(target.value.word.replaceAll('@', '@')) + : [] ) const confirmedPart = computed(() => getDeterminedCharacters(candidates.value.map(obj => obj.text))