Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions src/main/presenter/deeplinkPresenter/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,15 @@ export class DeeplinkPresenter implements IDeeplinkPresenter {
console.log('modelId:', modelId)
console.log('systemPrompt:', systemPrompt)
console.log('autoSend:', autoSend)

const focusedWindow = presenter.windowPresenter.getFocusedWindow()
if (focusedWindow) {
focusedWindow.show()
focusedWindow.focus()
} else {
presenter.windowPresenter.show()
}

eventBus.sendToRenderer(DEEPLINK_EVENTS.START, SendTarget.DEFAULT_TAB, {
msg,
modelId,
Expand Down
3 changes: 3 additions & 0 deletions src/main/presenter/tabPresenter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -609,6 +609,9 @@ export class TabPresenter implements ITabPresenter {
// Re-adding ensures it's on top in most view hierarchies
window.contentView.addChildView(view)
this.updateViewBounds(window, view)
if (!view.webContents.isDestroyed()) {
view.webContents.focus()
}
}

/**
Expand Down
24 changes: 24 additions & 0 deletions src/main/presenter/windowPresenter/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -310,6 +310,7 @@ export class WindowPresenter implements IWindowPresenter {
this.handleWindowRestore(targetWindow.id).catch((error) => {
console.error(`Error handling restore logic after showing window ${targetWindow!.id}:`, error)
})
this.focusActiveTab(targetWindow.id)
}

/**
Expand Down Expand Up @@ -374,6 +375,26 @@ export class WindowPresenter implements IWindowPresenter {
return focusedWindow ? focusedWindow.id === windowId : false
}

/**
* 将焦点传递给指定窗口的活动标签页
* @param windowId 窗口 ID
*/
private focusActiveTab(windowId: number): void {
try {
setTimeout(async () => {
const tabPresenterInstance = presenter.tabPresenter as TabPresenter
const tabsData = await tabPresenterInstance.getWindowTabsData(windowId)
const activeTab = tabsData.find((tab) => tab.isActive)
if (activeTab) {
console.log(`Focusing active tab ${activeTab.id} in window ${windowId}`)
await tabPresenterInstance.switchTab(activeTab.id)
}
}, 50)
} catch (error) {
console.error(`Error focusing active tab in window ${windowId}:`, error)
}
}

/**
* 向所有有效窗口的主 WebContents 和所有标签页的 WebContents 发送消息。
* @param channel IPC 通道名。
Expand Down Expand Up @@ -537,6 +558,7 @@ export class WindowPresenter implements IWindowPresenter {
if (!shellWindow.isDestroyed()) {
shellWindow.webContents.send('window-focused', windowId)
}
this.focusActiveTab(windowId)
})

// 窗口失去焦点
Expand Down Expand Up @@ -584,6 +606,7 @@ export class WindowPresenter implements IWindowPresenter {
this.handleWindowRestore(windowId).catch((error) => {
console.error(`Error handling restore logic for window ${windowId}:`, error)
})
this.focusActiveTab(windowId)
eventBus.sendToMain(WINDOW_EVENTS.WINDOW_RESTORED, windowId)
}
shellWindow.on('restore', handleRestore)
Expand Down Expand Up @@ -971,6 +994,7 @@ export class WindowPresenter implements IWindowPresenter {
console.log(` - Switching to tab ${targetTabData.id}`)
await tabPresenterInstance.switchTab(targetTabData.id)
}
// switchTab 已经会调用 bringViewToFront 来设置焦点,无需额外调用
} catch (error) {
console.error('Error switching to target window/tab:', error)
// 继续,因为消息发送成功
Expand Down
11 changes: 10 additions & 1 deletion src/renderer/src/components/ChatInput.vue
Original file line number Diff line number Diff line change
Expand Up @@ -1021,7 +1021,16 @@ function onKeydown(e: KeyboardEvent) {
defineExpose({
setText: (text: string) => {
inputText.value = text
editor.chain().setContent(text).focus('end').run()
nextTick(() => {
editor.chain().clearContent().insertContent(text).run()
nextTick(() => {
editor.view.updateState(editor.state)
setTimeout(() => {
const docSize = editor.state.doc.content.size
editor.chain().focus().setTextSelection(docSize).run()
}, 10)
})
})
}
})
</script>
Expand Down