Open source Loom alternative. Beautiful, shareable screen recordings.
Rust appcapcossloommacnextjsnextjs15open-sourceossreactrecordrustscreen-capturescreen-recorderscreenshotsolidjstauritauri-apptypescriptvite
fix(editor): improve hex color commit behavior on blur and Enter
Richie McIlroyd54ac3ab5b88
diff --git a/apps/desktop/src/routes/editor/color-utils.tsx b/apps/desktop/src/routes/editor/color-utils.tsxindex 010f68b2c..b273470c7 100644--- a/apps/desktop/src/routes/editor/color-utils.tsx+++ b/apps/desktop/src/routes/editor/color-utils.tsx@@ -41,6 +41,18 @@ export function RgbInput(props: {let colorInput!: HTMLInputElement;+ const commitValue = (raw: string) => {+ const trimmed = raw.trim();+ const value = hexToRgb(trimmed);+ if (value) {+ const [r, g, b] = value;+ props.onChange([r, g, b]);+ setText(rgbToHex([r, g, b]));+ return true;+ }+ return false;+ };+return (<div class="flex flex-row items-center gap-[0.75rem] relative"><button@@ -73,27 +85,28 @@ export function RgbInput(props: {onFocus={() => {prevHex = rgbToHex(props.value);}}+ onKeyDown={(e) => {+ if (e.key === "Enter") {+ e.preventDefault();+ if (!commitValue(e.currentTarget.value)) {+ setText(prevHex);+ }+ e.currentTarget.blur();+ }+ }}onInput={(e) => {setText(e.currentTarget.value);- const value = hexToRgb(e.target.value);+ const value = hexToRgb(e.currentTarget.value.trim());if (!value) return;const [r, g, b] = value;props.onChange([r, g, b]);}}onBlur={(e) => {- const value = hexToRgb(e.target.value);- if (value) {- const [r, g, b] = value;- props.onChange([r, g, b]);- } else {+ if (!commitValue(e.target.value)) {setText(prevHex);- const fallbackValue = hexToRgb(text());- if (!fallbackValue) return;-- const [r, g, b] = fallbackValue;- props.onChange([r, g, b]);+ props.onChange(props.value);}}}/>diff --git a/apps/desktop/src/routes/editor/text-style.tsx b/apps/desktop/src/routes/editor/text-style.tsxindex e0e3e56b3..e819ae6ce 100644--- a/apps/desktop/src/routes/editor/text-style.tsx+++ b/apps/desktop/src/routes/editor/text-style.tsx@@ -47,6 +47,17 @@ export function HexColorInput(props: {let prevColor = props.value;let colorInput!: HTMLInputElement;+ const commitValue = (raw: string) => {+ const trimmed = raw.trim();+ if (/^#[0-9A-F]{6}$/i.test(trimmed)) {+ const normalized = `#${trimmed.slice(1).toUpperCase()}`;+ props.onChange(normalized);+ setText(normalized);+ return true;+ }+ return false;+ };+return (<div class="flex flex-row items-center gap-[0.75rem] relative"><button@@ -74,14 +85,27 @@ export function HexColorInput(props: {onFocus={() => {prevColor = props.value;}}+ onKeyDown={(e) => {+ if (e.key === "Enter") {+ e.preventDefault();+ if (!commitValue(e.currentTarget.value)) {+ setText(prevColor);+ }+ e.currentTarget.blur();+ }+ }}onInput={(e) => {setText(e.currentTarget.value);- props.onChange(e.currentTarget.value);+ const trimmed = e.currentTarget.value.trim();+ if (/^#[0-9A-F]{6}$/i.test(trimmed)) {+ const normalized = `#${trimmed.slice(1).toUpperCase()}`;+ props.onChange(normalized);+ }}}onBlur={(e) => {- if (!/^#[0-9A-F]{6}$/i.test(e.target.value)) {+ if (!commitValue(e.target.value)) {setText(prevColor);- props.onChange(prevColor);+ props.onChange(props.value);}}}/>diff --git a/apps/desktop/src/routes/screenshot-editor/ColorPicker.tsx b/apps/desktop/src/routes/screenshot-editor/ColorPicker.tsxindex 8b50c2d7e..a210bb35f 100644--- a/apps/desktop/src/routes/screenshot-editor/ColorPicker.tsx+++ b/apps/desktop/src/routes/screenshot-editor/ColorPicker.tsx@@ -29,6 +29,18 @@ export function RgbInput(props: {let prevHex = rgbToHex(props.value);let colorInput!: HTMLInputElement;+ const commitValue = (raw: string) => {+ const trimmed = raw.trim();+ const value = hexToRgb(trimmed);+ if (value) {+ const [r, g, b] = value;+ props.onChange([r, g, b]);+ setText(rgbToHex([r, g, b]));+ return true;+ }+ return false;+ };+return (<div class="flex flex-row items-center gap-[0.75rem] relative"><button@@ -57,24 +69,26 @@ export function RgbInput(props: {onFocus={() => {prevHex = rgbToHex(props.value);}}+ onKeyDown={(e) => {+ if (e.key === "Enter") {+ e.preventDefault();+ if (!commitValue(e.currentTarget.value)) {+ setText(prevHex);+ }+ e.currentTarget.blur();+ }+ }}onInput={(e) => {setText(e.currentTarget.value);- const value = hexToRgb(e.target.value);+ const value = hexToRgb(e.currentTarget.value.trim());if (!value) return;const [r, g, b] = value;props.onChange([r, g, b]);}}onBlur={(e) => {- const value = hexToRgb(e.target.value);- if (value) {- const [r, g, b] = value;- props.onChange([r, g, b]);- } else {+ if (!commitValue(e.target.value)) {setText(prevHex);- const fallbackValue = hexToRgb(text());- if (!fallbackValue) return;- const [r, g, b] = fallbackValue;- props.onChange([r, g, b]);+ props.onChange(props.value);}}}/>