Skip to content

Commit 9b2c8d3

Browse files
committed
feat: add option to disable focus to input box after answering (#317)
1 parent 43256ed commit 9b2c8d3

File tree

6 files changed

+25
-4
lines changed

6 files changed

+25
-4
lines changed

src/_locales/en/main.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,5 +117,6 @@
117117
"Display selection tools next to input box to avoid blocking": "Display selection tools next to input box to avoid blocking",
118118
"Close All Chats In This Page": "Close All Chats In This Page",
119119
"When Icon Clicked": "When Icon Clicked",
120-
"Open Settings": "Open Settings"
120+
"Open Settings": "Open Settings",
121+
"Focus to input box after answering": "Focus to input box after answering"
121122
}

src/_locales/zh-hans/main.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,5 +117,6 @@
117117
"Display selection tools next to input box to avoid blocking": "将选择浮动工具显示在输入框旁边以避免遮挡",
118118
"Close All Chats In This Page": "关闭本页所有聊天",
119119
"When Icon Clicked": "当图标被点击时",
120-
"Open Settings": "打开设置"
120+
"Open Settings": "打开设置",
121+
"Focus to input box after answering": "回答结束后自动聚焦到输入框"
121122
}

src/_locales/zh-hant/main.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,5 +117,6 @@
117117
"Display selection tools next to input box to avoid blocking": "將選擇浮動工具顯示在輸入框旁邊以避免遮擋",
118118
"Close All Chats In This Page": "關閉本頁所有對話",
119119
"When Icon Clicked": "當圖示被點擊時",
120-
"Open Settings": "開啟設定"
120+
"Open Settings": "開啟設定",
121+
"Focus to input box after answering": "回答結束後自動聚焦到輸入框"
121122
}

src/components/InputBox/index.jsx

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import { useEffect, useRef, useState } from 'react'
22
import PropTypes from 'prop-types'
33
import { updateRefHeight } from '../../utils'
44
import { useTranslation } from 'react-i18next'
5+
import { getUserConfig } from '../../config/index.mjs'
56

67
export function InputBox({ onSubmit, enabled, port, reverseResizeDir }) {
78
const { t } = useTranslation()
@@ -13,6 +14,8 @@ export function InputBox({ onSubmit, enabled, port, reverseResizeDir }) {
1314
const virtualInputRef = reverseResizeDir ? reverseDivRef : inputRef
1415

1516
useEffect(() => {
17+
inputRef.current.focus()
18+
1619
const onResizeY = () => {
1720
if (virtualInputRef.current.h !== virtualInputRef.current.offsetHeight) {
1821
virtualInputRef.current.h = virtualInputRef.current.offsetHeight
@@ -37,7 +40,10 @@ export function InputBox({ onSubmit, enabled, port, reverseResizeDir }) {
3740
})
3841

3942
useEffect(() => {
40-
if (enabled) inputRef.current.focus()
43+
if (enabled)
44+
getUserConfig().then((config) => {
45+
if (config.focusAfterAnswer) inputRef.current.focus()
46+
})
4147
}, [enabled])
4248

4349
const handleKeyDownOrClick = (e) => {

src/config/index.mjs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,7 @@ export const defaultConfig = {
9696
autoRegenAfterSwitchModel: false,
9797
selectionToolsNextToInputBox: false,
9898
alwaysPinWindow: false,
99+
focusAfterAnswer: true,
99100

100101
apiKey: '', // openai ApiKey
101102

src/popup/sections/GeneralPart.jsx

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -360,6 +360,17 @@ export function GeneralPart({ config, updateConfig }) {
360360
/>
361361
{t('Always pin the floating window')}
362362
</label>
363+
<label>
364+
<input
365+
type="checkbox"
366+
checked={config.focusAfterAnswer}
367+
onChange={(e) => {
368+
const checked = e.target.checked
369+
updateConfig({ focusAfterAnswer: checked })
370+
}}
371+
/>
372+
{t('Focus to input box after answering')}
373+
</label>
363374
<br />
364375
</>
365376
)

0 commit comments

Comments
 (0)