mirror of
https://github.com/voideditor/void
synced 2026-05-24 09:58:23 +00:00
fix: preserve selection when adding to chat via CTRL+L with closed panel
This commit is contained in:
parent
053a022ef8
commit
dd42e40a8d
1 changed files with 16 additions and 25 deletions
|
|
@ -89,10 +89,7 @@ registerAction2(class extends Action2 {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
async run(accessor: ServicesAccessor): Promise<void> {
|
async run(accessor: ServicesAccessor): Promise<void> {
|
||||||
|
// Get services
|
||||||
|
|
||||||
// Get the views service to check if the sidebar is open
|
|
||||||
// const viewsService = accessor.get(IViewsService)
|
|
||||||
const commandService = accessor.get(ICommandService)
|
const commandService = accessor.get(ICommandService)
|
||||||
const viewsService = accessor.get(IViewsService)
|
const viewsService = accessor.get(IViewsService)
|
||||||
const metricsService = accessor.get(IMetricsService)
|
const metricsService = accessor.get(IMetricsService)
|
||||||
|
|
@ -101,31 +98,28 @@ registerAction2(class extends Action2 {
|
||||||
|
|
||||||
metricsService.capture('Ctrl+L', {})
|
metricsService.capture('Ctrl+L', {})
|
||||||
|
|
||||||
|
// Capture selection and model BEFORE opening the chat panel
|
||||||
|
const editor = editorService.getActiveCodeEditor()
|
||||||
|
const model = editor?.getModel()
|
||||||
|
if (!model) return
|
||||||
|
|
||||||
|
const selectionRange = roundRangeToLines(editor?.getSelection(), { emptySelectionBehavior: 'null' })
|
||||||
|
|
||||||
|
// Now check if panel is open and open it if needed
|
||||||
const wasAlreadyOpen = viewsService.isViewContainerVisible(VOID_VIEW_CONTAINER_ID)
|
const wasAlreadyOpen = viewsService.isViewContainerVisible(VOID_VIEW_CONTAINER_ID)
|
||||||
if (!wasAlreadyOpen) {
|
if (!wasAlreadyOpen) {
|
||||||
await commandService.executeCommand(VOID_OPEN_SIDEBAR_ACTION_ID)
|
await commandService.executeCommand(VOID_OPEN_SIDEBAR_ACTION_ID)
|
||||||
return
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Add selection to chat (whether it was already open or we just opened it)
|
||||||
// if was already open
|
|
||||||
|
|
||||||
const model = accessor.get(ICodeEditorService).getActiveCodeEditor()?.getModel()
|
|
||||||
if (!model) return
|
|
||||||
|
|
||||||
const editor = editorService.getActiveCodeEditor()
|
|
||||||
const selectionRange = roundRangeToLines(editor?.getSelection(), { emptySelectionBehavior: 'null' })
|
|
||||||
|
|
||||||
// if has no selection, close + return
|
|
||||||
// if (!selectionRange) {
|
|
||||||
// viewsService.closeViewContainer(VOID_VIEW_CONTAINER_ID);
|
|
||||||
// return;
|
|
||||||
// }
|
|
||||||
|
|
||||||
|
|
||||||
// add line selection
|
// add line selection
|
||||||
if (selectionRange) {
|
if (selectionRange) {
|
||||||
editor?.setSelection({ startLineNumber: selectionRange.startLineNumber, endLineNumber: selectionRange.endLineNumber, startColumn: 1, endColumn: Number.MAX_SAFE_INTEGER })
|
editor?.setSelection({
|
||||||
|
startLineNumber: selectionRange.startLineNumber,
|
||||||
|
endLineNumber: selectionRange.endLineNumber,
|
||||||
|
startColumn: 1,
|
||||||
|
endColumn: Number.MAX_SAFE_INTEGER
|
||||||
|
})
|
||||||
chatThreadService.addNewStagingSelection({
|
chatThreadService.addNewStagingSelection({
|
||||||
type: 'CodeSelection',
|
type: 'CodeSelection',
|
||||||
uri: model.uri,
|
uri: model.uri,
|
||||||
|
|
@ -142,12 +136,9 @@ registerAction2(class extends Action2 {
|
||||||
language: model.getLanguageId(),
|
language: model.getLanguageId(),
|
||||||
state: { wasAddedAsCurrentFile: false },
|
state: { wasAddedAsCurrentFile: false },
|
||||||
})
|
})
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
await chatThreadService.focusCurrentChat()
|
await chatThreadService.focusCurrentChat()
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue