feat(SelectionAssistant): support Shift+Click & enhance Ctrl key mode (#6566)

* feat: add filter mode and list functionality to selection assistant

- Introduced new filter mode options (default, whitelist, blacklist) for the selection assistant.
- Added methods to set and get filter mode and filter list in ConfigManager.
- Enhanced SelectionService to manage filter mode and list, affecting text selection processing.
- Updated UI components to allow users to configure filter settings.
- Localized new filter settings in multiple languages.

* feat: support Shift+Click & enhance Ctrl key method

* fix: remove comments
This commit is contained in:
fullex 2025-05-29 10:10:55 +08:00 committed by GitHub
parent 808afa053f
commit c5c5681cfd
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 30 additions and 17 deletions

View File

@ -90,7 +90,7 @@
"officeparser": "^4.1.1", "officeparser": "^4.1.1",
"os-proxy-config": "^1.1.2", "os-proxy-config": "^1.1.2",
"proxy-agent": "^6.5.0", "proxy-agent": "^6.5.0",
"selection-hook": "^0.9.15", "selection-hook": "^0.9.17",
"tar": "^7.4.3", "tar": "^7.4.3",
"turndown": "^7.2.0", "turndown": "^7.2.0",
"webdav": "^5.8.0", "webdav": "^5.8.0",

View File

@ -143,7 +143,7 @@ export class SelectionService {
this.filterMode = configManager.getSelectionAssistantFilterMode() this.filterMode = configManager.getSelectionAssistantFilterMode()
this.filterList = configManager.getSelectionAssistantFilterList() this.filterList = configManager.getSelectionAssistantFilterList()
this.setHookClipboardMode(this.filterMode, this.filterList) this.setHookGlobalFilterMode(this.filterMode, this.filterList)
configManager.subscribe(ConfigKeys.SelectionAssistantTriggerMode, (triggerMode: string) => { configManager.subscribe(ConfigKeys.SelectionAssistantTriggerMode, (triggerMode: string) => {
this.triggerMode = triggerMode this.triggerMode = triggerMode
@ -156,21 +156,21 @@ export class SelectionService {
configManager.subscribe(ConfigKeys.SelectionAssistantFilterMode, (filterMode: string) => { configManager.subscribe(ConfigKeys.SelectionAssistantFilterMode, (filterMode: string) => {
this.filterMode = filterMode this.filterMode = filterMode
this.setHookClipboardMode(this.filterMode, this.filterList) this.setHookGlobalFilterMode(this.filterMode, this.filterList)
}) })
configManager.subscribe(ConfigKeys.SelectionAssistantFilterList, (filterList: string[]) => { configManager.subscribe(ConfigKeys.SelectionAssistantFilterList, (filterList: string[]) => {
this.filterList = filterList this.filterList = filterList
this.setHookClipboardMode(this.filterMode, this.filterList) this.setHookGlobalFilterMode(this.filterMode, this.filterList)
}) })
} }
/** /**
* Set the clipboard mode for the selection-hook * Set the global filter mode for the selection-hook
* @param mode - The mode to set, either 'default', 'whitelist', or 'blacklist' * @param mode - The mode to set, either 'default', 'whitelist', or 'blacklist'
* @param list - An array of strings representing the list of items to include or exclude * @param list - An array of strings representing the list of items to include or exclude
*/ */
private setHookClipboardMode(mode: string, list: string[]) { private setHookGlobalFilterMode(mode: string, list: string[]) {
if (!this.selectionHook) return if (!this.selectionHook) return
const modeMap = { const modeMap = {
@ -178,8 +178,8 @@ export class SelectionService {
whitelist: 1, whitelist: 1,
blacklist: 2 blacklist: 2
} }
if (!this.selectionHook.setClipboardMode(modeMap[mode], list)) { if (!this.selectionHook.setGlobalFilterMode(modeMap[mode], list)) {
this.logError(new Error('Failed to set selection-hook clipboard mode')) this.logError(new Error('Failed to set selection-hook global filter mode'))
} }
} }
@ -194,8 +194,6 @@ export class SelectionService {
} }
try { try {
//init basic configs
this.initConfig()
//make sure the toolbar window is ready //make sure the toolbar window is ready
this.createToolbarWindow() this.createToolbarWindow()
// Initialize preloaded windows // Initialize preloaded windows
@ -209,6 +207,9 @@ export class SelectionService {
// Start the hook // Start the hook
if (this.selectionHook.start({ debug: isDev })) { if (this.selectionHook.start({ debug: isDev })) {
//init basic configs
this.initConfig()
//init trigger mode configs //init trigger mode configs
this.processTriggerMode() this.processTriggerMode()
@ -613,12 +614,16 @@ export class SelectionService {
selectionData.endBottom selectionData.endBottom
) )
// Note: shift key + mouse click == DoubleClick
//double click to select a word
if (isDoubleClick && isSameLine) { if (isDoubleClick && isSameLine) {
refOrientation = 'bottomMiddle' refOrientation = 'bottomMiddle'
refPoint = { x: selectionData.mousePosEnd.x, y: selectionData.endBottom.y + 4 } refPoint = { x: selectionData.mousePosEnd.x, y: selectionData.endBottom.y + 4 }
break break
} }
// below: isDoubleClick || isSameLine
if (isSameLine) { if (isSameLine) {
const direction = selectionData.mousePosEnd.x - selectionData.mousePosStart.x const direction = selectionData.mousePosEnd.x - selectionData.mousePosStart.x
@ -632,6 +637,7 @@ export class SelectionService {
break break
} }
// below: !isDoubleClick && !isSameLine
const direction = selectionData.mousePosEnd.y - selectionData.mousePosStart.y const direction = selectionData.mousePosEnd.y - selectionData.mousePosStart.y
if (direction > 0) { if (direction > 0) {
@ -732,6 +738,10 @@ export class SelectionService {
if (this.triggerMode === 'ctrlkey' && this.isCtrlkey(data.vkCode)) { if (this.triggerMode === 'ctrlkey' && this.isCtrlkey(data.vkCode)) {
return return
} }
//dont hide toolbar when shiftkey is pressed, because it's used for selection
if (this.isShiftkey(data.vkCode)) {
return
}
this.hideToolbar() this.hideToolbar()
} }
@ -788,6 +798,11 @@ export class SelectionService {
return vkCode === 162 || vkCode === 163 return vkCode === 162 || vkCode === 163
} }
//check if the key is shift key
private isShiftkey(vkCode: number) {
return vkCode === 160 || vkCode === 161
}
/** /**
* Create a preloaded action window for quick response * Create a preloaded action window for quick response
* Action windows handle specific operations on selected text * Action windows handle specific operations on selected text
@ -958,7 +973,6 @@ export class SelectionService {
this.isCtrlkeyListenerActive = false this.isCtrlkeyListenerActive = false
} }
this.selectionHook!.enableClipboard()
this.selectionHook!.setSelectionPassiveMode(false) this.selectionHook!.setSelectionPassiveMode(false)
} else if (this.triggerMode === 'ctrlkey') { } else if (this.triggerMode === 'ctrlkey') {
if (!this.isCtrlkeyListenerActive) { if (!this.isCtrlkeyListenerActive) {
@ -968,7 +982,6 @@ export class SelectionService {
this.isCtrlkeyListenerActive = true this.isCtrlkeyListenerActive = true
} }
this.selectionHook!.disableClipboard()
this.selectionHook!.setSelectionPassiveMode(true) this.selectionHook!.setSelectionPassiveMode(true)
} }
} }

View File

@ -5666,7 +5666,7 @@ __metadata:
remark-math: "npm:^6.0.0" remark-math: "npm:^6.0.0"
rollup-plugin-visualizer: "npm:^5.12.0" rollup-plugin-visualizer: "npm:^5.12.0"
sass: "npm:^1.88.0" sass: "npm:^1.88.0"
selection-hook: "npm:^0.9.15" selection-hook: "npm:^0.9.17"
shiki: "npm:^3.4.2" shiki: "npm:^3.4.2"
string-width: "npm:^7.2.0" string-width: "npm:^7.2.0"
styled-components: "npm:^6.1.11" styled-components: "npm:^6.1.11"
@ -16376,13 +16376,13 @@ __metadata:
languageName: node languageName: node
linkType: hard linkType: hard
"selection-hook@npm:^0.9.15": "selection-hook@npm:^0.9.17":
version: 0.9.15 version: 0.9.17
resolution: "selection-hook@npm:0.9.15" resolution: "selection-hook@npm:0.9.17"
dependencies: dependencies:
node-gyp: "npm:latest" node-gyp: "npm:latest"
node-gyp-build: "npm:^4.8.4" node-gyp-build: "npm:^4.8.4"
checksum: 10c0/e1b5fdfc9135f9d1a37a99d46414517ff63c11250e7510005adbaa144f35f8ae72871effd26245abb657cd85a8539d9b25df92c5850f46a0aa95224e17d7f0a1 checksum: 10c0/1dbd1234e06bb6fe53d2fe9cb0de9736177af0b66e824c4dd3fb2d90413c30235c999826893f999b1d8809bfaf33968108c609b5ac80ea4b946f6a4891f5d1b9
languageName: node languageName: node
linkType: hard linkType: hard