Bug 160626 - Selecting a style in the toolbar list sends it at the bottom of the list
Summary: Selecting a style in the toolbar list sends it at the bottom of the list
Status: VERIFIED FIXED
Alias: None
Product: LibreOffice
Classification: Unclassified
Component: Writer (show other bugs)
Version:
(earliest affected)
7.6.5.2 release
Hardware: x86-64 (AMD64) Linux (All)
: medium normal
Assignee: Heiko Tietze
URL:
Whiteboard: target:25.2.0
Keywords: bibisected, regression
Depends on:
Blocks: Writer-Styles-Paragraph-Combobox
  Show dependency treegraph
 
Reported: 2024-04-11 12:54 UTC by Kalytis
Modified: 2024-11-05 15:08 UTC (History)
4 users (show)

See Also:
Crash report or crash signature:


Attachments
Screenshot of the mentioned style list : "Titre 1" is at the bottom as it has just been selected, while he should be just above "Titre 2" (30.35 KB, image/png)
2024-04-11 12:55 UTC, Kalytis
Details
screenshot (355.96 KB, image/png)
2024-11-04 16:17 UTC, BogdanB
Details
screenshot (107.77 KB, image/png)
2024-11-04 16:20 UTC, BogdanB
Details
Demo document (10.33 KB, application/vnd.oasis.opendocument.text)
2024-11-05 07:17 UTC, BogdanB
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Kalytis 2024-04-11 12:54:46 UTC
Description:
My styles are in a certain order in my styles list. But when I select one to apply it to my document, upon reopening the list, my last selected style is at the bottom of the list.

Steps to Reproduce:
1. Open the styles list on toolbar
2. Select a style
3. Reopen the list

Actual Results:
Last selected style is at the bottom of the list.

Expected Results:
List should have stayed in the same order.


Reproducible: Always


User Profile Reset: No

Additional Info:
Version: 7.6.5.2 (X86_64) / LibreOffice Community
Build ID: 60(Build:2)
CPU threads: 12; OS: Linux 6.5; UI render: default; VCL: gtk3
Locale: fr-FR (fr_FR.UTF-8); UI: fr-FR
Ubuntu package version: 4:7.6.5-0ubuntu0.23.10.1
Calc: threaded
Comment 1 Kalytis 2024-04-11 12:55:57 UTC
Created attachment 193619 [details]
Screenshot of the mentioned style list : "Titre 1" is at the bottom as it has just been selected, while he should be just above "Titre 2"
Comment 2 Dieter 2024-05-01 11:25:27 UTC
I can't confirm it with

Version: 24.2.2.2 (X86_64) / LibreOffice Community
Build ID: d56cc158d8a96260b836f100ef4b4ef25d6f1a01
CPU threads: 4; OS: Windows 10.0 Build 19045; UI render: Skia/Raster; VCL: win
Locale: de-DE (de_DE); UI: en-GB
Calc: CL threaded

Des it also happen with a clean user profile?
=> NEEDINFO
Comment 3 QA Administrators 2024-10-30 03:09:47 UTC Comment hidden (obsolete)
Comment 4 Kalytis 2024-10-31 11:23:40 UTC
Yes, it keeps happening, even with a clean profile.
Comment 5 raal 2024-10-31 14:51:25 UTC
I can confirm wit Version: 25.2.0.0.alpha0+ (X86_64) / LibreOffice Community
Build ID: b0195d40f3abc343b88f767f4fe109a9c1d44347
CPU threads: 4; OS: Linux 6.8; UI render: default; VCL: gtk3
Locale: cs-CZ (cs_CZ.UTF-8); UI: en-US
Calc: threaded

but not with Version: 7.3.7.2 / LibreOffice Community
Build ID: 30(Build:2)
CPU threads: 4; OS: Linux 6.8; UI render: default; VCL: gtk3
Locale: cs-CZ (cs_CZ.UTF-8); UI: cs-CZ
Ubuntu package version: 1:7.3.7-0ubuntu0.22.04.7
Calc: threaded
Comment 6 raal 2024-10-31 14:58:53 UTC
This seems to have begun at the below commit in bibisect repository/OS linux-64-7.6.
Adding Cc: to Heiko Tietze ; Could you possibly take a look at this one?
Thanks
 bd12644c6d48cafa19e0fd5277f1070693c9a8e9 is the first bad commit
commit bd12644c6d48cafa19e0fd5277f1070693c9a8e9
Author: Jenkins Build User <tdf@pollux.tdf>
Date:   Wed Jan 11 17:18:33 2023 +0100

    source 95756934cf56e4a9ff58464bc0ed6881c15fe411

145268: Resolves tdf#152666 - Hide default styles for large lists | https://gerrit.libreoffice.org/c/core/+/145268
Comment 7 Heiko Tietze 2024-11-04 14:53:19 UTC
Let's give this a try. Please test with a nightly build.
Comment 8 Commit Notification 2024-11-04 14:53:33 UTC
Heiko Tietze committed a patch related to this issue.
It has been pushed to "master":

https://git.libreoffice.org/core/commit/117bca21b7b068266bb91f1d114e435e0a7ab525

Resolves tdf#160626 - Preserve sorting in SvxStyleToolBoxControl

It will be available in 25.2.0.

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

Affected users are encouraged to test the fix and report feedback.
Comment 9 BogdanB 2024-11-04 16:09:20 UTC Comment hidden (obsolete)
Comment 10 BogdanB 2024-11-04 16:16:08 UTC
Also, I have 23 styles I used in the document that all appear in the dropdown list. In the commit is mentioned: up to 12 default styles. I used for 23 different paragraphs, styles from Contents 1 to Contents 10 and from Heading 1 to Heading 10.
Comment 11 BogdanB 2024-11-04 16:17:27 UTC
Created attachment 197400 [details]
screenshot
Comment 12 BogdanB 2024-11-04 16:20:51 UTC Comment hidden (obsolete)
Comment 13 BogdanB 2024-11-04 17:13:24 UTC
I tested something on code, and it is working to keep just the last 12 styles.

On line 3247:
    // add used styles, keeping only the latest 12 entries
    pStyle = xIter->Next();
    while (pStyle)
    {
        if (aStyles.size() >= 12)
        {
            // Remove the oldest style to make room for the newest
            aStyles.erase(aStyles.begin());
        }
        
        // Add the latest style to the end of the list
        aStyles.push_back(pStyle->GetName());
        pStyle = xIter->Next();
    }

It worked for me on by build.


----
Also, another thing that I discovered testing this bug, that the sort is not correct.

If you use: Content 1, Content 2 and Content 10, they are sorted:
- Content 1, Content 10, Content 2, but should be:
- Content 1, Content 2, Content 10.
Comment 14 BogdanB 2024-11-04 17:44:35 UTC
I played a little bit with sorting and I succeeded sorting correctly:

#include <cctype>

bool naturalOrderComparator(const rtl::OUString& a, const rtl::OUString& b) {
    int posA = 0, posB = 0;
    int lenA = a.getLength();
    int lenB = b.getLength();

    while (posA < lenA && posB < lenB) {
        if (std::isdigit(a[posA]) && std::isdigit(b[posB])) {
            // Extract and compare numeric parts
            int numA = 0, numB = 0;
            while (posA < lenA && std::isdigit(a[posA])) {
                numA = numA * 10 + (a[posA] - '0');
                posA++;
            }
            while (posB < lenB && std::isdigit(b[posB])) {
                numB = numB * 10 + (b[posB] - '0');
                posB++;
            }
            if (numA != numB) {
                return numA < numB;
            }
        } else {
            // Compare non-numeric parts lexicographically
            if (a[posA] != b[posB]) {
                return a[posA] < b[posB];
            }
            posA++;
            posB++;
        }
    }
    return lenA < lenB;
}

// Sort aStyles with the custom comparator
std::sort(aStyles.begin(), aStyles.end(), naturalOrderComparator);

I don't want to change any code. I just tested for myself to test.
Comment 15 BogdanB 2024-11-04 18:39:21 UTC
(In reply to BogdanB from comment #9)
> I am testing on master now. I don´t know if it is from this commit or not,
> but if I the last style is Title, than More styles... will have Title size.
> If the last style is Signature, More Styles... will have that size for text.

This was already reported before:
https://bugs.documentfoundation.org/show_bug.cgi?id=159592
Comment 16 BogdanB 2024-11-05 07:17:49 UTC
Created attachment 197410 [details]
Demo document

Demo document to test: "Inserts now up to 12 default styles". There are more than 12 default styles in the dropdown.
Comment 17 Heiko Tietze 2024-11-05 07:32:04 UTC
(In reply to BogdanB from comment #10)
> Also, I have 23 styles I used in the document that all appear in the
> dropdown list. In the commit is mentioned: up to 12 default styles. I used
> for 23 different paragraphs, styles from Contents 1 to Contents 10 and from
> Heading 1 to Heading 10.
Exactly. The combobox lists three categories: default PS mostly for new documents, used PS filling the list infinitely and replacing the default styles, and the more button. The issue here was that using H1, for example, moves the entry from default to used. I fixed only this issue.

Not against other improvements but I see no good way to limit the number of used styles. Well, maybe perfection is not necessary on the control.
Comment 18 BogdanB 2024-11-05 15:08:25 UTC
Ok. I have verified. Fixed.
Thanks, Heiko.

Now everything is keeping its place.
Version: 25.2.0.0.alpha0+ (X86_64) / LibreOffice Community
Build ID: ad3f929a738292a519128192293c92bd5f96f025
CPU threads: 16; OS: Linux 6.8; UI render: default; VCL: gtk3
Locale: ro-RO (ro_RO.UTF-8); UI: en-US
Calc: threaded

Before when choosing Title, it moved on the last line
Version: 24.8.1.2 (X86_64) / LibreOffice Community
Build ID: 87fa9aec1a63e70835390b81c40bb8993f1d4ff6
CPU threads: 4; OS: Linux 6.8; UI render: default; VCL: gtk3
Locale: ro-RO (ro_RO.UTF-8); UI: en-US
Calc: threaded