refactor(host): share the composition guard between the browser's two inputs

The path editor and the folder-name input carried identical inline IME
handlers — the cross-file clone jscpd flagged against WorkspacePicker; one
component-level guard object serves both.
This commit is contained in:
creatixchu
2026-07-29 00:22:32 +08:00
parent f8cd2bf749
commit 99a8795aa4

View File

@@ -121,8 +121,13 @@ export function DirectoryBrowser({ open, listDirectory, createDirectory, onOpen,
// and the edit zone beside it) in view whenever the chain changes. // and the edit zone beside it) in view whenever the chain changes.
const crumbTrailRef = useRef<HTMLSpanElement | null>(null) const crumbTrailRef = useRef<HTMLSpanElement | null>(null)
// IME confirmation (Enter selecting a candidate) must not submit either // IME confirmation (Enter selecting a candidate) must not submit either
// text input; the same guard the workspace-name inputs carry. // text input; the same guard the workspace-name inputs carry, shared by
// the path editor and the folder-name input.
const composingRef = useRef(false) const composingRef = useRef(false)
const compositionGuard = {
onCompositionStart: () => { composingRef.current = true },
onCompositionEnd: () => { composingRef.current = false },
}
/** Replace the whole view with one freshly listed level (no selection). */ /** Replace the whole view with one freshly listed level (no selection). */
const navigate = useCallback((path?: string) => { const navigate = useCallback((path?: string) => {
@@ -305,8 +310,7 @@ export function DirectoryBrowser({ open, listDirectory, createDirectory, onOpen,
autoFocus autoFocus
disabled={parentInert} disabled={parentInert}
onChange={(event) => { setPathDraft(event.target.value) }} onChange={(event) => { setPathDraft(event.target.value) }}
onCompositionStart={() => { composingRef.current = true }} {...compositionGuard}
onCompositionEnd={() => { composingRef.current = false }}
onKeyDown={(event) => { onKeyDown={(event) => {
if (event.key === 'Enter' && !composingRef.current) { if (event.key === 'Enter' && !composingRef.current) {
event.preventDefault() event.preventDefault()
@@ -391,8 +395,7 @@ export function DirectoryBrowser({ open, listDirectory, createDirectory, onOpen,
autoFocus autoFocus
disabled={creatingFolder} disabled={creatingFolder}
onChange={(event) => { setFolderDraft(event.target.value) }} onChange={(event) => { setFolderDraft(event.target.value) }}
onCompositionStart={() => { composingRef.current = true }} {...compositionGuard}
onCompositionEnd={() => { composingRef.current = false }}
onKeyDown={(event) => { onKeyDown={(event) => {
if (event.key === 'Enter' && !composingRef.current) { if (event.key === 'Enter' && !composingRef.current) {
event.preventDefault() event.preventDefault()