mirror of
https://github.com/voideditor/void
synced 2026-05-24 09:58:23 +00:00
add codeBoxId, but now will change to uri
This commit is contained in:
parent
64ac6d4a12
commit
1079893527
4 changed files with 149 additions and 75 deletions
|
|
@ -128,13 +128,16 @@ export type StartApplyingOpts = {
|
||||||
from: 'QuickEdit';
|
from: 'QuickEdit';
|
||||||
type: 'rewrite';
|
type: 'rewrite';
|
||||||
diffareaid: number; // id of the CtrlK area (contains text selection)
|
diffareaid: number; // id of the CtrlK area (contains text selection)
|
||||||
|
chatCodeBoxId: string | null;
|
||||||
} | {
|
} | {
|
||||||
from: 'ClickApply';
|
from: 'ClickApply';
|
||||||
type: 'searchReplace' | 'rewrite';
|
type: 'searchReplace' | 'rewrite';
|
||||||
applyStr: string;
|
applyStr: string;
|
||||||
|
chatCodeBoxId: string | null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
export type AddCtrlKOpts = {
|
export type AddCtrlKOpts = {
|
||||||
startLine: number,
|
startLine: number,
|
||||||
endLine: number,
|
endLine: number,
|
||||||
|
|
@ -197,12 +200,11 @@ type DiffZone = {
|
||||||
isStreaming: true;
|
isStreaming: true;
|
||||||
streamRequestIdRef: { current: string | null };
|
streamRequestIdRef: { current: string | null };
|
||||||
line: number;
|
line: number;
|
||||||
applyBoxId?: string;
|
codeBoxId: string | null;
|
||||||
} | {
|
} | {
|
||||||
isStreaming: false;
|
isStreaming: false;
|
||||||
streamRequestIdRef?: undefined;
|
streamRequestIdRef?: undefined;
|
||||||
line?: undefined;
|
line?: undefined;
|
||||||
applyBoxId?: undefined;
|
|
||||||
};
|
};
|
||||||
editorId?: undefined;
|
editorId?: undefined;
|
||||||
linkedStreamingDiffZone?: undefined;
|
linkedStreamingDiffZone?: undefined;
|
||||||
|
|
@ -260,10 +262,10 @@ export interface IEditCodeService {
|
||||||
interruptCtrlKStreaming(opts: { diffareaid: number }): void;
|
interruptCtrlKStreaming(opts: { diffareaid: number }): void;
|
||||||
onDidChangeCtrlKZoneStreaming: Event<{ uri: URI; diffareaid: number }>;
|
onDidChangeCtrlKZoneStreaming: Event<{ uri: URI; diffareaid: number }>;
|
||||||
|
|
||||||
// // DiffZone streaming state
|
// // DiffZone codeBoxId streaming state
|
||||||
// isApplyBoxIdStreaming(opts: { applyBoxId: string }): boolean;
|
isCodeBoxIdStreaming(opts: { codeBoxId: string }): boolean;
|
||||||
// interruptApplyBoxId(opts: { applyBoxId: string }): void;
|
interruptCodeBoxId(opts: { codeBoxId: string }): void;
|
||||||
// onDidChangeApplyBoxIdStreaming: Event<{ applyBoxId: string }>;
|
onDidChangeCodeBoxIdStreaming: Event<{ codeBoxId: string }>;
|
||||||
|
|
||||||
// testDiffs(): void;
|
// testDiffs(): void;
|
||||||
}
|
}
|
||||||
|
|
@ -284,12 +286,14 @@ class EditCodeService extends Disposable implements IEditCodeService {
|
||||||
// only applies to diffZones
|
// only applies to diffZones
|
||||||
// streamingDiffZones: Set<number> = new Set()
|
// streamingDiffZones: Set<number> = new Set()
|
||||||
private readonly _onDidChangeDiffZoneStreaming = new Emitter<{ uri: URI; diffareaid: number }>();
|
private readonly _onDidChangeDiffZoneStreaming = new Emitter<{ uri: URI; diffareaid: number }>();
|
||||||
private readonly _onDidChangeCtrlKZoneStreaming = new Emitter<{ uri: URI; diffareaid: number }>();
|
private readonly _onDidAddOrDeleteDiffZones = new Emitter<{ uri: URI }>();
|
||||||
private readonly _onDidAddOrDeleteDiffZone = new Emitter<{ uri: URI }>();
|
|
||||||
|
|
||||||
onDidChangeDiffZoneStreaming = this._onDidChangeDiffZoneStreaming.event
|
private readonly _onDidChangeCtrlKZoneStreaming = new Emitter<{ uri: URI; diffareaid: number }>();
|
||||||
onDidChangeCtrlKZoneStreaming = this._onDidChangeCtrlKZoneStreaming.event
|
onDidChangeCtrlKZoneStreaming = this._onDidChangeCtrlKZoneStreaming.event
|
||||||
|
|
||||||
|
private readonly _onDidChangeCodeBoxIdStreaming = new Emitter<{ uri: URI; diffareaid: number; codeBoxId: string }>();
|
||||||
|
onDidChangeCodeBoxIdStreaming = this._onDidChangeCodeBoxIdStreaming.event
|
||||||
|
|
||||||
constructor(
|
constructor(
|
||||||
// @IHistoryService private readonly _historyService: IHistoryService, // history service is the history of pressing alt left/right
|
// @IHistoryService private readonly _historyService: IHistoryService, // history service is the history of pressing alt left/right
|
||||||
@ICodeEditorService private readonly _editorService: ICodeEditorService,
|
@ICodeEditorService private readonly _editorService: ICodeEditorService,
|
||||||
|
|
@ -342,7 +346,17 @@ class EditCodeService extends Disposable implements IEditCodeService {
|
||||||
}
|
}
|
||||||
|
|
||||||
this._register(this._onDidChangeDiffZoneStreaming.event(({ uri: uri_ }) => { if (uri_.fsPath === model.uri.fsPath) updateAcceptRejectAllUI() }))
|
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() }))
|
this._register(this._onDidAddOrDeleteDiffZones.event(({ uri: uri_ }) => { if (uri_.fsPath === model.uri.fsPath) updateAcceptRejectAllUI() }))
|
||||||
|
|
||||||
|
// codeBoxId
|
||||||
|
this._register(this._onDidChangeDiffZoneStreaming.event(({ diffareaid }) => {
|
||||||
|
const diffZone = this.diffAreaOfId[diffareaid]
|
||||||
|
if (diffZone?.type !== 'DiffZone') return
|
||||||
|
if (!diffZone._streamState.isStreaming) return
|
||||||
|
const { codeBoxId } = diffZone._streamState
|
||||||
|
if (codeBoxId === null) return
|
||||||
|
this._onDidChangeCodeBoxIdStreaming.fire({ uri: model.uri, codeBoxId, diffareaid })
|
||||||
|
}))
|
||||||
|
|
||||||
}
|
}
|
||||||
// initialize all existing models + initialize when a new model mounts
|
// initialize all existing models + initialize when a new model mounts
|
||||||
|
|
@ -864,7 +878,7 @@ class EditCodeService extends Disposable implements IEditCodeService {
|
||||||
}
|
}
|
||||||
this.diffAreasOfURI[uri.fsPath].add(diffareaid)
|
this.diffAreasOfURI[uri.fsPath].add(diffareaid)
|
||||||
}
|
}
|
||||||
this._onDidAddOrDeleteDiffZone.fire({ uri })
|
this._onDidAddOrDeleteDiffZones.fire({ uri })
|
||||||
|
|
||||||
// restore file content
|
// restore file content
|
||||||
const numLines = this._getNumLines(uri)
|
const numLines = this._getNumLines(uri)
|
||||||
|
|
@ -934,7 +948,7 @@ class EditCodeService extends Disposable implements IEditCodeService {
|
||||||
this._clearAllDiffAreaEffects(diffZone)
|
this._clearAllDiffAreaEffects(diffZone)
|
||||||
delete this.diffAreaOfId[diffZone.diffareaid]
|
delete this.diffAreaOfId[diffZone.diffareaid]
|
||||||
this.diffAreasOfURI[diffZone._URI.fsPath].delete(diffZone.diffareaid.toString())
|
this.diffAreasOfURI[diffZone._URI.fsPath].delete(diffZone.diffareaid.toString())
|
||||||
this._onDidAddOrDeleteDiffZone.fire({ uri: diffZone._URI })
|
this._onDidAddOrDeleteDiffZones.fire({ uri: diffZone._URI })
|
||||||
}
|
}
|
||||||
|
|
||||||
private _deleteTrackingZone(trackingZone: TrackingZone<unknown>) {
|
private _deleteTrackingZone(trackingZone: TrackingZone<unknown>) {
|
||||||
|
|
@ -1252,7 +1266,7 @@ class EditCodeService extends Disposable implements IEditCodeService {
|
||||||
|
|
||||||
private _initializeWriteoverStream(opts: StartApplyingOpts): DiffZone | undefined {
|
private _initializeWriteoverStream(opts: StartApplyingOpts): DiffZone | undefined {
|
||||||
|
|
||||||
const { from } = opts
|
const { from, chatCodeBoxId } = opts
|
||||||
|
|
||||||
let startLine: number
|
let startLine: number
|
||||||
let endLine: number
|
let endLine: number
|
||||||
|
|
@ -1312,13 +1326,14 @@ class EditCodeService extends Disposable implements IEditCodeService {
|
||||||
isStreaming: true,
|
isStreaming: true,
|
||||||
streamRequestIdRef,
|
streamRequestIdRef,
|
||||||
line: startLine,
|
line: startLine,
|
||||||
|
codeBoxId: chatCodeBoxId,
|
||||||
},
|
},
|
||||||
_diffOfId: {}, // added later
|
_diffOfId: {}, // added later
|
||||||
_removeStylesFns: new Set(),
|
_removeStylesFns: new Set(),
|
||||||
}
|
}
|
||||||
const diffZone = this._addDiffArea(adding)
|
const diffZone = this._addDiffArea(adding)
|
||||||
this._onDidChangeDiffZoneStreaming.fire({ uri, diffareaid: diffZone.diffareaid })
|
this._onDidChangeDiffZoneStreaming.fire({ uri, diffareaid: diffZone.diffareaid })
|
||||||
this._onDidAddOrDeleteDiffZone.fire({ uri })
|
this._onDidAddOrDeleteDiffZones.fire({ uri })
|
||||||
|
|
||||||
if (from === 'QuickEdit') {
|
if (from === 'QuickEdit') {
|
||||||
const { diffareaid } = opts
|
const { diffareaid } = opts
|
||||||
|
|
@ -1436,7 +1451,8 @@ class EditCodeService extends Disposable implements IEditCodeService {
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
private _initializeSearchAndReplaceStream({ applyStr }: { applyStr: string }) {
|
private _initializeSearchAndReplaceStream(opts: StartApplyingOpts & { from: 'ClickApply' }) {
|
||||||
|
const { applyStr, chatCodeBoxId } = opts
|
||||||
|
|
||||||
const uri_ = this._getActiveEditorURI()
|
const uri_ = this._getActiveEditorURI()
|
||||||
if (!uri_) return
|
if (!uri_) return
|
||||||
|
|
@ -1485,13 +1501,14 @@ class EditCodeService extends Disposable implements IEditCodeService {
|
||||||
isStreaming: true,
|
isStreaming: true,
|
||||||
streamRequestIdRef,
|
streamRequestIdRef,
|
||||||
line: startLine,
|
line: startLine,
|
||||||
|
codeBoxId: chatCodeBoxId,
|
||||||
},
|
},
|
||||||
_diffOfId: {}, // added later
|
_diffOfId: {}, // added later
|
||||||
_removeStylesFns: new Set(),
|
_removeStylesFns: new Set(),
|
||||||
}
|
}
|
||||||
const diffZone = this._addDiffArea(adding)
|
const diffZone = this._addDiffArea(adding)
|
||||||
this._onDidChangeDiffZoneStreaming.fire({ uri, diffareaid: diffZone.diffareaid })
|
this._onDidChangeDiffZoneStreaming.fire({ uri, diffareaid: diffZone.diffareaid })
|
||||||
this._onDidAddOrDeleteDiffZone.fire({ uri })
|
this._onDidAddOrDeleteDiffZones.fire({ uri })
|
||||||
|
|
||||||
|
|
||||||
const revertAndContinueHistory = () => {
|
const revertAndContinueHistory = () => {
|
||||||
|
|
@ -1729,12 +1746,16 @@ class EditCodeService extends Disposable implements IEditCodeService {
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
isDiffZoneStreaming({ diffareaid }: { diffareaid: number }) {
|
_interruptDiffZoneStreaming({ diffareaid }: { diffareaid: number }) {
|
||||||
const diffZone = this.diffAreaOfId[diffareaid]
|
const diffZone = this.diffAreaOfId[diffareaid]
|
||||||
if (diffZone?.type !== 'DiffZone') return false
|
if (diffZone?.type !== 'DiffZone') return
|
||||||
return diffZone._streamState.isStreaming
|
if (!diffZone._streamState.isStreaming) return
|
||||||
|
|
||||||
|
this._stopIfStreaming(diffZone)
|
||||||
|
this._undoHistory(diffZone._URI)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
isCtrlKZoneStreaming({ diffareaid }: { diffareaid: number }) {
|
isCtrlKZoneStreaming({ diffareaid }: { diffareaid: number }) {
|
||||||
const ctrlKZone = this.diffAreaOfId[diffareaid]
|
const ctrlKZone = this.diffAreaOfId[diffareaid]
|
||||||
if (!ctrlKZone) return false
|
if (!ctrlKZone) return false
|
||||||
|
|
@ -1743,15 +1764,6 @@ class EditCodeService extends Disposable implements IEditCodeService {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
interruptDiffZoneStreaming({ diffareaid }: { diffareaid: number }) {
|
|
||||||
const diffZone = this.diffAreaOfId[diffareaid]
|
|
||||||
if (diffZone?.type !== 'DiffZone') return
|
|
||||||
if (!diffZone._streamState.isStreaming) return
|
|
||||||
|
|
||||||
this._stopIfStreaming(diffZone)
|
|
||||||
this._undoHistory(diffZone._URI)
|
|
||||||
}
|
|
||||||
|
|
||||||
// diffareaid of the ctrlKZone (even though the stream state is dictated by the linked diffZone)
|
// diffareaid of the ctrlKZone (even though the stream state is dictated by the linked diffZone)
|
||||||
interruptCtrlKStreaming({ diffareaid }: { diffareaid: number }) {
|
interruptCtrlKStreaming({ diffareaid }: { diffareaid: number }) {
|
||||||
const ctrlKZone = this.diffAreaOfId[diffareaid]
|
const ctrlKZone = this.diffAreaOfId[diffareaid]
|
||||||
|
|
@ -1762,11 +1774,37 @@ class EditCodeService extends Disposable implements IEditCodeService {
|
||||||
if (!linkedStreamingDiffZone) return
|
if (!linkedStreamingDiffZone) return
|
||||||
if (linkedStreamingDiffZone.type !== 'DiffZone') return
|
if (linkedStreamingDiffZone.type !== 'DiffZone') return
|
||||||
|
|
||||||
this.interruptDiffZoneStreaming({ diffareaid: linkedStreamingDiffZone.diffareaid })
|
this._interruptDiffZoneStreaming({ diffareaid: linkedStreamingDiffZone.diffareaid })
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
isCodeBoxIdStreaming({ codeBoxId }: { codeBoxId: string }) {
|
||||||
|
// brute force is OK for now
|
||||||
|
for (const diffareaid in this.diffAreaOfId) {
|
||||||
|
const diffArea = this.diffAreaOfId[diffareaid]
|
||||||
|
if (!diffArea) continue
|
||||||
|
if (diffArea.type !== 'DiffZone') continue
|
||||||
|
if (!diffArea._streamState.isStreaming) continue
|
||||||
|
if (diffArea._streamState.codeBoxId === codeBoxId) return true
|
||||||
|
}
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
interruptCodeBoxId({ codeBoxId }: { codeBoxId: string }) {
|
||||||
|
// brute force for now is OK
|
||||||
|
for (const diffareaid in this.diffAreaOfId) {
|
||||||
|
const diffArea = this.diffAreaOfId[diffareaid]
|
||||||
|
if (!diffArea) continue
|
||||||
|
if (diffArea.type !== 'DiffZone') continue
|
||||||
|
if (!diffArea._streamState.isStreaming) continue
|
||||||
|
if (diffArea._streamState.codeBoxId === codeBoxId) {
|
||||||
|
this._interruptDiffZoneStreaming({ diffareaid: diffArea.diffareaid })
|
||||||
|
return
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
// public removeDiffZone(diffZone: DiffZone, behavior: 'reject' | 'accept') {
|
// public removeDiffZone(diffZone: DiffZone, behavior: 'reject' | 'accept') {
|
||||||
// const uri = diffZone._URI
|
// const uri = diffZone._URI
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,5 @@
|
||||||
import { useState, useEffect, useCallback } from 'react'
|
import { useState, useEffect, useCallback } from 'react'
|
||||||
import { useAccessor, useIsDiffZoneStreaming } from '../util/services.js'
|
import { useAccessor, useCodeBoxIdStreamingState, useSettingsState } from '../util/services.js'
|
||||||
import { useRefState } from '../util/helpers.js'
|
import { useRefState } from '../util/helpers.js'
|
||||||
import { isFeatureNameDisabled } from '../../../../common/voidSettingsTypes.js'
|
import { isFeatureNameDisabled } from '../../../../common/voidSettingsTypes.js'
|
||||||
|
|
||||||
|
|
@ -44,54 +44,35 @@ const CopyButton = ({ codeStr }: { codeStr: string }) => {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
const useStreamStateRef = ({ codeBoxId }: { codeBoxId: string | null }) => {
|
||||||
|
const accessor = useAccessor()
|
||||||
|
const editCodeService = accessor.get('IEditCodeService')
|
||||||
|
const [isStreamingRef, setIsStreamingRef] = useRefState(editCodeService.isCodeBoxIdStreaming({ codeBoxId }))
|
||||||
|
useCodeBoxIdStreamingState(useCallback((codeBoxId2, isStreaming) => {
|
||||||
|
if (codeBoxId !== codeBoxId2) return
|
||||||
|
setIsStreamingRef(isStreaming)
|
||||||
|
}, [codeBoxId, setIsStreamingRef]))
|
||||||
|
return [isStreamingRef, setIsStreamingRef] as const
|
||||||
|
}
|
||||||
|
|
||||||
const ApplyButton = ({ codeStr, codeBoxId }: { codeStr: string, codeBoxId: string }) => {
|
|
||||||
|
|
||||||
|
const StopButton = ({ codeBoxId }: { codeBoxId: string }) => {
|
||||||
const accessor = useAccessor()
|
const accessor = useAccessor()
|
||||||
|
|
||||||
const editCodeService = accessor.get('IEditCodeService')
|
const editCodeService = accessor.get('IEditCodeService')
|
||||||
const metricsService = accessor.get('IMetricsService')
|
const metricsService = accessor.get('IMetricsService')
|
||||||
|
|
||||||
|
const settingsState = useSettingsState()
|
||||||
|
|
||||||
// const isStreaming = useIsDiffZoneStreaming(isDiffAreaStreaming)
|
const [isStreamingRef, _] = useStreamStateRef({ codeBoxId })
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// const onSubmit = useCallback(() => {
|
|
||||||
|
|
||||||
// const uri = editCodeService.startApplying({
|
|
||||||
// from: 'ClickApply',
|
|
||||||
// type: 'searchReplace',
|
|
||||||
// applyStr: codeStr,
|
|
||||||
// })
|
|
||||||
|
|
||||||
// metricsService.capture('Apply Code', { length: codeStr.length }) // capture the length only
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// if (isStreaming) return
|
|
||||||
|
|
||||||
// setCurrentlyStreamingDiffZone(id ?? null)
|
|
||||||
// }, [isStreaming, editCodeService])
|
|
||||||
|
|
||||||
// const onInterrupt = useCallback(() => {
|
|
||||||
// if (currStreamingDiffZoneRef.current === null) return
|
|
||||||
// editCodeService.interruptStreaming(currStreamingDiffZoneRef.current)
|
|
||||||
// setCurrentlyStreamingDiffZone(null)
|
|
||||||
// textAreaFnsRef.current?.enable()
|
|
||||||
// }, [isStreaming, editCodeService])
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
const isSingleLine = !codeStr.includes('\n')
|
|
||||||
|
|
||||||
return <button
|
return <button
|
||||||
// btn btn-secondary btn-sm border text-sm border-vscode-input-border rounded
|
// btn btn-secondary btn-sm border text-sm border-vscode-input-border rounded
|
||||||
className={`${isSingleLine ? '' : 'px-1 py-0.5'} text-sm bg-void-bg-1 text-void-fg-1 hover:brightness-110 border border-vscode-input-border rounded`}
|
className={`${isSingleLine ? '' : 'px-1 py-0.5'} text-sm bg-void-bg-1 text-void-fg-1 hover:brightness-110 border border-vscode-input-border rounded`}
|
||||||
// onClick={onApply}
|
onClick={onInterrupt}
|
||||||
>
|
>
|
||||||
Apply
|
Apply
|
||||||
</button>
|
</button>
|
||||||
|
|
@ -103,8 +84,57 @@ const ApplyButton = ({ codeStr, codeBoxId }: { codeStr: string, codeBoxId: strin
|
||||||
|
|
||||||
|
|
||||||
export const ApplyBlockHoverButtons = ({ codeStr, codeBoxId }: { codeStr: string, codeBoxId: string | null }) => {
|
export const ApplyBlockHoverButtons = ({ codeStr, codeBoxId }: { codeStr: string, codeBoxId: string | null }) => {
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
const accessor = useAccessor()
|
||||||
|
|
||||||
|
const editCodeService = accessor.get('IEditCodeService')
|
||||||
|
const metricsService = accessor.get('IMetricsService')
|
||||||
|
|
||||||
|
const settingsState = useSettingsState()
|
||||||
|
|
||||||
|
const isDisabled = !!isFeatureNameDisabled('Apply', settingsState)
|
||||||
|
|
||||||
|
const [isStreamingRef, _] = useStreamStateRef({ codeBoxId })
|
||||||
|
|
||||||
|
const onSubmit = useCallback(() => {
|
||||||
|
if (isDisabled) return
|
||||||
|
if (isStreamingRef.current) return
|
||||||
|
editCodeService.startApplying({
|
||||||
|
from: 'ClickApply',
|
||||||
|
type: 'searchReplace',
|
||||||
|
applyStr: codeStr,
|
||||||
|
chatCodeBoxId: codeBoxId,
|
||||||
|
})
|
||||||
|
metricsService.capture('Apply Code', { length: codeStr.length }) // capture the length only
|
||||||
|
}, [isStreamingRef, editCodeService, codeBoxId, codeStr, metricsService])
|
||||||
|
|
||||||
|
|
||||||
|
const onInterrupt = useCallback(() => {
|
||||||
|
if (isStreamingRef.current) return
|
||||||
|
if (codeBoxId === null) return
|
||||||
|
editCodeService.interruptCodeBoxId({ codeBoxId, })
|
||||||
|
metricsService.capture('Stop Apply', {})
|
||||||
|
}, [isStreamingRef, editCodeService, codeBoxId, metricsService])
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
const isSingleLine = !codeStr.includes('\n')
|
||||||
|
|
||||||
|
const applyButton = <button
|
||||||
|
// btn btn-secondary btn-sm border text-sm border-vscode-input-border rounded
|
||||||
|
className={`${isSingleLine ? '' : 'px-1 py-0.5'} text-sm bg-void-bg-1 text-void-fg-1 hover:brightness-110 border border-vscode-input-border rounded`}
|
||||||
|
onClick={onSubmit}
|
||||||
|
>
|
||||||
|
Apply
|
||||||
|
</button>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
return <>
|
return <>
|
||||||
<CopyButton codeStr={codeStr} />
|
{!isStreamingRef.current && <CopyButton codeStr={codeStr} />}
|
||||||
{codeBoxId !== null && <ApplyButton codeBoxId={codeBoxId} codeStr={codeStr} />}
|
{!isStreamingRef.current && codeBoxId !== null && <ApplyButton codeBoxId={codeBoxId} codeStr={codeStr} />}
|
||||||
|
{!isStreamingRef.current && <StopButton codeStr={codeStr} />}
|
||||||
</>
|
</>
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -65,6 +65,7 @@ export const QuickEditChat = ({
|
||||||
from: 'QuickEdit',
|
from: 'QuickEdit',
|
||||||
type: 'rewrite',
|
type: 'rewrite',
|
||||||
diffareaid,
|
diffareaid,
|
||||||
|
chatCodeBoxId: null,
|
||||||
})
|
})
|
||||||
}, [isStreamingRef, isDisabled, editCodeService, diffareaid])
|
}, [isStreamingRef, isDisabled, editCodeService, diffareaid])
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -76,9 +76,7 @@ let colorThemeState: ColorScheme
|
||||||
const colorThemeStateListeners: Set<(s: ColorScheme) => void> = new Set()
|
const colorThemeStateListeners: Set<(s: ColorScheme) => void> = new Set()
|
||||||
|
|
||||||
const ctrlKZoneStreamingStateListeners: Set<(diffareaid: number, s: boolean) => void> = new Set()
|
const ctrlKZoneStreamingStateListeners: Set<(diffareaid: number, s: boolean) => void> = new Set()
|
||||||
|
const codeBoxIdStreamingStateListeners: Set<(codeBoxId: string, s: boolean) => void> = new Set()
|
||||||
let diffZoneStreamingState: Record<string, boolean>
|
|
||||||
const diffZoneStreamingStateListeners: Set<(diffareaid: number, state: boolean) => void> = new Set()
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -184,6 +182,12 @@ export const _registerServices = (accessor: ServicesAccessor) => {
|
||||||
ctrlKZoneStreamingStateListeners.forEach(l => l(diffareaid, isStreaming))
|
ctrlKZoneStreamingStateListeners.forEach(l => l(diffareaid, isStreaming))
|
||||||
})
|
})
|
||||||
)
|
)
|
||||||
|
disposables.push(
|
||||||
|
editCodeService.onDidChangeCodeBoxIdStreaming(({ codeBoxId }) => {
|
||||||
|
const isStreaming = editCodeService.isCodeBoxIdStreaming({ codeBoxId })
|
||||||
|
codeBoxIdStreamingStateListeners.forEach(l => l(codeBoxId, isStreaming))
|
||||||
|
})
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -351,7 +355,6 @@ export const useRefreshModelListener = (listener: (providerName: RefreshableProv
|
||||||
}, [listener, refreshModelProviderListeners])
|
}, [listener, refreshModelProviderListeners])
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
export const useCtrlKZoneStreamingState = (listener: (diffareaid: number, s: boolean) => void) => {
|
export const useCtrlKZoneStreamingState = (listener: (diffareaid: number, s: boolean) => void) => {
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
ctrlKZoneStreamingStateListeners.add(listener)
|
ctrlKZoneStreamingStateListeners.add(listener)
|
||||||
|
|
@ -359,16 +362,18 @@ export const useCtrlKZoneStreamingState = (listener: (diffareaid: number, s: boo
|
||||||
}, [listener, ctrlKZoneStreamingStateListeners])
|
}, [listener, ctrlKZoneStreamingStateListeners])
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export const useCodeBoxIdStreamingState = (listener: (codeBoxId: string, s: boolean) => void) => {
|
||||||
export const useIsDiffZoneStreaming = (diffareaid: number) => {
|
useEffect(() => {
|
||||||
return { current: true }
|
codeBoxIdStreamingStateListeners.add(listener)
|
||||||
|
return () => { codeBoxIdStreamingStateListeners.delete(listener) }
|
||||||
|
}, [listener, codeBoxIdStreamingStateListeners])
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
export const useIsDark = () => {
|
export const useIsDark = () => {
|
||||||
const [s, ss] = useState(colorThemeState)
|
const [s, ss] = useState(colorThemeState)
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue