Bug 169674 - Sort headings and retain their contents while moving them.
Summary: Sort headings and retain their contents while moving them.
Status: ASSIGNED
Alias: None
Product: LibreOffice
Classification: Unclassified
Component: Writer (show other bugs)
Version:
(earliest affected)
25.8.3.2 release
Hardware: All All
: medium enhancement
Assignee: Jim Raykowski
URL:
Whiteboard: target:26.8.0
Keywords:
Depends on:
Blocks: Navigator
  Show dependency treegraph
 
Reported: 2025-11-25 02:53 UTC by Ben Cottrell
Modified: 2026-01-14 23:38 UTC (History)
5 users (show)

See Also:
Crash report or crash signature:


Attachments
Demo of Navigator approach to do this (625.88 KB, video/x-matroska)
2026-01-14 05:57 UTC, Jim Raykowski
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Ben Cottrell 2025-11-25 02:53:31 UTC
Description:
In the sorting dialog, there isn't a mode picker for paragraphs and headings. In terms of splitting sections, this could be done up to where the next heading is found (maybe this could be specified by the dialog as well).

Steps to Reproduce:
1. Apply Level 1 heading style to lines of text
2. Add text beneath the headings
3. Click "Tools", "Sort".

Actual Results:
Both the headings and the contents within them are sorted; the original contents are not kept with the headings.

Expected Results:
Expected to see more options in the dialog, to control which styles control the sorting, and being able to sort headings, without affecting the order of the content in between them.


Reproducible: Always


User Profile Reset: No

Additional Info:
Version: 25.8.3.2 (X86_64) / LibreOffice Community
Build ID: 580(Build:2)
CPU threads: 12; OS: Linux 6.17; UI render: default; VCL: gtk3
Locale: en-NZ (en_NZ.UTF-8); UI: en-US
25.8.3-2
Calc: CL threaded
Comment 1 Dieter 2026-01-05 18:14:07 UTC
I confirm the current behaviour with

Version: 26.8.0.0.alpha0+ (X86_64)
Build ID: 680(Build:0)
CPU threads: 12; OS: Windows 11 X86_64 (build 26200); UI render: Skia/Raster; VCL: win
Locale: de-DE (de_DE); UI: en-GB
Calc: CL threaded

Not sure about a solution. I thought outline folding could be a solution, but sort commant is not available with outline folding.

cc: Design-Team
Comment 2 Heiko Tietze 2026-01-06 08:31:27 UTC
Took me a while to understand that Tools > Sort as well as Table > Sort requires some selection to work (but are also enabled on fields like the current date). And both .uno:SortDialog and .uno:TableSort seem to start the dialog.

I would not expect any paragraph sorting. However, a new command was implemented recently for bug 167491, which sorts the document chapters alphabetically. You need to enable experimental features and customize the command Sort Chapters / .uno:SortChapters manually into the UI. And this function keeps the text within the sorted chapter.

STR:

<H1>Beta>
123
<H1>Alpha>
456

select all, run tools > sort results in
123
456
<H1>Alpha</H1>
<H1>Beta</H1>

My take: One sort function for tables, another for text. With clear naming (we have four "Sort" available for customization).

Some options to define what level should be sorted sounds reasonable. But it complicates the workflow as you may ask for the level (eg. sort level 2 and 3 but not 1 and 4) or scope (eg. sort all levels in the current chapter). I suggest to not add these options and run the command from the Navigator either on Headings (sorting all chapters) or the "First Chapter" sorting all items below. This clashes with the current "Sort Alphabetically" that could become a toggle on the header. Or just renamed to "Sort List Alphabetically" (vs "Order Chapters Alphabetically"). Or consider radio buttons like bug 160951.

Table sort should (virtually) auto-select the table. For text sort I would always run the function on the entire text or parts if defined in some options dialog.
Comment 3 Heiko Tietze 2026-01-12 06:29:27 UTC
No further input, removing UX.

(In reply to Heiko Tietze from comment #2)
> run the command from the Navigator either on Headings 
> (sorting all chapters) or the "First Chapter" sorting all
> items below. This clashes with the current "Sort Alphabetically" that could
> become a toggle on the header. Or just renamed to "Sort List Alphabetically"
> (vs "Order Chapters Alphabetically"). Or consider radio buttons like bug
> 160951.
Is this feasible, Jim? Is this acceptable, edition?
Comment 4 Ben Cottrell 2026-01-12 22:09:58 UTC
(In reply to Heiko Tietze from comment #3)
> No further input, removing UX.
> 
> (In reply to Heiko Tietze from comment #2)
> > run the command from the Navigator either on Headings 
> > (sorting all chapters) or the "First Chapter" sorting all
> > items below. This clashes with the current "Sort Alphabetically" that could
> > become a toggle on the header. Or just renamed to "Sort List Alphabetically"
> > (vs "Order Chapters Alphabetically"). Or consider radio buttons like bug
> > 160951.
> Is this feasible, Jim? Is this acceptable, edition?

Note: changed name from "edition" to "Ben Cottrell"

No, keep it under the "Tools" menu.

If we want feature parity with Word, just sort the highest level headings. We could also include a "Sorting" button, which Word has on the "Paragraph" tab group, under the "Home" tab.

I suggest meeting the basic requirements for user expectations first, followed by more advanced features later.
Comment 5 Jim Raykowski 2026-01-14 05:57:00 UTC
Created attachment 205041 [details]
Demo of Navigator approach to do this

I was able to adapt what was done for the similar request in Bug 167491 for use by both that and this proposed approach using the Navigator.

To test, the enable experiment features needs to be checked in the Options dialog LibreOffice-Advanced tab page. (Menu > Tools > Options > LibreOffice > Advanced options)

The patch that does what is shown in the demo is here:
https://gerrit.libreoffice.org/c/core/+/197230
Comment 6 Ben Cottrell 2026-01-14 07:15:22 UTC
(In reply to Jim Raykowski from comment #5)
> Created attachment 205041 [details]
> Demo of Navigator approach to do this
> 
> I was able to adapt what was done for the similar request in Bug 167491 for
> use by both that and this proposed approach using the Navigator.
> 

Could this be adapted to the sort dialog, accessed under the tools menu?
Comment 7 Heiko Tietze 2026-01-14 07:34:46 UTC
(In reply to Jim Raykowski from comment #5)
> Demo of Navigator approach to do this
Awesome!

(In reply to Ben Cottrell from comment #6)
> Could this be adapted to the sort dialog, accessed under the tools menu?
Please don't. What we have now as Sort under Tool should become Table > Sort, run unconditionally, meaning not depending on a selection, for the whole table.

The Navigator approach is simple, easy to use and to understand by average users. Having the sort by chapter function in a dialog requires some kind of interface for the chapters which would be over-engineering.
Comment 8 Ben Cottrell 2026-01-14 08:23:56 UTC
(In reply to Heiko Tietze from comment #7)
> (In reply to Jim Raykowski from comment #5)
> > Demo of Navigator approach to do this
> Awesome!
> 
> (In reply to Ben Cottrell from comment #6)
> > Could this be adapted to the sort dialog, accessed under the tools menu?
> Please don't. What we have now as Sort under Tool should become Table >
> Sort, run unconditionally, meaning not depending on a selection, for the
> whole table.
> 
> The Navigator approach is simple, easy to use and to understand by average
> users. Having the sort by chapter function in a dialog requires some kind of
> interface for the chapters which would be over-engineering.

OK, how about a separate dialog for sorting headers instead, say, in the edit menu, in the short term? 

As there may be lots of users coming from Microsoft Word, I think it would be helpful to ease the learning curve. It's also useful to have things accessible in fewer clicks as possible.
Comment 9 Commit Notification 2026-01-14 22:04:54 UTC
Jim Raykowski committed a patch related to this issue.
It has been pushed to "master":

https://git.libreoffice.org/core/commit/9be7dacd773ee32a3d50dba77115fbee92506cea

tdf#169674 Sort headings and retain their contents while moving them

It will be available in 26.8.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 10 Jim Raykowski 2026-01-14 22:49:00 UTC
@Ben: Thanks for the ideas!

I didn't know of the Sort dialog until seeing your request here. I agree with Heiko that there should be separate dialogs for tables and text: "My take: One sort function for tables, another for text."

How would a text sort dialog look? Maybe a mock-up would be a good place to start?
Comment 11 Ben Cottrell 2026-01-14 23:38:05 UTC
(In reply to Jim Raykowski from comment #10)
> @Ben: Thanks for the ideas!
> 
> I didn't know of the Sort dialog until seeing your request here. I agree
> with Heiko that there should be separate dialogs for tables and text: "My
> take: One sort function for tables, another for text."
> 
> How would a text sort dialog look? Maybe a mock-up would be a good place to
> start?

Could just borrow the design from Word, like this screenshot:

https://external-content.duckduckgo.com/iu/?u=https%3A%2F%2Fcdn.extendoffice.com%2Fimages%2Fstories%2Fdoc-word%2Fsort-by-last-name%2Fdoc-sort-by-last-name-4.png&f=1&nofb=1&ipt=6277cf682af417399f7012e35716f4e5b92b5cf6a6ea080f56ff9bd18b4870f5