From a955fe2474706f76c57bde993b8206d86f7758e0 Mon Sep 17 00:00:00 2001 From: Joshua Harris Date: Wed, 10 Apr 2024 11:05:20 -0400 Subject: [PATCH] When starting input with operator, append to existing value instead of replacing (#2523) Co-authored-by: Joshua Harris <2312397+JazzyJosh@users.noreply.github.com> --- packages/desktop-client/src/components/table.tsx | 16 +++++++++++++++- upcoming-release-notes/2523.md | 6 ++++++ 2 files changed, 21 insertions(+), 1 deletion(-) create mode 100644 upcoming-release-notes/2523.md diff --git a/packages/desktop-client/src/components/table.tsx b/packages/desktop-client/src/components/table.tsx index 59ff2f19565..96fd84131b6 100644 --- a/packages/desktop-client/src/components/table.tsx +++ b/packages/desktop-client/src/components/table.tsx @@ -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 ( setValue(text)} + onChangeValue={text => setValue_(text)} onBlur={onBlur_} onUpdate={onUpdate} onKeyDown={onKeyDown} diff --git a/upcoming-release-notes/2523.md b/upcoming-release-notes/2523.md new file mode 100644 index 00000000000..42f0c8ac804 --- /dev/null +++ b/upcoming-release-notes/2523.md @@ -0,0 +1,6 @@ +--- +category: Enhancements +authors: [JazzyJosh] +--- + +Using any math operator on an input will begin a calculation starting with the existing value.