Skip to content

Commit

Permalink
add autoFocus settings
Browse files Browse the repository at this point in the history
  • Loading branch information
NitroRCr committed Dec 28, 2024
1 parent c69df34 commit 0eed7d8
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 5 deletions.
2 changes: 1 addition & 1 deletion docs/usage/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,4 +57,4 @@

- 快速滚动:对话右下角有快速滚动按钮,除了一般的滚动到顶部/底部,中间两个按钮是对齐到消息开头/末尾或者上一条/下一条消息的滚动,在消息较长时很方便

- 键盘控制:支持设置键盘快捷键触发上述的滚动操作,以及用键盘快捷键切换消息链
- 键盘控制:键盘控制:支持设置键盘快捷键触发上述的滚动操作,以及用键盘快捷键切换消息链、重新生成、新建对话
15 changes: 15 additions & 0 deletions src/pages/SettingsPage.vue
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,21 @@
/>
</q-item-section>
</q-item>
<q-item>
<q-item-section>
<q-item-label>
自动聚焦对话输入框
</q-item-label>
</q-item-section>
<q-item-section side>
<platform-enabled-input
v-model="perfs.autoFocusDialogInput"
class="min-w-120px"
dense
filled
/>
</q-item-section>
</q-item>
<q-item
clickable
v-ripple
Expand Down
4 changes: 3 additions & 1 deletion src/stores/user-perfs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ interface Perfs {
editCurrKey?: ShortcutKey
createDialogKey?: ShortcutKey
focusDialogInputKey?: ShortcutKey
autoFocusDialogInput: PlatformEnabled
}

export const useUserPerfsStore = defineStore('user-perfs', () => {
Expand Down Expand Up @@ -71,7 +72,8 @@ export const useUserPerfsStore = defineStore('user-perfs', () => {
switchPrevKeyV2: { key: 'ArrowLeft', withCtrl: true },
switchNextKeyV2: { key: 'ArrowRight', withCtrl: true },
switchFirstKey: { key: 'ArrowLeft', withShift: true },
switchLastKey: { key: 'ArrowRight', withShift: true }
switchLastKey: { key: 'ArrowRight', withShift: true },
autoFocusDialogInput: 'desktop-only'
}
const [perfs, ready] = persistentReactive('#user-perfs', { ...defaultPerfs })
watchEffect(() => {
Expand Down
9 changes: 6 additions & 3 deletions src/views/DialogView.vue
Original file line number Diff line number Diff line change
Expand Up @@ -452,6 +452,9 @@ function getChain(node, route: number[]) {
}
const messageInput = ref()
function focusInput() {
isPlatformEnabled(perfs.autoFocusDialogInput) && messageInput.value?.focus()
}
async function edit(index) {
const target = chain.value[index - 1]
const { type, contents } = messageMap.value[chain.value[index]]
Expand All @@ -466,7 +469,7 @@ async function edit(index) {
saveItems(content.items.map(id => itemMap.value[id]))
})
await nextTick()
messageInput.value.focus()
focusInput()
}
async function regenerate(index) {
const target = chain.value[index - 1]
Expand Down Expand Up @@ -1059,7 +1062,7 @@ watch(route, to => {
db.workspaces.update(workspace.value.id, { lastDialogId: props.id } as Partial<Workspace>)
until(dialog).toMatch(val => val?.id === props.id).then(() => {
messageInput.value?.focus()
focusInput()
if (to.hash === '#genTitle') {
genTitle()
router.replace({ hash: '' })
Expand Down Expand Up @@ -1216,7 +1219,7 @@ if (isPlatformEnabled(perfs.enableShortcutKey)) {
useListenKey(toRef(perfs, 'switchLastKey'), () => switchTo('last'))
useListenKey(toRef(perfs, 'regenerateCurrKey'), () => regenerateCurr())
useListenKey(toRef(perfs, 'editCurrKey'), () => editCurr())
useListenKey(toRef(perfs, 'focusDialogInputKey'), () => messageInput.value.focus())
useListenKey(toRef(perfs, 'focusDialogInputKey'), () => focusInput())
}
defineEmits(['toggle-drawer'])
Expand Down

0 comments on commit 0eed7d8

Please sign in to comment.