Skip to content

AI-native design editor. Open-source Figma alternative.

fix(keyboard): apply opacity immediately on each keypress

sadkodev9d88c4f0451d
diff --git a/src/app/shell/keyboard/actions.ts b/src/app/shell/keyboard/actions.ts
index 95143200a..54af17101 100644
--- a/src/app/shell/keyboard/actions.ts
+++ b/src/app/shell/keyboard/actions.ts
@@ -101,28 +101,21 @@ export function createKeyboardActions({
}
let opacityBuffer = ''
- let opacityTimer: ReturnType<typeof setTimeout> | undefined
+ let opacityResetTimer: ReturnType<typeof setTimeout> | undefined
- function applyOpacityBuffer() {
- clearTimeout(opacityTimer)
- if (!opacityBuffer) return
+ function opacityDigit(digit: string) {
+ if (store.state.selectedIds.size === 0) return
+ opacityBuffer += digit
+ if (opacityBuffer.length > 3) opacityBuffer = opacityBuffer.slice(-3)
const n = Number.parseInt(opacityBuffer, 10)
const percent = opacityBuffer.length === 1 ? n * 10 : n
const clamped = Math.min(100, Math.max(0, percent))
- opacityBuffer = ''
setOpacityTarget(clamped / 100)
runCommand('selection.setOpacity')
- }
-
- function opacityDigit(digit: string) {
- if (store.state.selectedIds.size === 0) return
- opacityBuffer += digit
- clearTimeout(opacityTimer)
- if (opacityBuffer.length >= 3) {
- applyOpacityBuffer()
- } else {
- opacityTimer = setTimeout(applyOpacityBuffer, 400)
- }
+ clearTimeout(opacityResetTimer)
+ opacityResetTimer = setTimeout(() => {
+ opacityBuffer = ''
+ }, 800)
}
return {