Bug 97968 - EDITING: Cut/paste doesn't change formula references
Summary: EDITING: Cut/paste doesn't change formula references
Status: RESOLVED FIXED
Alias: None
Product: LibreOffice
Classification: Unclassified
Component: Calc (show other bugs)
Version:
(earliest affected)
4.3.2.2 release
Hardware: All All
: medium normal
Assignee: Eike Rathke
URL:
Whiteboard: target:5.3.0 target:5.2.4
Keywords: bibisected, bisected, regression
Depends on:
Blocks:
 
Reported: 2016-02-18 09:29 UTC by OTgzMDY2OTEK
Modified: 2016-11-11 08:53 UTC (History)
4 users (show)

See Also:
Crash report or crash signature:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description OTgzMDY2OTEK 2016-02-18 09:29:56 UTC
Cut/paste of a part of a range with formulas depending on each other will not move the cell references correctly.

Example:

1. Enter 1 in A1 and =A1+1 in A2.
2. Copy A2 into cells A3:A6.
3. Cut the range A4:A6 and paste it into B4.

The result in B4:B6 will be 4, 1, 1 instead of the expected 4, 5, 6. The formulas in B5 and B6 refers to A4 and A5 instead of B4 and B5.

If you had cut and paste the entire range (A1:A6) the result would have been correct. There is minor bug when undoing the paste. Numbers 1, 2, 3, 4, 5 in cells A2:A6. When you press a second time on undo number one will appear in A1.

Cutting and pasting works correctly if the formulas had been written horizontally e.g. on the first row instead of vertically in column A.
Comment 1 Buovjaga 2016-02-20 15:39:26 UTC
Which version are you using? Which operating system?
Did this work in an older version?

Set to NEEDINFO.
Change back to UNCONFIRMED after you have provided the information.
Comment 2 OTgzMDY2OTEK 2016-02-20 23:33:02 UTC
I get the same behaviour on both computers running Windows 10 and Linux (Fedora).

The version of LibreOffice on Windows was either 4.4.x or 4.5.x, when I discovered the problem for the first time. It was then updated to 5.0.x, but it didn't solve the issue.

On Linux I have got the same behaviour with LibreOffice 4.3.2 and 5.0.5.2.

I can not confirm that this would have worked correctly on an older version, but I have neither noticed the problem earlier.
Comment 3 Buovjaga 2016-02-21 15:36:53 UTC
Reproduced.

In 3.5, the behavior works like you expect.

Win 7 Pro 64-bit Version: 5.2.0.0.alpha0+
Build ID: ef02de2698d90fd874bddf3146165cbe85487bc5
CPU Threads: 4; OS Version: Windows 6.1; UI Render: default; 
TinderBox: Win-x86@39, Branch:master, Time: 2016-02-19_23:40:50
Locale: fi-FI (fi_FI)
Comment 4 raal 2016-02-24 20:05:43 UTC
This seems to have begun at the below commit.
Adding Cc: to Kohei Yoshida ; Could you possibly take a look at this one?
Thanks

4eec5655c56f97d86f5eee2605a76074c6ac48eb is the first bad commit
commit 4eec5655c56f97d86f5eee2605a76074c6ac48eb
Author: Matthew Francis <mjay.francis@gmail.com>
Date:   Thu May 28 19:31:17 2015 +0800

    source-hash-79d03eb090a5f88863c1004ef8b7f483cbecb69d
    
    commit 79d03eb090a5f88863c1004ef8b7f483cbecb69d
    Author:     Kohei Yoshida <kohei.yoshida@collabora.com>
    AuthorDate: Tue Feb 25 12:53:33 2014 -0500
    Commit:     Kohei Yoshida <kohei.yoshida@collabora.com>
    CommitDate: Tue Feb 25 22:53:39 2014 -0500
    
        fdo#75386: Totally fix reference update during range move.
    
        It was just not working at all due to multiple reasons.  The
        reference update needed to be reworked for formula groups such that
        the token array is adjusted only for the top cell but all formula cells
        still needed to be processed afterwards.  The bound check also needed
        to be done against the old range prior to the move, not the new range
        after the move.
    
        During undo, the paint had to be deferred until after the two calls to
        DoUndo() else the formula cells would get re-calculated before the
        values were placed back to their old positions, causing them to mis-
        calculate wrong values.
    
        Change-Id: Iba66f80a413e0539cac5ab619226cd6f7a04f317

:040000 040000 66cc4bf0b61397915fb773ceace0d0caca8852de 28672e00ca36716ef23c59ce51ebb6e177d64b9f M	opt
Comment 5 Eike Rathke 2016-10-18 18:34:36 UTC
Taking.
Comment 6 Commit Notification 2016-10-19 21:06:49 UTC
Eike Rathke committed a patch related to this issue.
It has been pushed to "master":

http://cgit.freedesktop.org/libreoffice/core/commit/?id=dfa92e106f7eaa8c3fc6cda034001197ecc53a8f

Resolves: tdf#97968 adjust references during Cut&Paste of formula groups

It will be available in 5.3.0.

The patch should be included in the daily builds available at
http://dev-builds.libreoffice.org/daily/ in the next 24-48 hours. More
information about daily builds can be found at:
http://wiki.documentfoundation.org/Testing_Daily_Builds

Affected users are encouraged to test the fix and report feedback.
Comment 7 Eike Rathke 2016-10-19 21:10:08 UTC
Pending review https://gerrit.libreoffice.org/30067 for 5-2
Comment 8 Commit Notification 2016-10-20 17:41:50 UTC
Eike Rathke committed a patch related to this issue.
It has been pushed to "master":

http://cgit.freedesktop.org/libreoffice/core/commit/?id=27fcf604684cb358d2dc2e550dc93d0e66d5757b

unit test for tdf#97968, Cut&Paste grouped references adjustment

It will be available in 5.3.0.

The patch should be included in the daily builds available at
http://dev-builds.libreoffice.org/daily/ in the next 24-48 hours. More
information about daily builds can be found at:
http://wiki.documentfoundation.org/Testing_Daily_Builds

Affected users are encouraged to test the fix and report feedback.
Comment 9 Commit Notification 2016-11-11 08:53:37 UTC
Eike Rathke committed a patch related to this issue.
It has been pushed to "libreoffice-5-2":

http://cgit.freedesktop.org/libreoffice/core/commit/?id=560469473f8485da4be1e9cedcb7f5399799a485&h=libreoffice-5-2

Resolves: tdf#97968 adjust references during Cut&Paste of formula groups

It will be available in 5.2.4.

The patch should be included in the daily builds available at
http://dev-builds.libreoffice.org/daily/ in the next 24-48 hours. More
information about daily builds can be found at:
http://wiki.documentfoundation.org/Testing_Daily_Builds

Affected users are encouraged to test the fix and report feedback.