This commit is contained in:
Andrew Pareles 2025-01-05 18:03:36 -08:00
parent 35091eb8f2
commit fb948b331f
7 changed files with 58 additions and 47 deletions

View file

@ -31,7 +31,7 @@ import { ctrlKStream_prefixAndSuffix, ctrlKStream_prompt, ctrlKStream_systemMess
import { ILLMMessageService } from '../../../../platform/void/common/llmMessageService.js'; import { ILLMMessageService } from '../../../../platform/void/common/llmMessageService.js';
import { IPosition } from '../../../../editor/common/core/position.js'; import { IPosition } from '../../../../editor/common/core/position.js';
import { mountCtrlK } from '../browser/react/out/ctrl-k-tsx/index.js' import { mountCtrlK } from '../browser/react/out/quick-edit-tsx/index.js'
import { QuickEditPropsType } from './quickEditActions.js'; import { QuickEditPropsType } from './quickEditActions.js';
import { InputBox } from '../../../../base/browser/ui/inputbox/inputBox.js'; import { InputBox } from '../../../../base/browser/ui/inputbox/inputBox.js';
import { LLMMessage } from '../../../../platform/void/common/llmMessageTypes.js'; import { LLMMessage } from '../../../../platform/void/common/llmMessageTypes.js';

View file

@ -361,10 +361,10 @@ Note that the SELECTION has code that comes before it. This code is indicated wi
Note also that the SELECTION has code that comes after it. This code is indicated with <${sufTag}>...after<${sufTag}/>. Note also that the SELECTION has code that comes after it. This code is indicated with <${sufTag}>...after<${sufTag}/>.
Instructions: Instructions:
1. Your OUTPUT should be a SINGLE PIECE OF CODE of the form <${midTag}>...new_selection<${midTag}/> 1. Your OUTPUT should be a SINGLE PIECE OF CODE of the form <${midTag}>...new_selection<${midTag}/>. Do not give any explanation before or after this. ONLY output this format, nothing more.
2. You may ONLY CHANGE the original SELECTION, and NOT the content in the <${preTag}>...<${preTag}/> or <${sufTag}>...<${sufTag}/> tags 2. You may ONLY CHANGE the original SELECTION, and NOT the content in the <${preTag}>...<${preTag}/> or <${sufTag}>...<${sufTag}/> tags.
3. Make sure all brackets in the new selection are balanced the same as in the original selection 3. Make sure all brackets in the new selection are balanced the same as in the original selection.
4. Be careful not to duplicate or remove variables, comments, or other syntax by mistake 4. Be careful not to duplicate or remove variables, comments, or other syntax by mistake.
Complete the following: Complete the following:
<${preTag}>${prefix}</${preTag}> <${preTag}>${prefix}</${preTag}>

View file

@ -6,16 +6,16 @@
import { useEffect, useState } from 'react' import { useEffect, useState } from 'react'
import { useIsDark, useSidebarState } from '../util/services.js' import { useIsDark, useSidebarState } from '../util/services.js'
import ErrorBoundary from '../sidebar-tsx/ErrorBoundary.js' import ErrorBoundary from '../sidebar-tsx/ErrorBoundary.js'
import { CtrlKChat } from './CtrlKChat.js' import { QuickEditChat } from './QuickEditChat.js'
import { QuickEditPropsType } from '../../../quickEditActions.js' import { QuickEditPropsType } from '../../../quickEditActions.js'
export const CtrlK = (props: QuickEditPropsType) => { export const QuickEdit = (props: QuickEditPropsType) => {
const isDark = useIsDark() const isDark = useIsDark()
return <div className={`@@void-scope ${isDark ? 'dark' : ''}`}> return <div className={`@@void-scope ${isDark ? 'dark' : ''}`}>
<ErrorBoundary> <ErrorBoundary>
<CtrlKChat {...props} /> <QuickEditChat {...props} />
</ErrorBoundary> </ErrorBoundary>
</div> </div>

View file

@ -14,13 +14,14 @@ import { ButtonStop, ButtonSubmit } from '../sidebar-tsx/SidebarChat.js';
import { ModelDropdown } from '../void-settings-tsx/ModelDropdown.js'; import { ModelDropdown } from '../void-settings-tsx/ModelDropdown.js';
import { X } from 'lucide-react'; import { X } from 'lucide-react';
export const CtrlKChat = ({ diffareaid, onGetInputBox, onUserUpdateText, onChangeHeight, initText }: QuickEditPropsType) => { export const QuickEditChat = ({ diffareaid, onGetInputBox, onUserUpdateText, onChangeHeight, initText }: QuickEditPropsType) => {
const accessor = useAccessor() const accessor = useAccessor()
const inlineDiffsService = accessor.get('IInlineDiffsService') const inlineDiffsService = accessor.get('IInlineDiffsService')
const sizerRef = useRef<HTMLDivElement | null>(null) const sizerRef = useRef<HTMLDivElement | null>(null)
const inputBoxRef: React.MutableRefObject<InputBox | null> = useRef(null); const inputBoxRef: React.MutableRefObject<InputBox | null> = useRef(null);
useEffect(() => { useEffect(() => {
const inputContainer = sizerRef.current const inputContainer = sizerRef.current
if (!inputContainer) return; if (!inputContainer) return;
@ -67,6 +68,10 @@ export const CtrlKChat = ({ diffareaid, onGetInputBox, onUserUpdateText, onChang
}, [inlineDiffsService]) }, [inlineDiffsService])
const onX = useCallback(() => {
inlineDiffsService.removeCtrlKZone({ diffareaid })
}, [inlineDiffsService, diffareaid])
// sync init value // sync init value
const alreadySetRef = useRef(false) const alreadySetRef = useRef(false)
useEffect(() => { useEffect(() => {
@ -116,9 +121,9 @@ export const CtrlKChat = ({ diffareaid, onGetInputBox, onUserUpdateText, onChang
@@[&_div.monaco-inputbox]:!void-outline-none`} @@[&_div.monaco-inputbox]:!void-outline-none`}
> >
<div className='flex flex-row justify-between items-end gap-1'> <div className='flex flex-row justify-between items-end gap-1'>
<div className='absolute size-0.5 top-0 right-4 z-[1]'> <div className='absolute size-[4px] top-0 right-4 z-[1]'>
<X <X
onClick={() => { inlineDiffsService.removeCtrlKZone({ diffareaid }) }} onClick={onX}
/> />
</div> </div>
@ -132,6 +137,12 @@ export const CtrlKChat = ({ diffareaid, onGetInputBox, onUserUpdateText, onChang
onChangeText={onChangeText} onChangeText={onChangeText}
onCreateInstance={useCallback((instance: InputBox) => { onCreateInstance={useCallback((instance: InputBox) => {
inputBoxRef.current = instance; inputBoxRef.current = instance;
// if presses the esc key, X
instance.element.addEventListener('keydown', (e) => {
if (e.key === 'Escape')
onX()
})
onGetInputBox(instance); onGetInputBox(instance);
instance.focus() instance.focus()
}, [onGetInputBox])} }, [onGetInputBox])}

View file

@ -4,9 +4,9 @@
*--------------------------------------------------------------------------------------------*/ *--------------------------------------------------------------------------------------------*/
import { mountFnGenerator } from '../util/mountFnGenerator.js' import { mountFnGenerator } from '../util/mountFnGenerator.js'
import { CtrlK } from './CtrlK.js' import { QuickEdit } from './QuickEdit.js'
export const mountCtrlK = mountFnGenerator(CtrlK) export const mountCtrlK = mountFnGenerator(QuickEdit)

View file

@ -9,7 +9,7 @@ export default defineConfig({
entry: [ entry: [
'./src2/sidebar-tsx/index.tsx', './src2/sidebar-tsx/index.tsx',
'./src2/void-settings-tsx/index.tsx', './src2/void-settings-tsx/index.tsx',
'./src2/ctrl-k-tsx/index.tsx', './src2/quick-edit-tsx/index.tsx',
'./src2/diff/index.tsx', './src2/diff/index.tsx',
], ],
outDir: './out', outDir: './out',

View file

@ -83,45 +83,45 @@ registerAction2(class extends Action2 {
) )
// select whole lines
if (selectionRange) { if (selectionRange) {
// select whole lines
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 })
}
const selectionStr = getContentInRange(model, selectionRange) const selectionStr = getContentInRange(model, selectionRange)
const selection: CodeStagingSelection = selectionStr === null || selectionRange.startLineNumber > selectionRange.endLineNumber ? { const selection: CodeStagingSelection = !selectionRange || !selectionStr || (selectionRange.startLineNumber > selectionRange.endLineNumber) ? {
type: 'File', type: 'File',
fileURI: model.uri, fileURI: model.uri,
selectionStr: null, selectionStr: null,
range: null, range: null,
} : { } : {
type: 'Selection', type: 'Selection',
fileURI: model.uri, fileURI: model.uri,
selectionStr: selectionStr, selectionStr: selectionStr,
range: selectionRange, range: selectionRange,
} }
// add selection to staging // add selection to staging
const threadHistoryService = accessor.get(IThreadHistoryService) const threadHistoryService = accessor.get(IThreadHistoryService)
const currentStaging = threadHistoryService.state._currentStagingSelections const currentStaging = threadHistoryService.state._currentStagingSelections
const currentStagingEltIdx = currentStaging?.findIndex(s => const currentStagingEltIdx = currentStaging?.findIndex(s =>
s.fileURI.fsPath === model.uri.fsPath s.fileURI.fsPath === model.uri.fsPath
&& s.range?.startLineNumber === selection.range?.startLineNumber && s.range?.startLineNumber === selection.range?.startLineNumber
&& s.range?.endLineNumber === selection.range?.endLineNumber && s.range?.endLineNumber === selection.range?.endLineNumber
) )
// if matches with existing selection, overwrite // if matches with existing selection, overwrite
if (currentStagingEltIdx !== undefined && currentStagingEltIdx !== -1) { if (currentStagingEltIdx !== undefined && currentStagingEltIdx !== -1) {
threadHistoryService.setStaging([ threadHistoryService.setStaging([
...currentStaging!.slice(0, currentStagingEltIdx), ...currentStaging!.slice(0, currentStagingEltIdx),
selection, selection,
...currentStaging!.slice(currentStagingEltIdx + 1, Infinity) ...currentStaging!.slice(currentStagingEltIdx + 1, Infinity)
]) ])
} }
// if no match, add // if no match, add
else { else {
threadHistoryService.setStaging([...(currentStaging ?? []), selection]) threadHistoryService.setStaging([...(currentStaging ?? []), selection])
}
} }
} }