Description: I have macros writted in versions 7 and older. In connection with ticket 167178 I discover different behaviour of function ThisComponent.Sheets.moveByName(name, index) in version 25.2.3.2 and 25.2.6. I do't know if it is bug or new property... Steps to Reproduce: In table with sheets Sheet0 Sheet1 Sheet3 Sheet4 lastsheet run this code which insert new sheet a next move it to right order: Sub Main oLast = ThisComponent.Sheets.getByName("lastsheet") ThisComponent.Sheets.insertNewByName("Sheet2", 0) oSheet = ThisComponent.Sheets.getByName("Sheet2") for i = oLast.RangeAddress.sheet - 1 to 1 step -1 j = strComp(ThisComponent.Sheets.getByIndex(i).getName(),"Sheet2") if j = -1 then ThisComponent.Sheets.moveByName("Sheet2", i + 1) exit for end if next i End Sub Actual Results: Order of sheets in versions 25.2. is Sheet0 Sheet1 Sheet3 Sheet2 Sheet4 lastsheet Expected Results: Order of sheets in versions 7.5.0.3. and olders, is: Sheet0 Sheet1 Sheet2 Sheet3 Sheet4 lastsheet Reproducible: Always User Profile Reset: No Additional Info: I only have official versions 25.2. and later for testing and version 7.5.0.3 in which I once wrote the code. I can't find out exactly from which version the behavior of the moveByName() function changed. Thanks
Created attachment 201700 [details] sample file
Regression introduced by: commit e6d4af2a03f22de1493e00e497e081240bf8a5c4 [log] author Alin Andrei Abahnencei <alinandrei2004@gmail.com> Thu Dec 12 16:03:22 2024 +0200 committer Mike Kaganski <mike.kaganski@collabora.com> Wed Dec 18 07:08:24 2024 +0100 tree c1aabac8d6ac0b697a5e27564885083cd12f5046 parent 943c079def4f55463581e1639b08c11f04863a04 [diff] tdf#163319 Do not decrement destination position when moving a tab
@Mike, I thought you would be interested in this issue
(In reply to Xisco Faulí from comment #2) > Regression introduced by: Xisco: please don't set NEW and Regression, when the change has intentionally changed it in this way. Zdenek: thank you for filing this, as we discussed in bug 167178. Now that the change is identified, it is clear that no, this is not a bug, but a bugfix, where previously it worked incorrectly.
(In reply to Zdenek Borecky from comment #0) To clarify: previously, you had to do that "+ 1": > Sub Main > ... > ThisComponent.Sheets.moveByName("Sheet2", i + 1) And that was exactly wrong. To move to position i, you had to make it i+i; and also you had to consider, if i is greater or smaller than the current index of the sheet you are moving. That is now fixed. When you want to move sheet to position i, you just use that i, and may be sure that ThisComponent.Sheets.moveByName("Sheet2", i) MsgBox ThisComponent.Sheets.getByName("Sheet2").RangeAddress.sheet would show the value of i.
Thanks you very much for quick reaction and explanation. I will fix my code.