mirror of
https://github.com/voideditor/void
synced 2026-05-24 09:58:23 +00:00
fix react - tedious
This commit is contained in:
parent
ea10765abd
commit
2ecce822f3
2 changed files with 31 additions and 32 deletions
|
|
@ -3,6 +3,7 @@ import { useAccessor, useURIStreamState, useSettingsState } from '../util/servic
|
||||||
import { useRefState } from '../util/helpers.js'
|
import { useRefState } from '../util/helpers.js'
|
||||||
import { isFeatureNameDisabled } from '../../../../common/voidSettingsTypes.js'
|
import { isFeatureNameDisabled } from '../../../../common/voidSettingsTypes.js'
|
||||||
import { URI } from '../../../../../../../base/common/uri.js'
|
import { URI } from '../../../../../../../base/common/uri.js'
|
||||||
|
import { IEditCodeService, URIStreamState } from '../../../editCodeService.js'
|
||||||
|
|
||||||
enum CopyButtonText {
|
enum CopyButtonText {
|
||||||
Idle = 'Copy',
|
Idle = 'Copy',
|
||||||
|
|
@ -52,6 +53,7 @@ const CopyButton = ({ codeStr }: { codeStr: string }) => {
|
||||||
const applyingURIOfApplyBoxIdRef: { current: { [applyBoxId: string]: URI | undefined } } = { current: {} }
|
const applyingURIOfApplyBoxIdRef: { current: { [applyBoxId: string]: URI | undefined } } = { current: {} }
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
export const ApplyBlockHoverButtons = ({ codeStr, applyBoxId }: { codeStr: string, applyBoxId: string }) => {
|
export const ApplyBlockHoverButtons = ({ codeStr, applyBoxId }: { codeStr: string, applyBoxId: string }) => {
|
||||||
|
|
||||||
console.log('applyboxid', applyBoxId, applyingURIOfApplyBoxIdRef)
|
console.log('applyboxid', applyBoxId, applyingURIOfApplyBoxIdRef)
|
||||||
|
|
@ -63,46 +65,43 @@ export const ApplyBlockHoverButtons = ({ codeStr, applyBoxId }: { codeStr: strin
|
||||||
const editCodeService = accessor.get('IEditCodeService')
|
const editCodeService = accessor.get('IEditCodeService')
|
||||||
const metricsService = accessor.get('IMetricsService')
|
const metricsService = accessor.get('IMetricsService')
|
||||||
|
|
||||||
const [applyingUriRef, setApplyingUri_] = useRefState(applyingURIOfApplyBoxIdRef.current[applyBoxId] ?? null)
|
const [_, rerender] = useState(0)
|
||||||
const [streamStateRef, setStreamState_] = useRefState(editCodeService.getURIStreamState({ uri: applyingUriRef.current ?? null }))
|
|
||||||
|
|
||||||
const setApplyingUri = useCallback((uri: URI | null) => { // switched the box's URI to whatever they clicked on most recently
|
const applyingUri = useCallback(() => applyingURIOfApplyBoxIdRef.current[applyBoxId] ?? null, [applyBoxId])
|
||||||
setApplyingUri_(uri)
|
const streamState = useCallback(() => editCodeService.getURIStreamState({ uri: applyingUri() }), [editCodeService, applyingUri])
|
||||||
const newStreamState = editCodeService.getURIStreamState({ uri })
|
|
||||||
if (uri) applyingURIOfApplyBoxIdRef.current[applyBoxId] = uri
|
|
||||||
setStreamState_(newStreamState)
|
|
||||||
}, [applyBoxId, setApplyingUri_, editCodeService, setStreamState_])
|
|
||||||
|
|
||||||
// listen for stream updates
|
// listen for stream updates
|
||||||
useURIStreamState(
|
useURIStreamState(
|
||||||
useCallback((uri, streamState) => {
|
useCallback((uri, newStreamState) => {
|
||||||
const shouldUpdate = applyingUriRef.current?.fsPath === uri.fsPath
|
const shouldUpdate = applyingUri()?.fsPath !== uri.fsPath
|
||||||
if (!shouldUpdate) return
|
if (shouldUpdate) return
|
||||||
setStreamState_(streamState) // editCodeService.getURIStreamState({ uri: applyingUriRef.current ?? null })
|
rerender(c => c + 1)
|
||||||
}, [applyingUriRef, setStreamState_])
|
if (newStreamState !== streamState()) console.log('AAAAAAAAAAAAAAAAAAA')
|
||||||
|
}, [applyBoxId, editCodeService, applyingUri, rerender, streamState])
|
||||||
)
|
)
|
||||||
|
|
||||||
const onSubmit = useCallback(() => {
|
const onSubmit = useCallback(() => {
|
||||||
if (isDisabled) return
|
if (isDisabled) return
|
||||||
if (streamStateRef.current === 'streaming') return
|
if (streamState() === 'streaming') return
|
||||||
const uri = editCodeService.startApplying({
|
const newApplyingUri = editCodeService.startApplying({
|
||||||
from: 'ClickApply',
|
from: 'ClickApply',
|
||||||
type: 'searchReplace',
|
type: 'searchReplace',
|
||||||
applyStr: codeStr,
|
applyStr: codeStr,
|
||||||
chatApplyBoxId: applyBoxId,
|
|
||||||
})
|
})
|
||||||
setApplyingUri(uri)
|
applyingURIOfApplyBoxIdRef.current[applyBoxId] = newApplyingUri ?? undefined
|
||||||
|
rerender(c => c + 1)
|
||||||
metricsService.capture('Apply Code', { length: codeStr.length }) // capture the length only
|
metricsService.capture('Apply Code', { length: codeStr.length }) // capture the length only
|
||||||
}, [editCodeService, applyBoxId, codeStr, metricsService, isDisabled, streamStateRef, setApplyingUri])
|
}, [isDisabled, streamState, editCodeService, codeStr, applyBoxId, metricsService])
|
||||||
|
|
||||||
|
|
||||||
const onInterrupt = useCallback(() => {
|
const onInterrupt = useCallback(() => {
|
||||||
if (streamStateRef.current !== 'streaming') return
|
if (streamState() !== 'streaming') return
|
||||||
if (!applyingUriRef.current) return
|
const uri = applyingUri()
|
||||||
|
if (!uri) return
|
||||||
|
|
||||||
editCodeService.interruptURIStreaming({ uri: applyingUriRef.current, })
|
editCodeService.interruptURIStreaming({ uri })
|
||||||
metricsService.capture('Stop Apply', {})
|
metricsService.capture('Stop Apply', {})
|
||||||
}, [editCodeService, metricsService, streamStateRef, applyingUriRef])
|
}, [streamState, applyingUri,editCodeService, metricsService])
|
||||||
|
|
||||||
|
|
||||||
const isSingleLine = !codeStr.includes('\n')
|
const isSingleLine = !codeStr.includes('\n')
|
||||||
|
|
@ -128,8 +127,8 @@ export const ApplyBlockHoverButtons = ({ codeStr, applyBoxId }: { codeStr: strin
|
||||||
// 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={() => {
|
onClick={() => {
|
||||||
if (!applyingUriRef.current) return
|
const uri = applyingUri()
|
||||||
editCodeService.removeDiffAreas({ uri: applyingUriRef.current, behavior: 'accept', removeCtrlKs: false })
|
if (uri) editCodeService.removeDiffAreas({ uri, behavior: 'accept', removeCtrlKs: false })
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
Accept
|
Accept
|
||||||
|
|
@ -138,20 +137,21 @@ export const ApplyBlockHoverButtons = ({ codeStr, applyBoxId }: { codeStr: strin
|
||||||
// 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={() => {
|
onClick={() => {
|
||||||
if (!applyingUriRef.current) return
|
const uri = applyingUri()
|
||||||
editCodeService.removeDiffAreas({ uri: applyingUriRef.current, behavior: 'reject', removeCtrlKs: false })
|
if (uri) editCodeService.removeDiffAreas({ uri, behavior: 'reject', removeCtrlKs: false })
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
Reject
|
Reject
|
||||||
</button>
|
</button>
|
||||||
</>
|
</>
|
||||||
|
|
||||||
console.log('streamStateRef.current', streamStateRef.current)
|
console.log('streamStateRef.current', streamState())
|
||||||
|
|
||||||
|
const currStreamState = streamState()
|
||||||
return <>
|
return <>
|
||||||
{streamStateRef.current !== 'streaming' && <CopyButton codeStr={codeStr} />}
|
{currStreamState !== 'streaming' && <CopyButton codeStr={codeStr} />}
|
||||||
{streamStateRef.current === 'idle' && !isDisabled && applyButton}
|
{currStreamState === 'idle' && !isDisabled && applyButton}
|
||||||
{streamStateRef.current === 'streaming' && stopButton}
|
{currStreamState === 'streaming' && stopButton}
|
||||||
{streamStateRef.current === 'acceptRejectAll' && acceptRejectButtons}
|
{currStreamState === 'acceptRejectAll' && acceptRejectButtons}
|
||||||
</>
|
</>
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -65,7 +65,6 @@ export const QuickEditChat = ({
|
||||||
from: 'QuickEdit',
|
from: 'QuickEdit',
|
||||||
type: 'rewrite',
|
type: 'rewrite',
|
||||||
diffareaid,
|
diffareaid,
|
||||||
chatApplyBoxId: null,
|
|
||||||
})
|
})
|
||||||
}, [isStreamingRef, isDisabled, editCodeService, diffareaid])
|
}, [isStreamingRef, isDisabled, editCodeService, diffareaid])
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue