From 9b2c8d3d330799eb21dfbb207e51ca39ddd02778 Mon Sep 17 00:00:00 2001 From: josc146 Date: Sat, 13 May 2023 16:37:30 +0800 Subject: [PATCH] feat: add option to disable `focus to input box after answering` (#317) --- src/_locales/en/main.json | 3 ++- src/_locales/zh-hans/main.json | 3 ++- src/_locales/zh-hant/main.json | 3 ++- src/components/InputBox/index.jsx | 8 +++++++- src/config/index.mjs | 1 + src/popup/sections/GeneralPart.jsx | 11 +++++++++++ 6 files changed, 25 insertions(+), 4 deletions(-) diff --git a/src/_locales/en/main.json b/src/_locales/en/main.json index 337aca7..c0d0b7a 100644 --- a/src/_locales/en/main.json +++ b/src/_locales/en/main.json @@ -117,5 +117,6 @@ "Display selection tools next to input box to avoid blocking": "Display selection tools next to input box to avoid blocking", "Close All Chats In This Page": "Close All Chats In This Page", "When Icon Clicked": "When Icon Clicked", - "Open Settings": "Open Settings" + "Open Settings": "Open Settings", + "Focus to input box after answering": "Focus to input box after answering" } diff --git a/src/_locales/zh-hans/main.json b/src/_locales/zh-hans/main.json index 310fa1f..67d9282 100644 --- a/src/_locales/zh-hans/main.json +++ b/src/_locales/zh-hans/main.json @@ -117,5 +117,6 @@ "Display selection tools next to input box to avoid blocking": "将选择浮动工具显示在输入框旁边以避免遮挡", "Close All Chats In This Page": "关闭本页所有聊天", "When Icon Clicked": "当图标被点击时", - "Open Settings": "打开设置" + "Open Settings": "打开设置", + "Focus to input box after answering": "回答结束后自动聚焦到输入框" } diff --git a/src/_locales/zh-hant/main.json b/src/_locales/zh-hant/main.json index bafafd3..b164716 100644 --- a/src/_locales/zh-hant/main.json +++ b/src/_locales/zh-hant/main.json @@ -117,5 +117,6 @@ "Display selection tools next to input box to avoid blocking": "將選擇浮動工具顯示在輸入框旁邊以避免遮擋", "Close All Chats In This Page": "關閉本頁所有對話", "When Icon Clicked": "當圖示被點擊時", - "Open Settings": "開啟設定" + "Open Settings": "開啟設定", + "Focus to input box after answering": "回答結束後自動聚焦到輸入框" } diff --git a/src/components/InputBox/index.jsx b/src/components/InputBox/index.jsx index 80a4399..748b84c 100644 --- a/src/components/InputBox/index.jsx +++ b/src/components/InputBox/index.jsx @@ -2,6 +2,7 @@ import { useEffect, useRef, useState } from 'react' import PropTypes from 'prop-types' import { updateRefHeight } from '../../utils' import { useTranslation } from 'react-i18next' +import { getUserConfig } from '../../config/index.mjs' export function InputBox({ onSubmit, enabled, port, reverseResizeDir }) { const { t } = useTranslation() @@ -13,6 +14,8 @@ export function InputBox({ onSubmit, enabled, port, reverseResizeDir }) { const virtualInputRef = reverseResizeDir ? reverseDivRef : inputRef useEffect(() => { + inputRef.current.focus() + const onResizeY = () => { if (virtualInputRef.current.h !== virtualInputRef.current.offsetHeight) { virtualInputRef.current.h = virtualInputRef.current.offsetHeight @@ -37,7 +40,10 @@ export function InputBox({ onSubmit, enabled, port, reverseResizeDir }) { }) useEffect(() => { - if (enabled) inputRef.current.focus() + if (enabled) + getUserConfig().then((config) => { + if (config.focusAfterAnswer) inputRef.current.focus() + }) }, [enabled]) const handleKeyDownOrClick = (e) => { diff --git a/src/config/index.mjs b/src/config/index.mjs index a96cba6..3fee22a 100644 --- a/src/config/index.mjs +++ b/src/config/index.mjs @@ -96,6 +96,7 @@ export const defaultConfig = { autoRegenAfterSwitchModel: false, selectionToolsNextToInputBox: false, alwaysPinWindow: false, + focusAfterAnswer: true, apiKey: '', // openai ApiKey diff --git a/src/popup/sections/GeneralPart.jsx b/src/popup/sections/GeneralPart.jsx index 96c7831..32734ab 100644 --- a/src/popup/sections/GeneralPart.jsx +++ b/src/popup/sections/GeneralPart.jsx @@ -360,6 +360,17 @@ export function GeneralPart({ config, updateConfig }) { /> {t('Always pin the floating window')} +
)