calculator icon indicating copy to clipboard operation
calculator copied to clipboard

Copy/pasting a long formula in chunks, and in whole, give different results

Open TimLovellSmith opened this issue 4 years ago • 10 comments

Consider the following multiline sum in a document, simplified for purposes of easy to repro. (The real numbers were longer.)

1 +2 -3 
+4 +5 +6

and the same sum but written on a single line

1 +2 -3 +4 +5 +6

Describe the bug

I was very surprised to realize the results of copy-pasting the first formula, one line-at-a-time, and then hitting = is different from the result of copy-pasting it both-lines-together, or copy-pasting the single-line version all in one shot.

Steps To Reproduce

  1. Standard mode [Edit: also the same issue reproduces for me in scientific mode which it is the other main mode I find useful]
  2. Copy text 1 +2 -3 onto your clipboard from another app
  3. Paste into calculator with Ctrl+V
  4. Copy text +4 +5 +6 onto your clipboard from another app
  5. Paste into calculator with Ctrl+V

Observed result:

Calculator shows the sum it has computed to be 1 + 2 - 4 + 5 + 6, resulting in 10 (the 'wrong' answer)

Expected result:

Calculator should have shown the sum it has computed to be 1 + 2 - 3 + 4 + 5 + 6, resulting in 15!

Impact:

Took quite a while to figure out why calculator kept giving me the wrong answer! I'm lucky that for me it was obviously wrong. If it wasn't obvious I might not have even realized and just believed the wrong number.

Screenshots

Device and Application Information

  • OS Build: 10.0.19042.0
  • Architecture: X64
  • Application Version: 10.2005.23.0 also repros in 10.2012.21.0
  • Region: en-US
  • Dev Version Installed: False

I'm just reporting this problem. I don't want to fix it.

TimLovellSmith avatar Feb 01 '21 05:02 TimLovellSmith

This is your friendly Microsoft Issue Bot. I've seen this issue come in and have gone to tell a human about it.

MicrosoftIssueBot avatar Feb 01 '21 10:02 MicrosoftIssueBot

This is your friendly Microsoft Issue Bot. I've seen this issue come in and have gone to tell a human about it.

I want to work on this issue. Please assign it to me

Ayushsunny avatar Feb 06 '21 21:02 Ayushsunny

Took a closer look to see what is happening. When you paste 1 +2 -3 into Calculator with Ctrl+V, you are left with an "uncommitted operation" (the "3" is lingering there, but you have not submitted it by hitting enter).

When you paste in +4 +5 +6, it is replacing the 3 with the new string, but it also appears to be dropping the leading "+". This issue only appears to occur on paste, if you were to copy in 1 +2 -3 and then enter a "+" with the keyboard before pasting in +4 +5 +6, the expression is evaluated as expected.

I suspect the fix here is to ensure that we are treating the leading "+" as an operator and not a sign, but not sure how that might affect pasting in positive/negative numbers.

grochocki avatar Mar 31 '21 06:03 grochocki

Took a closer look to see what is happening. When you paste 1 +2 -3 into Calculator with Ctrl+V, you are left with an "uncommitted operation" (the "3" is lingering there, but you have not submitted it by hitting enter).

When you paste in +4 +5 +6, it is replacing the 3 with the new string, but it also appears to be dropping the leading "+". This issue only appears to occur on paste, if you were to copy in 1 +2 -3 and then enter a "+" with the keyboard before pasting in +4 +5 +6, the expression is evaluated as expected.

I suspect the fix here is to ensure that we are treating the leading "+" as an operator and not a sign, but not sure how that might affect pasting in positive/negative numbers.

Assign me so that I can look forward for this issue.

Ayushsunny avatar Apr 01 '21 06:04 Ayushsunny

Thanks, @Ayushsunny! There is a technical limitation preventing us from assigning issues to community members, which is really unfortunate, but if you want to take look at this, it is all yours.

grochocki avatar Apr 01 '21 06:04 grochocki

Thanks, @Ayushsunny! There is a technical limitation preventing us from assigning issues to community members, which is really unfortunate, but if you want to take look at this, it is all yours.

Ohh.. I thought Open source is for non-community members. So that anybody can contribute to the org. Anyway I'm looking into the issue and please help me if i'll get stuck somewhere

Ayushsunny avatar Apr 01 '21 07:04 Ayushsunny

I thought Open source is for non-community members.

Oh, it is! And it appears we now can assign issues to team members outside of our immediate team! When we have tried in the past, it would not show community members in the assignment dropdown.

grochocki avatar Apr 01 '21 16:04 grochocki

Hello Sir @grochocki can you help me to find out the code-base of this issue.

Ayushsunny avatar Apr 02 '21 11:04 Ayushsunny

@tian-lt may be able to help point you in the right direction here

grochocki avatar May 26 '21 08:05 grochocki

Hi @Ayushsunny, If you are getting started on working this issue, I'd recommend you to take a look at StandardCalculatorViewModel::OnPasteCommand() and StandardCalculatorViewModel::OnPaste(). The basic logic is that the ViewModel parses the input string pasted from the Clipboard, and then simulate the typing actions to send the corresponding commands to CalcEngine.

tian-lt avatar May 26 '21 09:05 tian-lt