The all-in-one local AI studio for your desktop: chat, image and video generation and a coding agent in one free, open source app. Windows and Linux. No Docker, no terminal, no cloud required.
TypeScript agentai-chatai-studioall-in-onecoding-agentdesktop-appfluximage-generationlinuxllmlocal-ailocal-llmopen-sourceprivacyself-hostedstable-diffusionuncensoreduncensored-aivideo-generationwindows
fix(settings): der Modellordner wird beim Tippen nicht mehr unter dem Cursor beschnitten
purple131019dd0d09
diff --git a/src/components/settings/SettingsPage.tsx b/src/components/settings/SettingsPage.tsxindex 334e2a46..061c43ba 100644--- a/src/components/settings/SettingsPage.tsx+++ b/src/components/settings/SettingsPage.tsx@@ -270,16 +270,6 @@ function WorkflowSection() {// Models tab stayed empty beside a folder full of models. It is read now// (lib/custom-model-dir.ts), and the copy says what it does.-/**- * How long typing has to stop before the folder is stored anyway (A14-2a).- *- * Long enough that it does not fire between two keystrokes of a typed path,- * short enough that walking away right after typing has already saved. The- * write itself is a settings update plus one model-list refresh, so a stray- * extra one costs nothing.- */-export const MODEL_DIR_SAVE_DEBOUNCE_MS = 600-export function HfDownloadPathSetting() {const override = useSettingsStore(s => s.settings.hfDownloadPathOverride)const [draft, setDraft] = useState(override)@@ -290,7 +280,17 @@ export function HfDownloadPathSetting() {// from, so the empty field can name it instead of saying "(auto-detect)"// and leaving the user to guess.const [autoDir, setAutoDir] = useState('')- useEffect(() => { setDraft(override) }, [override])+ /** Typed but not stored yet. Null means there is nothing owed. Declared+ * before the effect below because that effect asks it. */+ const pendingPath = useRef<string | null>(null)+ // The store value flows back into the box, EXCEPT while the user is in the+ // middle of typing one. A16 counter-check follow-up: with a half typed path+ // owed, a store write from anywhere would have pulled the box back to the+ // stored value under the cursor.+ useEffect(() => {+ if (pendingPath.current !== null) return+ setDraft(override)+ }, [override])// How the GGUF scan itself fared in that folder. A folder too big to finish// within the budget returns a real but partial list, and the only person who@@ -337,18 +337,25 @@ export function HfDownloadPathSetting() {// counter-check's first attempt concluded from that the folder was being// ignored, which is the reading anyone would reach.//- // Two things are added, and neither replaces the blur. A short debounce, so- // a value that has stopped changing is stored without any further gesture- // and a refresh of the list sees the folder. And a commit when the field- // goes away, so leaving the panel saves rather than discards.- const saveTimer = useRef<ReturnType<typeof setTimeout> | null>(null)- /** Typed but not stored yet. Null means there is nothing owed. */- const pendingPath = useRef<string | null>(null)-- /** Store it. Everything that saves goes through here, so cancelling the- * debounce and clearing the debt cannot be forgotten on one path. */+ // The first answer to that was a 600 ms debounce, and the follow-up+ // counter-check showed what it cost. The debounce wrote the TRIMMED value+ // into the store while the field was still being typed in, the effect above+ // pushed the store value straight back into the box, and a path with a space+ // in it lost that space mid word: "C:\Program " became "C:\Program", the+ // cursor jumped to the end, and the next keystrokes produced+ // "C:\ProgramFiles". A half typed path also reached the folder scan, which+ // then hung a red "unreachable" line under a field nobody had finished+ // filling in.+ //+ // So no timer writes anything any more. The field commits on blur, on Enter+ // and when it goes away, and the third of those is what the finding was+ // actually about: walking away from a settings field IS a blur or an+ // unmount, so nothing is lost without a clock having to guess when the user+ // is done.++ /** Store it. Everything that saves goes through here, so clearing the debt+ * cannot be forgotten on one path. */function commit(next: string) {- if (saveTimer.current) { clearTimeout(saveTimer.current); saveTimer.current = null }pendingPath.current = nullconst store = useSettingsStore.getState()if (store.settings.hfDownloadPathOverride === next) return@@ -363,28 +370,24 @@ export function HfDownloadPathSetting() {commit(next)}- /** One keystroke. The value is owed from here until something commits it. */+ /** One keystroke. Stored verbatim, trailing space and all: it is trimmed at+ * commit time and not before, so a path that is still being typed keeps the+ * space the next word needs. */function typePath(next: string) {setDraft(next)- pendingPath.current = next.trim()- if (saveTimer.current) clearTimeout(saveTimer.current)- saveTimer.current = setTimeout(() => {- saveTimer.current = null- const owed = pendingPath.current- if (owed !== null) commit(owed)- }, MODEL_DIR_SAVE_DEBOUNCE_MS)+ pendingPath.current = next}// Closing Settings or switching tabs unmounts this field. Whatever was owed// at that moment is stored, not thrown away.useEffect(() => () => {- if (saveTimer.current) clearTimeout(saveTimer.current)const owed = pendingPath.currentpendingPath.current = nullif (owed === null) returnconst store = useSettingsStore.getState()- if (store.settings.hfDownloadPathOverride === owed) return- store.updateSettings({ hfDownloadPathOverride: owed })+ const trimmed = owed.trim()+ if (store.settings.hfDownloadPathOverride === trimmed) return+ store.updateSettings({ hfDownloadPathOverride: trimmed })window.dispatchEvent(new CustomEvent('lu-models-refresh'))}, [])@@ -407,6 +410,7 @@ export function HfDownloadPathSetting() {value={draft}onChange={(e) => typePath(e.target.value)}onBlur={() => apply(draft.trim())}+ onKeyDown={(e) => { if (e.key === 'Enter') apply(draft.trim()) }}placeholder={luEngineFolderPlaceholder(autoDir)}aria-label="LU Engine folder"className="flex-1 px-2 py-1 rounded bg-transparent border border-white/8 text-[0.65rem] text-gray-700 dark:text-gray-300 font-mono focus:outline-none focus:border-white/20"diff --git a/src/components/settings/__tests__/model-folder-survives-walking-away.test.ts b/src/components/settings/__tests__/model-folder-survives-walking-away.test.tsindex cd663811..161a8c84 100644--- a/src/components/settings/__tests__/model-folder-survives-walking-away.test.ts+++ b/src/components/settings/__tests__/model-folder-survives-walking-away.test.ts@@ -9,8 +9,18 @@* ignored. It is the reading anyone would reach, and a field that keeps* showing a value it never saved has earned it.*- * Two ways to save were added and the blur was kept: a short debounce after- * typing stops, and a commit when the field is unmounted.+ * The first answer to that was a 600 ms debounce beside the blur, and the+ * follow-up counter-check showed what it cost. The debounce stored the TRIMMED+ * value while the user was still typing, the store value flowed straight back+ * into the box, and a path with a space in it lost the space mid word:+ * "C:\Program " became "C:\Program" with the cursor at the end, and typing on+ * produced "C:\ProgramFiles". The same write sent a half typed path to the+ * folder scan, which answered with a red "unreachable" line under a field+ * nobody had finished filling in.+ *+ * No timer writes anything now. Blur, Enter and unmount commit, and the third+ * is what the original finding was about: walking away from a field IS a blur+ * or an unmount.** Run: npx vitest run src/components/settings/__tests__/model-folder-survives-walking-away.test.ts*/@@ -18,6 +28,8 @@ import { describe, it, expect, beforeEach, afterEach, vi } from 'vitest'import { createElement } from 'react'import { render, screen, cleanup, act, fireEvent } from '@testing-library/react'+const listBundledModels = vi.fn(async () => [])+vi.mock('../../../api/backend', () => ({backendCall: vi.fn(async () => null),isTauri: () => true,@@ -31,17 +43,20 @@ vi.mock('../../../api/engine', async () => {const actual = await vi.importActual<typeof import('../../../api/engine')>('../../../api/engine')return {...actual,- listBundledModels: vi.fn(async () => []),+ listBundledModels: () => listBundledModels(),lastCustomScanDir: () => null,lastScanDirs: () => [],syncCustomModelDir: vi.fn(async () => null),}})-const { HfDownloadPathSetting, MODEL_DIR_SAVE_DEBOUNCE_MS } = await import('../SettingsPage')+const { HfDownloadPathSetting } = await import('../SettingsPage')const { useSettingsStore } = await import('../../../stores/settingsStore')const TYPED = 'C:\\lu-e2e-models'+/** Longer than the debounce that used to sit here, so a timer that came back+ * would fire inside this window and be caught. */+const A_PAUSE_MS = 700function storedFolder() {return useSettingsStore.getState().settings.hfDownloadPathOverride@@ -57,6 +72,7 @@ async function fieldWithTypedPath() {beforeEach(() => {vi.useFakeTimers()+ listBundledModels.mockClear()useSettingsStore.getState().updateSettings({ hfDownloadPathOverride: '' })})afterEach(() => {@@ -77,9 +93,41 @@ describe('a folder typed into the LU Engine field', () => {expect(storedFolder(), 'the typed folder was thrown away on the way out').toBe(TYPED)})- it('is stored on its own shortly after typing stops', async () => {- await fieldWithTypedPath()- await act(async () => { await vi.advanceTimersByTimeAsync(MODEL_DIR_SAVE_DEBOUNCE_MS + 50) })+ it('survives a pause in the middle of a path that has a space in it', async () => {+ // The counter-check's own example. "C:\Program " is a path in the middle+ // of being typed, and the trailing space is part of it.+ render(createElement(HfDownloadPathSetting))+ await act(async () => { await Promise.resolve(); await Promise.resolve() })+ const box = screen.getByLabelText('LU Engine folder')+ const scansBefore = listBundledModels.mock.calls.length++ fireEvent.change(box, { target: { value: 'C:\\Program ' } })+ await act(async () => { await vi.advanceTimersByTimeAsync(A_PAUSE_MS) })++ // The pause must not have eaten the space, or the next word joins the+ // previous one.+ expect((box as HTMLInputElement).value, 'the trailing space was trimmed away under the cursor')+ .toBe('C:\\Program ')+ // And it must not have sent half a path to the folder scan, which answers+ // a half path with a red "unreachable" line.+ expect(storedFolder(), 'half a path reached the store').toBe('')+ expect(+ listBundledModels.mock.calls.length,+ 'the folder scan ran on a path the user had not finished typing',+ ).toBe(scansBefore)++ fireEvent.change(box, { target: { value: 'C:\\Program Files' } })+ expect((box as HTMLInputElement).value).toBe('C:\\Program Files')+ fireEvent.blur(box)+ expect(storedFolder()).toBe('C:\\Program Files')+ })++ it('is stored on Enter, trimmed', async () => {+ render(createElement(HfDownloadPathSetting))+ await act(async () => { await Promise.resolve() })+ const box = screen.getByLabelText('LU Engine folder')+ fireEvent.change(box, { target: { value: ` ${TYPED} ` } })+ fireEvent.keyDown(box, { key: 'Enter' })expect(storedFolder()).toBe(TYPED)})@@ -87,25 +135,25 @@ describe('a folder typed into the LU Engine field', () => {const refreshes: Event[] = []const onRefresh = (e: Event) => refreshes.push(e)window.addEventListener('lu-models-refresh', onRefresh)- await fieldWithTypedPath()- await act(async () => { await vi.advanceTimersByTimeAsync(MODEL_DIR_SAVE_DEBOUNCE_MS + 50) })+ const box = await fieldWithTypedPath()+ fireEvent.blur(box)window.removeEventListener('lu-models-refresh', onRefresh)expect(refreshes.length).toBeGreaterThan(0)})- // NEGATIVE CONTROL: it is a debounce, not a write per keystroke. A path- // being typed must not be stored half finished, or the scan runs against- // "C:\lu" while the user is still on the second syllable.- it('is not stored mid word', async () => {+ // NEGATIVE CONTROL: nothing is written while the user is still typing. A+ // path stored half finished sends the scan against "C:\lu" while the user is+ // on the second syllable, and the scan's verdict about that folder is worse+ // than no verdict at all.+ it('is not stored mid word, however long the pause', async () => {render(createElement(HfDownloadPathSetting))await act(async () => { await Promise.resolve() })const box = screen.getByLabelText('LU Engine folder')fireEvent.change(box, { target: { value: 'C:\\lu' } })- await act(async () => { await vi.advanceTimersByTimeAsync(MODEL_DIR_SAVE_DEBOUNCE_MS - 200) })- fireEvent.change(box, { target: { value: TYPED } })- await act(async () => { await vi.advanceTimersByTimeAsync(MODEL_DIR_SAVE_DEBOUNCE_MS - 200) })+ await act(async () => { await vi.advanceTimersByTimeAsync(A_PAUSE_MS * 5) })expect(storedFolder(), 'a half typed path reached the store').toBe('')- await act(async () => { await vi.advanceTimersByTimeAsync(300) })+ fireEvent.change(box, { target: { value: TYPED } })+ fireEvent.blur(box)expect(storedFolder()).toBe(TYPED)})@@ -120,6 +168,17 @@ describe('a folder typed into the LU Engine field', () => {expect(storedFolder()).toBe(TYPED)})+ // NEGATIVE CONTROL: the unmount trims too, so walking away and blurring+ // cannot store two different strings for one typed path.+ it('trims on the way out as well', async () => {+ render(createElement(HfDownloadPathSetting))+ await act(async () => { await Promise.resolve() })+ const box = screen.getByLabelText('LU Engine folder')+ fireEvent.change(box, { target: { value: ` ${TYPED} ` } })+ cleanup()+ expect(storedFolder()).toBe(TYPED)+ })+// NEGATIVE CONTROL: an unmount that owes nothing must not write. Otherwise// opening and closing Settings would rewrite the setting, and Reset would be// undone by the very act of leaving.