Bug 99672 - Replace All with format in search and empty replace text does not replace.
Summary: Replace All with format in search and empty replace text does not replace.
Status: RESOLVED FIXED
Alias: None
Product: LibreOffice
Classification: Unclassified
Component: Writer (show other bugs)
Version:
(earliest affected)
Inherited From OOo
Hardware: All All
: medium normal
Assignee: Andreas Heinisch
URL:
Whiteboard: target:26.8.0
Keywords:
: 112840 118174 (view as bug list)
Depends on:
Blocks: Find-Search Formatting-Text-Diverse
  Show dependency treegraph
 
Reported: 2016-05-04 11:56 UTC by Pieter van Oostrum
Modified: 2026-04-22 03:01 UTC (History)
7 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 Pieter van Oostrum 2016-05-04 11:56:48 UTC
In the Find & Replace Dialog a Replace All with an empty replace text does not function if the search criterium contains a Format.

To reproduce:
1. Open a new Writer document
2. Enter some text and sprinkle the word "test" a couple of times in it.
3. Give (some of) the words "test" a font color, e.g. Red.
4. Open the Replace & Find dialog.
5. In the find text field enter "test" (without the quotes). Leave the replacement text empty.
6. Click Other Options > Format > Font Effects > Font color and select Red
7. Click Replace All.

The dialog answers with "Search key replaced xx times." but in reality the texts are not replaced.

Replace All does work if no format is selected, and/or if the replacement text is not empty.
It also fails if other formats are selected, e.g. Font.

An easy workaround is to click "find All" and then delete the selected text, but the Replace All should also work.
Comment 1 raal 2016-05-05 07:59:17 UTC
I can confirm with Version: 5.2.0.0.alpha0+, 4.5 ; win7
Comment 2 QA Administrators 2017-05-22 13:38:44 UTC Comment hidden (noise, obsolete)
Comment 3 Thomas Lendo 2018-06-14 22:27:17 UTC
*** Bug 118174 has been marked as a duplicate of this bug. ***
Comment 4 QA Administrators 2019-06-15 02:59:28 UTC Comment hidden (noise)
Comment 5 David Bolton 2019-06-24 16:10:08 UTC
If the Replace field and formatting is empty, Replace All does nothing (other than highlight the occurrences). 

If the Replace field has no text but has formatting, it swaps out the formatting (but does not delete the text). 

I would expect an empty Replace field to delete all found occurrences (like it does for plain text find and replace). 


Tested using: 

Version: 6.2.4.2 (x64)
Build ID: 2412653d852ce75f65fbfa83fb7e7b669a126d64
CPU threads: 4; OS: Windows 10.0; UI render: default; VCL: win; 
Locale: en-US (en_US); UI-Language: en-US
Calc: threaded
Comment 6 stragu 2021-06-28 14:06:56 UTC
Reproduced in:

Version: 7.3.0.0.alpha0+ / LibreOffice Community
Build ID: f446a203fa2897bab8ae7686c948a8bf060675c6
CPU threads: 8; OS: Linux 4.15; UI render: default; VCL: gtk3
Locale: en-AU (en_AU.UTF-8); UI: en-US
TinderBox: Linux-rpm_deb-x86_64@86-TDF, Branch:master, Time: 2021-06-24_15:16:38
Calc: threaded

and:

Version: 7.2.0.0.beta1 / LibreOffice Community
Build ID: c6974f7afec4cd5195617ae48c6ef9aacfe85ddd
CPU threads: 8; OS: Linux 4.15; UI render: default; VCL: gtk3
Locale: en-AU (en_AU.UTF-8); UI: en-US
Calc: threaded
Comment 7 stragu 2021-06-28 14:10:37 UTC
*** Bug 112840 has been marked as a duplicate of this bug. ***
Comment 8 stragu 2021-06-28 14:11:39 UTC
According to duplicate Bug 112840, this is inherited from OOo.
Comment 9 QA Administrators 2025-05-22 03:13:10 UTC Comment hidden (noise)
Comment 10 Pieter van Oostrum 2026-03-13 15:06:25 UTC
Tested again with LibreOffice 26.2.1.2 (build 8399f6259d8c87f40e7255cdb3c9b958f5e08948) AARCH64)

The bug is still the same.
Comment 11 Mike Kaganski 2026-03-15 07:51:32 UTC
Having empty replace field has special semantics, when formatting is used.

1. You may have both Find box and Replace box empty; have Find format X, and Replace format Y: this finds all occurrences of formatting X, and replaces with formatting Y, *keeping text*.
2. You may have some text in Find box, and empty Replace box; have Find format X, and Replace format Y: this finds all occurrences of formatting X *on Find text*, and replaces with formatting Y, *keeping text*.

Note that empty Replace consistently means *keep text* here!

Basically, in this case, it also "replaces", as it claims - just the empty replacement formatting means "do not apply any changes".

The "replace text with nothing" could be only a reasonable expectation in case when "replace" set is also empty...
Comment 12 Mike Kaganski 2026-03-15 08:11:12 UTC
(In reply to Mike Kaganski from comment #11)
> The "replace text with nothing" could be only a reasonable expectation in
> case when "replace" set is also empty...

And even then: what would be a reasonable expectation, when Find text is empty, too (only Find formatting is set)?
Comment 13 Andreas Heinisch 2026-03-15 09:36:41 UTC
I think of searching a format and replacing it leaving the replace box empty should replace the text. However, if you add a format change and an empty box, the text should remain. Can this be a viable option?
Comment 14 Pieter van Oostrum 2026-03-15 13:45:15 UTC
(In reply to Andreas Heinisch from comment #13)
> I think of searching a format and replacing it leaving the replace box empty
> should replace the text. However, if you add a format change and an empty
> box, the text should remain. Can this be a viable option?

The last item, yes. An empty text with a format does not make sense, so if there is a replace format and the replace text is empty, leaving the text unchanged is a logical option.

However, this leaves us with one ambiguous case: If the search text has a format selected, and the rplace text is empty end the replace format is empty, y=this could mean two things:
1. remove the text (obviously with the format).
2. remove the format, but leave the text.

The use should then have the possibility to indicate which one is desired. It should be clearly indicated, son that the user is aware that both are possible.

I see two possibilities:
1. an option to indicate "leave the text unchanged". This removes any ambiguity.
2. an option "remove format".

There is also "Attributes". Does the same apply to these?
Comment 15 Andreas Heinisch 2026-03-16 14:01:44 UTC
Current discussion: https://gerrit.libreoffice.org/c/core/+/201713
Comment 16 Mike Kaganski 2026-03-16 14:40:45 UTC
(In reply to Pieter van Oostrum from comment #14)
> However, this leaves us with one ambiguous case: If the search text has a
> format selected, and the rplace text is empty end the replace format is
> empty, y=this could mean two things:
> 1. remove the text (obviously with the format).
> 2. remove the format, but leave the text.

In no case the empty replace format means "remove format". Format is only positive, never negative: what is explicitly defined in format gets applied (replacing current value of that property), but missing properties are not unset. So - no ambiguity here.
Comment 17 Pieter van Oostrum 2026-03-16 20:31:30 UTC
(In reply to Mike Kaganski from comment #16)
> (In reply to Pieter van Oostrum from comment #14)
> > However, this leaves us with one ambiguous case: If the search text has a
> > format selected, and the rplace text is empty end the replace format is
> > empty, y=this could mean two things:
> > 1. remove the text (obviously with the format).
> > 2. remove the format, but leave the text.
> 
> In no case the empty replace format means "remove format". Format is only
> positive, never negative: what is explicitly defined in format gets applied
> (replacing current value of that property), but missing properties are not
> unset. So - no ambiguity here.

So then how do you accomplish this: from all texts matching a regular explression with color red, remove the red color? My guess would be to have the format empty in the replacement. Unless there would be an option  "remove format".
Comment 18 Mike Kaganski 2026-03-17 04:42:25 UTC
(In reply to Pieter van Oostrum from comment #17)
> So then how do you accomplish this: from all texts matching a regular
> explression with color red, remove the red color? My guess would be to have
> the format empty in the replacement. Unless there would be an option 
> "remove format".

1. You are changing the topic of this specific issue. Anything except "Replace All with format in search and empty replace text does not replace" is off-topic here, and needs a separate report / discussion.

2. Answering it, though. First, what does "remove color" mean? Do you imagine a "text without a color"? Or is your idea "apply automatic color"? Or are you talking about resetting the color to inherited value - translated as "remove direct formatting"? Depending on your answer: "remove color" in strong sense is meaningless; applying automatic color means you explicitly choose automatic color, so again have a setting in the formatting set; and there was never, and still is not, a "remove direct formatting" mode of the discussed dialog (so implementing that would be a new feature - again, for a separate report). And its implementation would still require you to explicitly define which properties you intend to reset (so you would have to choose a property, likely some special "reset" value, which would then be in the formatting set, and will be "applied" in a special way by the operation).
Comment 19 Commit Notification 2026-03-18 17:36:15 UTC
Andreas Heinisch committed a patch related to this issue.
It has been pushed to "master":

https://git.libreoffice.org/core/commit/73b7ac240ecb8f875e869744d60651280a7945fa

tdf#99672 - Allow replace with empty string when a search format is set

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 20 Franklin Weng 2026-04-22 03:01:15 UTC
(In reply to Commit Notification from comment #19)
> Andreas Heinisch committed a patch related to this issue.
> It has been pushed to "master":
> 
> https://git.libreoffice.org/core/commit/
> 73b7ac240ecb8f875e869744d60651280a7945fa
> 
> tdf#99672 - Allow replace with empty string when a search format is set
> 
> 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.

Please see tdf#171825.  Similar issue, but different scenario.  

In my test case, I set format and leave "Find" field empty, but fill the "Replace" field (that's the case our users reported back).  Replace works, but not Replace All.  And this commit does not fix our case.