Skip to content

Commit b1b37c9

Browse files
committed
Improve text input handling
1 parent 274d69f commit b1b37c9

File tree

1 file changed

+24
-6
lines changed

1 file changed

+24
-6
lines changed

apps/desktop/src/routes/editor/ConfigSidebar.tsx

Lines changed: 24 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1900,6 +1900,14 @@ function ClipSegmentConfig(props: {
19001900
}) {
19011901
const { setProject, setEditorState, project } = useEditorContext();
19021902

1903+
// Local state for the input field
1904+
const [inputValue, setInputValue] = createSignal(props.segment.timescale.toString());
1905+
1906+
// Update input value when timescale changes externally (e.g., from slider or buttons)
1907+
createEffect(() => {
1908+
setInputValue(props.segment.timescale.toString());
1909+
});
1910+
19031911
return (
19041912
<>
19051913
<div class="flex flex-row justify-between items-center">
@@ -1961,23 +1969,30 @@ function ClipSegmentConfig(props: {
19611969
<div class="flex items-center gap-1">
19621970
<TextInput
19631971
type="number"
1964-
value={props.segment.timescale.toFixed(2)}
1972+
value={inputValue()}
19651973
onInput={(e) => {
1966-
const value = parseFloat(e.currentTarget.value);
1967-
if (!isNaN(value) && value > 0 && value <= 10) {
1974+
const value = e.currentTarget.value;
1975+
setInputValue(value);
1976+
1977+
const numValue = parseFloat(value);
1978+
if (!isNaN(numValue) && numValue > 0 && numValue <= 10) {
19681979
setProject(
19691980
"timeline",
19701981
"segments",
19711982
props.segmentIndex,
19721983
"timescale",
1973-
value
1984+
numValue
19741985
);
19751986
}
19761987
}}
1988+
onFocus={(e) => {
1989+
// Select all text on focus for easy replacement
1990+
e.currentTarget.select();
1991+
}}
19771992
onBlur={(e) => {
19781993
const value = parseFloat(e.currentTarget.value);
19791994
if (isNaN(value) || value <= 0) {
1980-
e.currentTarget.value = props.segment.timescale.toFixed(2);
1995+
setInputValue(props.segment.timescale.toFixed(2));
19811996
} else if (value > 10) {
19821997
setProject(
19831998
"timeline",
@@ -1986,7 +2001,10 @@ function ClipSegmentConfig(props: {
19862001
"timescale",
19872002
10
19882003
);
1989-
e.currentTarget.value = "10.00";
2004+
setInputValue("10.00");
2005+
} else {
2006+
// Format to 2 decimal places on blur
2007+
setInputValue(value.toFixed(2));
19902008
}
19912009
}}
19922010
class="w-16 px-2 py-1 text-xs text-center border rounded-md bg-gray-2 text-gray-12"

0 commit comments

Comments
 (0)