Bug 495419 - Tab order is not properly restored
Summary: Tab order is not properly restored
Status: RESOLVED FIXED
Alias: None
Product: kate
Classification: Applications
Component: sessions (other bugs)
Version First Reported In: Git
Platform: Other Linux
: NOR normal
Target Milestone: ---
Assignee: KWrite Developers
URL:
Keywords:
: 495872 496180 (view as bug list)
Depends on:
Blocks:
 
Reported: 2024-10-27 09:12 UTC by Allen Winter
Modified: 2025-07-14 20:20 UTC (History)
10 users (show)

See Also:
Latest Commit:
Version Fixed/Implemented In: 24.12.0
Sentry Crash Report:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Allen Winter 2024-10-27 09:12:38 UTC
Using freshly built from git master today on Linux Fedora.

In a session, move a tab to the left-most position.
quit kate
start kate
notice that the same tab is not restored to the left-most position

tab order in a session should be properly saved and restored
Comment 1 Christoph Cullmann 2024-10-27 11:34:26 UTC
Could you try

https://invent.kde.org/utilities/kate/-/merge_requests/1618



On 2024-10-27 10:12, Allen Winter wrote:
> https://bugs.kde.org/show_bug.cgi?id=495419
> 
>             Bug ID: 495419
>            Summary: Tab order is not properly restored
>     Classification: Applications
>            Product: kate
>            Version: Git
>           Platform: Other
>                 OS: Linux
>             Status: REPORTED
>           Severity: normal
>           Priority: NOR
>          Component: sessions
>           Assignee: kwrite-bugs-null@kde.org
>           Reporter: winter@kde.org
>   Target Milestone: ---
> 
> Using freshly built from git master today on Linux Fedora.
> 
> In a session, move a tab to the left-most position.
> quit kate
> start kate
> notice that the same tab is not restored to the left-most position
> 
> tab order in a session should be properly saved and restored
Comment 2 Allen Winter 2024-10-27 11:57:37 UTC
yes, that patch seems to work quite well
Comment 3 Christoph Cullmann 2024-10-27 15:11:05 UTC
Git commit d04ee358b6324730366ff7f00d545acaf3b375e8 by Christoph Cullmann.
Committed on 27/10/2024 at 15:11.
Pushed by cullmann into branch 'master'.

ensure we keep the tab order on session restore

M  +48   -1    apps/lib/autotests/kate_view_mgmt_test2.cpp
M  +2    -1    apps/lib/katemainwindow.h
M  +3    -1    apps/lib/katetabbar.h
M  +26   -10   apps/lib/kateviewspace.cpp

https://invent.kde.org/utilities/kate/-/commit/d04ee358b6324730366ff7f00d545acaf3b375e8
Comment 4 Christoph Cullmann 2024-10-27 15:11:25 UTC
Thanks for testing!
Comment 5 Waqar Ahmed 2024-11-06 12:13:10 UTC
*** Bug 495872 has been marked as a duplicate of this bug. ***
Comment 6 Christoph Cullmann 2024-11-12 18:08:26 UTC
*** Bug 496180 has been marked as a duplicate of this bug. ***
Comment 7 Allen Winter 2024-12-11 13:43:29 UTC
This is still happening (or regressed)

I have a session with a 13 documents/tabs
I move one of those tabs to the second position (from left) . then restart kate.
now that tab is in position 13 instead or restored to position 2.
Comment 8 Allen Winter 2024-12-11 13:44:44 UTC
forgot to mention this is with today's kate from git with HEAD 77c61734ca359e9486b320f754198b64c6f2be3f
Comment 9 Christoph Cullmann 2024-12-14 21:47:23 UTC
Hmmm, ok, bad. Not sure how that can happen, added some small test, too. That still works.
Comment 10 Allen Winter 2024-12-31 16:08:50 UTC
restoring tab order doesn't work even when switching sessions.

in sessionA, move tab in position4 to position2.
switch to sessionB
switch back to sessionA and notice that tab that should be in position2 is back in position4
Comment 11 Mihai Sorin Dobrescu 2025-01-04 07:01:49 UTC
Operating System: MocaccinoOS (Gentoo)
KDE Plasma Version: 6.2.4
KDE Frameworks Version: 6.7.0
Qt Version: 6.7.3
Kernel Version: 6.6.67-mocaccino (64-bit)
Graphics Platform: X11
Processors: 16 × 11th Gen Intel® Core™ i7-11700K @ 3.60GHz
Memory: 61.6 GiB of RAM
Graphics Processor: NVIDIA GeForce GTX 1060 6GB/PCIe/SSE2
Manufacturer: ASUS

I have this too.

It worked for a while after the upgrade to Kate 24.08.3 until I have closed one tab. That may have saved the session and broke it ever after.
The order does not make any sense now as the tabs are not even in some lexicographic order.
It is difficult to use it and to find the needed tab now.
Comment 12 Mihai Sorin Dobrescu 2025-02-27 08:02:55 UTC
I have noticed another thing that may be related.
If I have two files named the same, but opened from different paths, the document selector may chose the other file than the one the user peeks.
Comment 13 Nate Graham 2025-03-10 17:21:02 UTC
I can also confirm this, for me on current git master. The order seems to be scrambled on every launch.
Comment 14 Mihai Sorin Dobrescu 2025-03-11 07:18:47 UTC
I confirm Nate's remark.
The order seems to be related to the latter edited files, but I am not 100% sure.
Comment 15 Waqar Ahmed 2025-07-14 07:12:44 UTC
Seems like the Tab limit triggers this bug. With unlimited tabs, I wasn't able to reproduce. Once you have `num docs open` > `tab limit`, the bug manifests
Comment 16 Bug Janitor Service 2025-07-14 10:36:29 UTC
A possibly relevant merge request was started @ https://invent.kde.org/utilities/kate/-/merge_requests/1818
Comment 17 Christoph Cullmann 2025-07-14 18:14:08 UTC
Git commit 988e8514c3ba6b7b4325b97e1d08e25d28700cf4 by Christoph Cullmann, on behalf of Waqar Ahmed.
Committed on 14/07/2025 at 18:09.
Pushed by cullmann into branch 'master'.

Fix tab order restore with limited tabs

If the number of documents are greater than the user set "Tab Limit",
then tab order restore was broken. The existing implementation did
the simple thing:

```
// assume tab limit = 2
docList = [1, 2, 3]
// expected restore order = [2, 3]

register doc "1", // gets tab 0
register doc "2", // gets tab 1
register doc "3", // gets tab 0, replace 0 because its the lru doc

restored order = [3, 2] // incorrect
```

To fix this, we must do an additional pass over the tabs and restore
the tabs to what the docList says. We can do this simply by calling
setTabDocument for each document we have in the right order. To find
the right order, instead of traversing the docList again we can just
use m_registeredDocuments which stores the document in MRU order. So
for the above case, the order is:

```
m_registeredDocument = [3, 2, 1]
```

We can just reverse iterate m_registeredDocuments and fix the tabs. But
we can't just iterate it directly, we must first skip the documents that
don't have tabs. We can find that by simply subtracting the number of tabs
from m_registeredDocuments. This works because when saving session state
we always put the documents that don't have tabs first and then we add
the documents that have tabs.

Also add a test case for this so that it doesn't break again.
Signed-off-by: Waqar Ahmed <waqar.17a@gmail.com>

M  +76   -0    apps/lib/autotests/kate_view_mgmt_test2.cpp
M  +17   -0    apps/lib/kateviewspace.cpp
M  +1    -0    apps/lib/kateviewspace.h

https://invent.kde.org/utilities/kate/-/commit/988e8514c3ba6b7b4325b97e1d08e25d28700cf4
Comment 18 Christoph Cullmann 2025-07-14 18:14:16 UTC
Git commit c162bfc323230932ebfe85a280e7b8c5a7db8b2c by Christoph Cullmann, on behalf of Waqar Ahmed.
Committed on 14/07/2025 at 18:09.
Pushed by cullmann into branch 'master'.

Fix tab restore when "open to right of current tab" is true

When that setting is true it can mess up order of tabs. If the user
is using Unlimited tabs, they will not get restored correctly.

Disable this setting during session restore as it makes no sense here.

M  +74   -0    apps/lib/autotests/kate_view_mgmt_test2.cpp
M  +15   -0    apps/lib/katetabbar.h
M  +8    -0    apps/lib/kateviewspace.cpp

https://invent.kde.org/utilities/kate/-/commit/c162bfc323230932ebfe85a280e7b8c5a7db8b2c
Comment 19 Christoph Cullmann 2025-07-14 20:20:12 UTC
Git commit ece2a91479bae77eaec8661f268501ad3be52157 by Christoph Cullmann.
Committed on 14/07/2025 at 20:20.
Pushed by cullmann into branch 'release/25.08'.

Fix tab order restore with limited tabs

If the number of documents are greater than the user set "Tab Limit",
then tab order restore was broken. The existing implementation did
the simple thing:

```
// assume tab limit = 2
docList = [1, 2, 3]
// expected restore order = [2, 3]

register doc "1", // gets tab 0
register doc "2", // gets tab 1
register doc "3", // gets tab 0, replace 0 because its the lru doc

restored order = [3, 2] // incorrect
```

To fix this, we must do an additional pass over the tabs and restore
the tabs to what the docList says. We can do this simply by calling
setTabDocument for each document we have in the right order. To find
the right order, instead of traversing the docList again we can just
use m_registeredDocuments which stores the document in MRU order. So
for the above case, the order is:

```
m_registeredDocument = [3, 2, 1]
```

We can just reverse iterate m_registeredDocuments and fix the tabs. But
we can't just iterate it directly, we must first skip the documents that
don't have tabs. We can find that by simply subtracting the number of tabs
from m_registeredDocuments. This works because when saving session state
we always put the documents that don't have tabs first and then we add
the documents that have tabs.

Also add a test case for this so that it doesn't break again.
Signed-off-by: Waqar Ahmed <waqar.17a@gmail.com>


(cherry picked from commit 988e8514c3ba6b7b4325b97e1d08e25d28700cf4)

Co-authored-by: Waqar Ahmed <waqar.17a@gmail.com>

M  +76   -0    apps/lib/autotests/kate_view_mgmt_test2.cpp
M  +17   -0    apps/lib/kateviewspace.cpp
M  +1    -0    apps/lib/kateviewspace.h

https://invent.kde.org/utilities/kate/-/commit/ece2a91479bae77eaec8661f268501ad3be52157
Comment 20 Christoph Cullmann 2025-07-14 20:20:51 UTC
Git commit 3f9e2a040ed2827b2cd1d2f03b5996a4efba1a59 by Christoph Cullmann.
Committed on 14/07/2025 at 20:20.
Pushed by cullmann into branch 'release/25.08'.

Fix tab restore when "open to right of current tab" is true

When that setting is true it can mess up order of tabs. If the user
is using Unlimited tabs, they will not get restored correctly.

Disable this setting during session restore as it makes no sense here.


(cherry picked from commit c162bfc323230932ebfe85a280e7b8c5a7db8b2c)

Co-authored-by: Waqar Ahmed <waqar.17a@gmail.com>

M  +74   -0    apps/lib/autotests/kate_view_mgmt_test2.cpp
M  +15   -0    apps/lib/katetabbar.h
M  +8    -0    apps/lib/kateviewspace.cpp

https://invent.kde.org/utilities/kate/-/commit/3f9e2a040ed2827b2cd1d2f03b5996a4efba1a59