mirror of
https://github.com/voideditor/void
synced 2026-05-24 09:58:23 +00:00
ctrlK
This commit is contained in:
parent
9005de65a6
commit
64ac6d4a12
3 changed files with 14 additions and 22 deletions
|
|
@ -287,8 +287,6 @@ class EditCodeService extends Disposable implements IEditCodeService {
|
|||
private readonly _onDidChangeCtrlKZoneStreaming = new Emitter<{ uri: URI; diffareaid: number }>();
|
||||
private readonly _onDidAddOrDeleteDiffZone = new Emitter<{ uri: URI }>();
|
||||
|
||||
private readonly _onDidChangeAcceptRejectAllState = new Emitter<{ uri: URI, state: AcceptRejectAllState }>(); // was going to be used, but decided not to
|
||||
|
||||
onDidChangeDiffZoneStreaming = this._onDidChangeDiffZoneStreaming.event
|
||||
onDidChangeCtrlKZoneStreaming = this._onDidChangeCtrlKZoneStreaming.event
|
||||
|
||||
|
|
@ -325,19 +323,9 @@ class EditCodeService extends Disposable implements IEditCodeService {
|
|||
})
|
||||
)
|
||||
|
||||
// add the accept|reject UI here
|
||||
let removeAcceptRejectAllUI: (() => void) | null = null
|
||||
this._register(this._onDidChangeAcceptRejectAllState.event(({ uri, state }) => {
|
||||
if (state === 'acceptRejectAll' && !removeAcceptRejectAllUI) {
|
||||
removeAcceptRejectAllUI = this._addAcceptRejectAllUI(uri) ?? null
|
||||
} else {
|
||||
removeAcceptRejectAllUI?.()
|
||||
removeAcceptRejectAllUI = null
|
||||
}
|
||||
}))
|
||||
|
||||
// when a stream starts or ends
|
||||
const changeUriState = () => {
|
||||
// when a stream starts or ends, add/remove the accept|reject UI
|
||||
let _removeAcceptRejectAllUI: (() => void) | null = null
|
||||
const updateAcceptRejectAllUI = () => {
|
||||
const uri = model.uri
|
||||
const diffZones = [...this.diffAreasOfURI[uri.fsPath].values()]
|
||||
.map(diffareaid => this.diffAreaOfId[diffareaid])
|
||||
|
|
@ -345,12 +333,16 @@ class EditCodeService extends Disposable implements IEditCodeService {
|
|||
const isStreaming = diffZones.find(diffZone => !!diffZone._streamState.isStreaming)
|
||||
|
||||
const state: AcceptRejectAllState = isStreaming ? 'streaming' : (diffZones.length === 0 ? 'idle' : 'acceptRejectAll')
|
||||
this._onDidChangeAcceptRejectAllState.fire({ uri, state })
|
||||
if (state === 'acceptRejectAll' && !_removeAcceptRejectAllUI) {
|
||||
_removeAcceptRejectAllUI = this._addAcceptRejectAllUI(uri) ?? null
|
||||
} else {
|
||||
_removeAcceptRejectAllUI?.()
|
||||
_removeAcceptRejectAllUI = null
|
||||
}
|
||||
}
|
||||
this._register(this._onDidChangeDiffZoneStreaming.event(({ uri: uri_ }) => { if (uri_.fsPath === model.uri.fsPath) changeUriState() }))
|
||||
this._register(this._onDidAddOrDeleteDiffZone.event(({ uri: uri_ }) => { if (uri_.fsPath === model.uri.fsPath) changeUriState() }))
|
||||
|
||||
|
||||
this._register(this._onDidChangeDiffZoneStreaming.event(({ uri: uri_ }) => { if (uri_.fsPath === model.uri.fsPath) updateAcceptRejectAllUI() }))
|
||||
this._register(this._onDidAddOrDeleteDiffZone.event(({ uri: uri_ }) => { if (uri_.fsPath === model.uri.fsPath) updateAcceptRejectAllUI() }))
|
||||
|
||||
}
|
||||
// initialize all existing models + initialize when a new model mounts
|
||||
|
|
|
|||
|
|
@ -49,7 +49,7 @@ export const QuickEditChat = ({
|
|||
const isDisabled = instructionsAreEmpty || !!isFeatureNameDisabled('Ctrl+K', settingsState)
|
||||
|
||||
|
||||
const [isStreamingRef, setIsStreamingRef] = useRefState(false)
|
||||
const [isStreamingRef, setIsStreamingRef] = useRefState(editCodeService.isCtrlKZoneStreaming({ diffareaid }))
|
||||
useCtrlKZoneStreamingState(useCallback((diffareaid2, isStreaming) => {
|
||||
if (diffareaid !== diffareaid2) return
|
||||
setIsStreamingRef(isStreaming)
|
||||
|
|
|
|||
|
|
@ -348,7 +348,7 @@ export const useRefreshModelListener = (listener: (providerName: RefreshableProv
|
|||
useEffect(() => {
|
||||
refreshModelProviderListeners.add(listener)
|
||||
return () => { refreshModelProviderListeners.delete(listener) }
|
||||
}, [listener])
|
||||
}, [listener, refreshModelProviderListeners])
|
||||
}
|
||||
|
||||
|
||||
|
|
@ -356,7 +356,7 @@ export const useCtrlKZoneStreamingState = (listener: (diffareaid: number, s: boo
|
|||
useEffect(() => {
|
||||
ctrlKZoneStreamingStateListeners.add(listener)
|
||||
return () => { ctrlKZoneStreamingStateListeners.delete(listener) }
|
||||
}, [listener])
|
||||
}, [listener, ctrlKZoneStreamingStateListeners])
|
||||
}
|
||||
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue