Просмотр исходного кода

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.
creatixchu 2 месяцев назад
Родитель
Сommit
99a8795aa4
1 измененных файлов с 8 добавлено и 5 удалено
  1. 8 5
      packages/host/directory-picker-browse/src/client/DirectoryBrowser.tsx

+ 8 - 5
packages/host/directory-picker-browse/src/client/DirectoryBrowser.tsx

@@ -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 }}
-                onCompositionEnd={() => { composingRef.current = false }}
+                {...compositionGuard}
                 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 }}
-            onCompositionEnd={() => { composingRef.current = false }}
+            {...compositionGuard}
             onKeyDown={(event) => {
             onKeyDown={(event) => {
               if (event.key === 'Enter' && !composingRef.current) {
               if (event.key === 'Enter' && !composingRef.current) {
                 event.preventDefault()
                 event.preventDefault()