diff --git a/packages/gui/package.json b/packages/gui/package.json index e5fe7cd..24af998 100644 --- a/packages/gui/package.json +++ b/packages/gui/package.json @@ -34,6 +34,7 @@ "request-progress": "^3.0.0", "sass": "^1.81.0", "sass-loader": "^16.0.3", + "search-bar-vue2": "^1.0.0", "vue": "^2.7.16", "vue-json-editor-fix-cn": "^1.4.3", "vue-router": "^3.6.5" diff --git a/packages/gui/src/background.js b/packages/gui/src/background.js index 0b2763c..b5b4e36 100644 --- a/packages/gui/src/background.js +++ b/packages/gui/src/background.js @@ -298,28 +298,38 @@ function createWindow (startHideWindow, autoQuitIfError = true) { }) const shortcut = (event, input) => { - // 按 F12,打开/关闭 开发者工具 - if (input.key === 'F12') { - // 阻止默认的按键事件行为 + if (input.key === 'F12' && input.type === 'keyUp' && !input.control && !input.shift && !input.alt && !input.meta) { + // 按 F12,打开/关闭 开发者工具 event.preventDefault() - // 切换开发者工具显示状态 switchDevTools() - // eslint-disable-next-line style/brace-style - } - // 按 F5,刷新页面 - else if (input.key === 'F5') { - // 阻止默认的按键事件行为 + } else if (input.key === 'F5' && input.type === 'keyUp' && !input.control && !input.shift && !input.alt && !input.meta) { + // 按 F5,刷新页面 event.preventDefault() - // 刷新页面 win.webContents.reload() + } else { + // 全文检索框(SearchBar)相关快捷键 + if ((input.key === 'F' || input.key === 'f') && input.type === 'keyDown' && input.control && !input.shift && !input.alt && !input.meta) { + // 按 Ctrl + F,显示或隐藏全文检索框(SearchBar) + event.preventDefault() + win.webContents.send('search-bar', { key: 'show-hide' }) + } else if (input.key === 'Escape' && input.type === 'keyUp' && !input.control && !input.shift && !input.alt && !input.meta) { + // 按 ESC,隐藏全文检索框(SearchBar) + event.preventDefault() + win.webContents.send('search-bar', { key: 'show-hide', hideSearchBar: true }) + } else if (input.key === 'F3' && input.type === 'keyDown' && !input.control && !input.shift && !input.alt && !input.meta) { + // 按 F3,全文检索框(SearchBar)定位到下一个 + event.preventDefault() + win.webContents.send('search-bar', { key: 'next' }) + } else if (input.key === 'F3' && input.type === 'keyDown' && !input.control && input.shift && !input.alt && !input.meta) { + // 按 Shift + F3,全文检索框(SearchBar)定位到上一个 + event.preventDefault() + win.webContents.send('search-bar', { key: 'previous' }) + } } } // 监听键盘事件 win.webContents.on('before-input-event', (event, input) => { - if (input.type !== 'keyUp' || input.control || input.alt || input.shift || input.meta) { - return - } win.webContents.executeJavaScript('config') .then((value) => { console.info('window.config:', value, ', key:', input.key) diff --git a/packages/gui/src/main.js b/packages/gui/src/main.js index 198abb9..e89daaa 100644 --- a/packages/gui/src/main.js +++ b/packages/gui/src/main.js @@ -1,6 +1,7 @@ import antd from 'ant-design-vue' import Vue from 'vue' import VueRouter from 'vue-router' +import SearchBar from 'search-bar-vue2' import { ipcRenderer } from 'electron' import view from './view' import App from './view/App.vue' @@ -25,6 +26,7 @@ try { Vue.config.productionTip = false Vue.use(antd) Vue.use(VueRouter) + Vue.use(SearchBar) Vue.component(DsContainer) // 3. 创建 router 实例,然后传 `routes` 配置 // 你还可以传别的配置参数, 不过先这么简单着吧。 diff --git a/packages/gui/src/view/App.vue b/packages/gui/src/view/App.vue index 4ce294d..5f02614 100644 --- a/packages/gui/src/view/App.vue +++ b/packages/gui/src/view/App.vue @@ -1,4 +1,6 @@