Skip to content

Commit

Permalink
When starting input with operator, append to existing value instead o…
Browse files Browse the repository at this point in the history
…f replacing (actualbudget#2523)

Co-authored-by: Joshua Harris <[email protected]>
  • Loading branch information
JazzyJosh and JazzyJosh authored Apr 10, 2024
1 parent 4e9130a commit a955fe2
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
16 changes: 15 additions & 1 deletion packages/desktop-client/src/components/table.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -339,11 +339,25 @@ function InputValue({
}
}

const ops = ['+', '-', '*', '/', '^'];

function valueIsASingleOperator(text) {
return text?.length === 1 && ops.includes(text.charAt(0));
}

function setValue_(text) {
if (valueIsASingleOperator(text)) {
setValue(defaultValue + text);
} else {
setValue(text);
}
}

return (
<Input
{...props}
value={value}
onChangeValue={text => setValue(text)}
onChangeValue={text => setValue_(text)}
onBlur={onBlur_}
onUpdate={onUpdate}
onKeyDown={onKeyDown}
Expand Down
6 changes: 6 additions & 0 deletions upcoming-release-notes/2523.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
category: Enhancements
authors: [JazzyJosh]
---

Using any math operator on an input will begin a calculation starting with the existing value.

0 comments on commit a955fe2

Please sign in to comment.