Skip to content

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.

feat(create): LoRA strength slider covers -2 to 2 and widens to a typed value (D4b)

purpled3a914988d61
diff --git a/e2e/lora-stack-search-and-wide-strength.spec.ts b/e2e/lora-stack-search-and-wide-strength.spec.ts
index c9a37473..74bee803 100644
--- a/e2e/lora-stack-search-and-wide-strength.spec.ts
+++ b/e2e/lora-stack-search-and-wide-strength.spec.ts
@@ -131,6 +131,9 @@ test('search, kept position, copy, and a wide negative strength that reaches the
await expect(age).toHaveValue('-10.00')
await expect(detail).toHaveValue('15.00')
await expect(page.getByText('· 2 active')).toBeVisible()
+ // D4b: each slider widened to its typed value, 0 in the middle.
+ await expect(page.locator('input[type=range][min="-10"][max="10"]')).toHaveValue('-10')
+ await expect(page.locator('input[type=range][min="-15"][max="15"]')).toHaveValue('15')
await shot(page, 'lora-4-staerke-minus10-und-15')
// 25 is pulled back to the end of the range.
await detail.fill('25')
diff --git a/src/components/create/experimental/LoraStrength.tsx b/src/components/create/experimental/LoraStrength.tsx
index 290b1c5c..d862aa27 100644
--- a/src/components/create/experimental/LoraStrength.tsx
+++ b/src/components/create/experimental/LoraStrength.tsx
@@ -1,8 +1,8 @@
import { useId, useState } from 'react'
import { Slider } from '../ui/Slider'
import {
- LORA_SLIDER_MAX, LORA_SLIDER_MIN, LORA_STRENGTH_MAX, LORA_STRENGTH_MIN, LORA_STRENGTH_STEP,
- parseLoraStrength, stepLoraStrength,
+ LORA_STRENGTH_MAX, LORA_STRENGTH_MIN, LORA_STRENGTH_STEP,
+ loraSliderReach, parseLoraStrength, stepLoraStrength,
} from '../../../lib/lora-strength'
interface Props {
@@ -16,11 +16,13 @@ interface Props {
const shown = (v: number) => v.toFixed(2)
/**
- * The strength of one LoRA in the stack: the slider for the usual 0 to 2 and
- * a number field for the exact value, which also takes what the slider cannot
- * reach (Discord 2026-10-02: slider LoRAs for Krea 2 are made
+ * The strength of one LoRA in the stack: the slider for -2 to 2 with 0 marked
+ * in the middle, and a number field for the exact value, which takes -20 to 20
+ * (Discord 2026-10-02: slider LoRAs for Krea 2 are made
* for about -10 to 10, negative included; Discord 2026-10-23: some for -10 to
- * 15, so the field takes -20 to 20).
+ * 15). A typed value beyond 2 widens the slider to it (Discord 2026-11-01), and
+ * the slider stays that wide while the control is open, so dragging back
+ * towards 0 does not shrink the track under the thumb.
*
* The field is a text input on purpose. While someone types, "-" and "1," are
* not numbers yet, and a number input hands those back as an empty string, so
@@ -31,6 +33,8 @@ const shown = (v: number) => v.toFixed(2)
export function LoraStrength({ name, value, onChange }: Props) {
const id = useId()
const [draft, setDraft] = useState<string | null>(null)
+ const [reach, setReach] = useState(() => loraSliderReach(value))
+ if (loraSliderReach(value) > reach) setReach(loraSliderReach(value))
const label = name.replace(/^.*[\\/]/, '').replace(/\.safetensors$/i, '')
return (
<div className="space-y-1.5">
@@ -64,10 +68,11 @@ export function LoraStrength({ name, value, onChange }: Props) {
/>
</div>
<Slider
- min={LORA_SLIDER_MIN}
- max={LORA_SLIDER_MAX}
+ min={-reach}
+ max={reach}
step={LORA_STRENGTH_STEP}
- value={Math.max(LORA_SLIDER_MIN, Math.min(LORA_SLIDER_MAX, value))}
+ origin={0}
+ value={Math.max(-reach, Math.min(reach, value))}
onChange={onChange}
/>
</div>
diff --git a/src/components/create/experimental/__tests__/lora-staerke-regler-negativ.test.tsx b/src/components/create/experimental/__tests__/lora-staerke-regler-negativ.test.tsx
new file mode 100644
index 00000000..93ccf50b
--- /dev/null
+++ b/src/components/create/experimental/__tests__/lora-staerke-regler-negativ.test.tsx
@@ -0,0 +1,85 @@
+/**
+ * @vitest-environment jsdom
+ *
+ * D4b (3.0.9, Discord 2026-11-01): the LoRA strength slider stopped at 0 to 2,
+ * slider LoRAs need values below zero and some -10 to 20. The slider now
+ * covers -2 to 2 with 0 marked in the middle, the field still takes any value
+ * from -20 to 20, and a typed value beyond 2 widens the slider to it.
+ * Stored strengths read as before.
+ *
+ * Run: npx vitest run src/components/create/experimental/__tests__/lora-staerke-regler-negativ.test.tsx
+ */
+import { describe, it, expect, afterEach } from 'vitest'
+import { useState } from 'react'
+import { render, screen, fireEvent, cleanup } from '@testing-library/react'
+import { LoraStrength } from '../LoraStrength'
+import { loraSliderReach } from '../../../../lib/lora-strength'
+
+const NAME = 'krea2_slider_age.safetensors'
+const seen: number[] = []
+
+function Harness({ start = 0.8 }: { start?: number }) {
+ const [value, setValue] = useState(start)
+ return <LoraStrength name={NAME} value={value} onChange={(v) => { seen.push(v); setValue(v) }} />
+}
+
+const field = () => screen.getByRole('textbox', { name: 'Strength of krea2_slider_age' }) as HTMLInputElement
+const slider = () => screen.getByRole('slider') as HTMLInputElement
+const range = () => [slider().min, slider().max]
+const type = (text: string) => {
+ fireEvent.focus(field())
+ fireEvent.change(field(), { target: { value: text } })
+ fireEvent.blur(field())
+}
+
+afterEach(() => { cleanup(); seen.length = 0 })
+
+describe('D4b: the strength slider goes below zero', () => {
+ it('covers -2 to 2 by default, with 0 marked in the middle', () => {
+ render(<Harness />)
+ expect(range()).toEqual(['-2', '2'])
+ expect(slider().value).toBe('0.8')
+ expect(screen.getByTestId('slider-origin').style.left).toBe('50%')
+ })
+
+ it('drags to a negative strength, and the field shows it', () => {
+ render(<Harness />)
+ fireEvent.change(slider(), { target: { value: '-1.5' } })
+ expect(seen.at(-1)).toBe(-1.5)
+ expect(field().value).toBe('-1.50')
+ })
+
+ it('a typed value beyond 2 widens the slider to it, on both sides', () => {
+ render(<Harness />)
+ type('-15')
+ expect(seen.at(-1)).toBe(-15)
+ expect(range()).toEqual(['-15', '15'])
+ expect(slider().value).toBe('-15')
+ type('20')
+ expect(range()).toEqual(['-20', '20'])
+ expect(slider().value).toBe('20')
+ })
+
+ it('stays wide while it is open, so dragging back to 0 does not move the track', () => {
+ render(<Harness />)
+ type('12.5')
+ fireEvent.change(slider(), { target: { value: '0.5' } })
+ expect(seen.at(-1)).toBe(0.5)
+ expect(range()).toEqual(['-13', '13'])
+ })
+
+ it('a stored strength opens where it is: 0.8 on the usual slider, -6 on a wider one', () => {
+ render(<Harness start={0.8} />)
+ expect(range()).toEqual(['-2', '2'])
+ cleanup()
+ render(<Harness start={-6} />)
+ expect(range()).toEqual(['-6', '6'])
+ expect(slider().value).toBe('-6')
+ expect(field().value).toBe('-6.00')
+ expect(seen).toEqual([])
+ })
+
+ it('the reach is 2, or the next whole number past the value, never past 20', () => {
+ expect([0, 0.8, 2, -2, 2.01, -15, 15.5, 20].map(loraSliderReach)).toEqual([2, 2, 2, 2, 3, 15, 16, 20])
+ })
+})
diff --git a/src/components/create/experimental/__tests__/lora-strength-feld.test.tsx b/src/components/create/experimental/__tests__/lora-strength-feld.test.tsx
index 8a8c0dd3..6a4034e2 100644
--- a/src/components/create/experimental/__tests__/lora-strength-feld.test.tsx
+++ b/src/components/create/experimental/__tests__/lora-strength-feld.test.tsx
@@ -126,21 +126,21 @@ describe('the number field', () => {
})
describe('the slider next to it', () => {
- it('covers the usual 0 to 2 in steps of 0.05 and writes into the same value', () => {
+ it('covers -2 to 2 in steps of 0.05 and writes into the same value', () => {
render(<Harness />)
- expect([slider().min, slider().max, slider().step]).toEqual(['0', '2', '0.05'])
+ expect([slider().min, slider().max, slider().step]).toEqual(['-2', '2', '0.05'])
fireEvent.change(slider(), { target: { value: '1.35' } })
expect(seen.at(-1)).toBe(1.35)
expect(field().value).toBe('1.35')
})
- it('rests at its end when the typed value is beyond it, the field keeps the truth', () => {
+ it('widens to a value beyond it (D4b), the field keeps the truth', () => {
render(<Harness start={-6} />)
- expect(slider().value).toBe('0')
+ expect([slider().min, slider().max, slider().value]).toEqual(['-6', '6', '-6'])
expect(field().value).toBe('-6.00')
cleanup()
render(<Harness start={8} />)
- expect(slider().value).toBe('2')
+ expect([slider().min, slider().max, slider().value]).toEqual(['-8', '8', '8'])
expect(field().value).toBe('8.00')
})
})
diff --git a/src/components/create/ui/Slider.tsx b/src/components/create/ui/Slider.tsx
index 35536ede..e7daa5a7 100644
--- a/src/components/create/ui/Slider.tsx
+++ b/src/components/create/ui/Slider.tsx
@@ -7,14 +7,19 @@ interface Props {
onChange: (v: number) => void
unit?: string
format?: (v: number) => string
+ /** Where the bar starts and a small mark sits, for a range around zero
+ * (the LoRA strength). Without it the bar starts at min, as before. */
+ origin?: number
}
// Upgrade of src/components/settings/SliderControl.tsx — same neutral-grey fill
// and thumb as the live app, plus a unit + tabular-mono value readout.
-export function Slider({ label, value, min, max, step, onChange, unit, format }: Props) {
+export function Slider({ label, value, min, max, step, onChange, unit, format, origin }: Props) {
// Held inside the track: a value outside min..max (a stored setting from a
// wider range) drew the bar and the thumb past the end of the slider.
- const pct = max > min ? Math.min(100, Math.max(0, ((value - min) / (max - min)) * 100)) : 0
+ const at = (v: number) => max > min ? Math.min(100, Math.max(0, ((v - min) / (max - min)) * 100)) : 0
+ const pct = at(value)
+ const from = origin === undefined ? 0 : at(origin)
const display = format ? format(value) : `${value}${unit ? ' ' + unit : ''}`
return (
<div className="space-y-1.5">
@@ -26,7 +31,10 @@ export function Slider({ label, value, min, max, step, onChange, unit, format }:
)}
<div className="relative h-5 flex items-center">
<div className="absolute inset-x-0 h-1 rounded-full bg-white/10" />
- <div className="absolute left-0 h-1 rounded-full bg-gray-400" style={{ width: `${pct}%` }} />
+ <div className="absolute h-1 rounded-full bg-gray-400" style={{ left: `${Math.min(from, pct)}%`, width: `${Math.abs(pct - from)}%` }} />
+ {origin !== undefined && (
+ <div data-testid="slider-origin" className="absolute w-px h-2.5 bg-gray-500" style={{ left: `${from}%` }} />
+ )}
<input
type="range"
min={min}
diff --git a/src/lib/__tests__/lora-strength.test.ts b/src/lib/__tests__/lora-strength.test.ts
index cede6385..0c810872 100644
--- a/src/lib/__tests__/lora-strength.test.ts
+++ b/src/lib/__tests__/lora-strength.test.ts
@@ -14,11 +14,11 @@ import {
} from '../lora-strength'
describe('the range', () => {
- it('is -20 to 20 in steps of 0.05, inside what ComfyUI accepts, and the slider keeps 0 to 2', () => {
+ it('is -20 to 20 in steps of 0.05, inside what ComfyUI accepts, and the slider covers -2 to 2', () => {
expect([LORA_STRENGTH_MIN, LORA_STRENGTH_MAX, LORA_STRENGTH_STEP]).toEqual([-20, 20, 0.05])
expect(LORA_STRENGTH_MIN).toBeGreaterThanOrEqual(-100)
expect(LORA_STRENGTH_MAX).toBeLessThanOrEqual(100)
- expect([LORA_SLIDER_MIN, LORA_SLIDER_MAX]).toEqual([0, 2])
+ expect([LORA_SLIDER_MIN, LORA_SLIDER_MAX]).toEqual([-2, 2])
})
it('clamps at both ends and keeps two decimals', () => {
diff --git a/src/lib/lora-strength.ts b/src/lib/lora-strength.ts
index d894a09b..86ba0c42 100644
--- a/src/lib/lora-strength.ts
+++ b/src/lib/lora-strength.ts
@@ -8,13 +8,23 @@
* are made for a wide range around zero (Discord 2026-10-02:
* Krea 2 LoRAs meant for -10 to 10; Discord 2026-10-23: some are
* used from -10 to 15), so the number field takes -20 to 20.
- * The slider keeps the usual 0 to 2. */
+ * The slider covers -2 to 2 with 0 in the middle (Discord 2026-11-01:
+ * slider LoRAs go below zero all the time); a value typed beyond that
+ * widens it, see loraSliderReach. */
export const LORA_STRENGTH_MIN = -20
export const LORA_STRENGTH_MAX = 20
export const LORA_STRENGTH_STEP = 0.05
-export const LORA_SLIDER_MIN = 0
+export const LORA_SLIDER_MIN = -2
export const LORA_SLIDER_MAX = 2
+/** How far the slider reaches either side of zero for a value: the usual 2,
+ * or the next whole number past a typed value beyond it (-15 gives -15 to
+ * 15), so the thumb shows where the value is instead of resting at the end.
+ * The same on both sides keeps 0 in the middle. */
+export function loraSliderReach(value: number): number {
+ return Math.min(LORA_STRENGTH_MAX, Math.max(LORA_SLIDER_MAX, Math.ceil(Math.abs(value))))
+}
+
/** Into the allowed range, on ComfyUI's own grid of 0.01. */
export function clampLoraStrength(value: number): number {
const v = Math.max(LORA_STRENGTH_MIN, Math.min(LORA_STRENGTH_MAX, value))