Bug 151889 - CLEAR FORMATTING: Give option to clear every formatting in a single step
Summary: CLEAR FORMATTING: Give option to clear every formatting in a single step
Status: RESOLVED WONTFIX
Alias: None
Product: LibreOffice
Classification: Unclassified
Component: Writer (show other bugs)
Version:
(earliest affected)
7.4.2.3 release
Hardware: All All
: medium enhancement
Assignee: Not Assigned
URL:
Whiteboard:
Keywords:
Depends on:
Blocks: Clear-Formatting DoAsMacro
  Show dependency treegraph
 
Reported: 2022-11-04 08:14 UTC by Orwel
Modified: 2022-11-18 09:52 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 Orwel 2022-11-04 08:14:10 UTC
Description:
I was often using Clear Direct Formatting (CDF) feature (found in Menu/Format) to all formats. The CDF change to default only the Character style (it removes Bold, Italic, Underline) but not the paragraph style.
I suppose there should be either some other function which clears all formatting changes (inclusive paragraph style) to default, or CDF function should do it.

You have not the possibility to "clear" a new line or some marked text to default and you have to manually change the style.

Steps to Reproduce:
1. Write some text in Default paragraph style.
2. Change the style to some other style, e.g. Heading 1.
3. Mark the changed style and press Clear Direct Formatting.


Actual Results:
The style of the text remains as Heading 1

Expected Results:
Either also style should change to Default paragraph style when using CDF or some other clear formatting feature should be added, which clears all kinds of formatting changes and set everything to default.


Reproducible: Always


User Profile Reset: Yes

Additional Info:
Version: 7.4.2.3 (x64) / LibreOffice Community
Build ID: 382eef1f22670f7f4118c8c2dd222ec7ad009daf
CPU threads: 16; OS: Windows 10.0 Build 19042; UI render: Skia/Raster; VCL: win
Locale: sk-SK (sk_SK); UI: en-GB
Calc: CL
Comment 1 Rafael Lima 2022-11-04 12:31:20 UTC
Hi Orwel, thanks for reporting.

It is not the purpose of CDF to remove styles applied to text. It only removes direct formatting applied on top of styles.

From the help page:

Applied styles (paragraph, character, and other types) are not affected by Clear Direct Formatting, only direct formatting applied on top of the styles. To remove formatting applied by a character or paragraph style, reapply the corresponding Default style.

Link: https://help.libreoffice.org/latest/en-US/text/shared/01/05010000.html
Comment 2 LeroyG 2022-11-06 15:57:26 UTC
(In reply to Orwel from comment #0)
> but not the paragraph style.

If Border, Alignment, and all other options under menu Format - Paragraph are applied to a paragraph, Clear Direct Formatting will clear them if the cursor is in a paragraph, but no character is selected.

Take note that Styles are not Direct Formatting.

Not a bug for me.
Comment 3 Orwel 2022-11-07 14:41:33 UTC
Hi, thank you for the answer. I did not report it as a bug, but as an enhancement. It would be great if some options, which clears everything to DEFAULT (text/style/paragraph...) would exist.
Comment 4 Dieter 2022-11-08 20:27:11 UTC
(In reply to Orwel from comment #3)
> Hi, thank you for the answer. I did not report it as a bug, but as an
> enhancement. It would be great if some options, which clears everything to
> DEFAULT (text/style/paragraph...) would exist.

You just have to select "Default Paragraph Style". Why this isn't sufficient for you? Do you need a keyboard shortcut for it?
=> NEEDINFO
Comment 5 Orwel 2022-11-09 10:30:11 UTC
Hi,
exactly, shortcut would do it also. I know there is the shortcut CTRL+0 which set the paragraph style to default. But what I am speaking about is some function (or shortcut) which clears any (maybe marked) text setting to default:
- there is a shortcut for Clear direct formatting (which removes, bold, italic... but not numbering, paragraph style...),
- there is a shortcut for Default paragraph style (which does not removes numbering, intends,...).

It would be useful, if I had a shortcut to clear all formats (character, paragraphs style, removing numbering, intends and also pressed TAB, alignments, text flow...) and set it to default in the marked line, like it is set, when you start typing in a blank document (this means, default of your template) - this means default text style, paragraph style, no intends-text starts on the very left margin...)
Comment 6 QA Administrators 2022-11-10 04:03:59 UTC Comment hidden (obsolete)
Comment 7 Dieter 2022-11-10 16:03:00 UTC
(In reply to Orwel from comment #5)
> Hi,
> exactly, shortcut would do it also.
O.K., let's ask design-team. I've changes bug summary and hope you agree.

> I know there is the shortcut CTRL+0
> which set the paragraph style to default.
CTRL+0 changes text to "Text Body". So not clear to me, if you're talking about text body or default paragraph style
Comment 8 Orwel 2022-11-10 19:46:33 UTC
(In reply to Dieter from comment #7)
> O.K., let's ask design-team. I've changes bug summary and hope you agree.
Perfect, thank you Dieter, also for the change in summary.

> CTRL+0 changes text to "Text Body". So not clear to me, if you're talking
> about text body or default paragraph style
I had probably made a change in shortcuts... I have on CTRL+0: Menu/View/Toolbars/Customize/Keyboard: 
-Category: Styles/Paragraph
-Function: Default paragraph style.
Comment 9 Heiko Tietze 2022-11-14 14:28:29 UTC
Ctrl+M clears direct formatting on the character level (font color, size etc.) and the paragraph level (manual indention, alignment etc.). It does not reset any other style like character, page, list or table style.

The shortcut ctrl+0 applies the PS "Text Body" to the current selection. And the two functions should not get mixed. 

It makes not much sense to remove all styles. And CDF works as expected. What I could imagine but it's likely not helping you is to have a modifier key (like shift+ctrl+M) to not only remove DF but also CS.

I disagree with the CC'ed  bug 78371. Splitting CDF into CDCF and CDPF makes only sense when the format is badly applied.
Comment 10 Orwel 2022-11-15 14:12:00 UTC
(In reply to Heiko Tietze from comment #9)
> It makes not much sense to remove all styles.

I do not agree with this summary. I work with lot of .doc and .docx documents, which other people using MS Word of different versions are correct/annotate. Although LibreOffice improved in last few years in compatibility, I am often confronted with some compatibility issues. If the whole document was prepared by me in LO and some changes are made by people using MS Word I often got broken paragraphs, numbering...

For this reason a "Clear every format change" (paragraph, character, numbering...) to get a raw default setting on a specific line/marked text like it is at the start on a blank document (this means with default values from template) would bring a lot of time savings, as I would not be forced to look for the specific change MS Word/LO incompatibility made, because I know, how should the formatting be like, but the compatibility issues prevent sometimes the changes made simply by changing paragraph style, numbering, ....
Comment 11 Orwel 2022-11-15 14:32:07 UTC
I would like to amend, that what I was looking for is possible to create with a Record Macro (with F3/Default Paragraph style, No character Style, No list) and assigning a shortcut to it. But for people who are not familiar with macro recording a possibility in Format menu list of such format change would be much more easier.
Comment 12 Heiko Tietze 2022-11-15 14:44:54 UTC
(In reply to Orwel from comment #11)
> But for people who are not familiar
> with macro recording a possibility in Format menu list of such format change
> would be much more easier.

You could pack this macro into an extension and share it on our site.
Comment 13 Orwel 2022-11-15 18:15:36 UTC
(In reply to Heiko Tietze from comment #12)

> You could pack this macro into an extension and share it on our site.

Sorry, I am not familiar with this procedure. But it is simple:
1. Highlight some text
2. F3 (menu/View/Styles)
3. Tools/Macros/Record macro
4. On Paragraph styles (in F3 window): Default paragraph style,
5. On Character styles (in F3 window): No character style,
6. On List styles (in F3 window): No list,
7. Stop recording macro, save it and set some shortcut.
Comment 14 Heiko Tietze 2022-11-16 07:40:42 UTC
(In reply to Orwel from comment #13)
>> You could pack this macro into an extension and share it on our site.
> Sorry, I am not familiar with this procedure. But it is simple:

https://wiki.documentfoundation.org/Development/Create_a_Hello_World_LibreOffice_extension
Comment 15 Rafael Lima 2022-11-16 12:03:26 UTC
Let's associate this with bug 145878 (DoAsExtension).

Maybe someone might be interested in implementing this extension. The steps described by the OP shouldn't be too difficult to implement as a macro and then converted into an extension.
Comment 16 Rafael Lima 2022-11-16 14:25:47 UTC
Hi Orwell, can you please test if this macro does what you need?

Sub ClearEverything
    ' Get the current selection
    Dim oSel as Object
    oSel = ThisComponent.CurrentSelection
    
    ' Dispatch helper to use the CDF command
    Dim oProvider as Object
    Dim oDispHelper as Object
    oProvider = ThisComponent.CurrentController.Frame
    oDispHelper = CreateUnoService("com.sun.star.frame.DispatchHelper")
    
    ' First of all apply the CDF command to the entire selection
    oDispHelper.executeDispatch(oProvider, ".uno:ResetAttributes", "", , Array())
    
    ' Traverse all text ranges
    Dim rangeCount as Integer, i as Integer
    Dim oEnum as object, oElement as Object
    rangeCount = oSel.getCount()
    For i = 0 To rangeCount - 1
        ' Traverse all text elements
        oTextRange = oSel.getByIndex(i)
        oEnum = oTextRange.createEnumeration()
        Do While oEnum.hasMoreElements()
            oElement = oEnum.nextElement()
            With oElement
                ' Clear paragraph style
                .ParaStyleName = "Default Paragraph Style"
                ' Cleat character style
                .CharFontStyleName = ""
                .CharFontStyleNameAsian = ""
                .CharFontStyleNameComplex = ""
                .CharStyleName = "No Character Style"
                ' Clear list format
                .ListId = ""
                .NumberingIsNumber = False
                .NumberingStyleName = ""
            End With
        Loop
    Next i
End Sub
Comment 17 Orwel 2022-11-18 09:52:05 UTC
(In reply to Rafael Lima from comment #16)
> Hi Orwell, can you please test if this macro does what you need?
> 

Hi Rafael, it works perfect. May be give a thought to the label of the macro as it clears the whole paragraph formatting although you mark only a part of text in the paragraph. The behavior is as I intended, but some people not familiar with our discussion could be confused by the name. What about:
ClearAllFormatsInParagraph or
ClearEverythingInParagraph

instead of simple ClearEverything.

But it is only a thought, it  is on you.