Bug 116261 - CALC FORMATTING editing in-cell attributed content (rich text) in the Input Line removes attribution from cell content
Summary: CALC FORMATTING editing in-cell attributed content (rich text) in the Input L...
Status: NEW
Alias: None
Product: LibreOffice
Classification: Unclassified
Component: Calc (show other bugs)
Version:
(earliest affected)
Inherited From OOo
Hardware: All All
: medium normal
Assignee: Not Assigned
URL:
Whiteboard:
Keywords:
Depends on: 155453
Blocks: Cell-Direct-Formatting-Parts
  Show dependency treegraph
 
Reported: 2018-03-07 10:25 UTC by Elyse Cordeau
Modified: 2024-10-26 16:56 UTC (History)
9 users (show)

See Also:
Crash report or crash signature:


Attachments
Try to change the color of some characters of the cells A2, A3, A4 or A5 (16.14 KB, application/vnd.oasis.opendocument.spreadsheet)
2018-03-07 10:25 UTC, Elyse Cordeau
Details
The bug, step by step, with images (7.38 KB, image/png)
2018-03-07 15:48 UTC, Elyse Cordeau
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Elyse Cordeau 2018-03-07 10:25:51 UTC
Created attachment 140421 [details]
Try to change the color of some characters of the cells A2, A3, A4 or A5

It seems that calc interprets some text cells as a formula when it comes to formatting.

1) I type in a cell a text that starts with the character '+' or '-', and that this text contains at least once a cell reference (ex: "+ foofoo A7 foofoo")

2) If I change the color of some characters (not the whole cell!), for example the 2nd foo (ex: "+ foo<foo> A7 foofoo"), it works.

=> Here, we already see that A7 becomes blue as if it were a formula.

3) But if you modify the cell (selection, add a space, ...), the color goes away.

Yet I tried to see with TYPE or ISFORMULA functions, but these cells look like text (left alignment).
Comment 1 Jacques Guilleron 2018-03-07 14:59:53 UTC
Hi Elyse,

I don't reproduce with
LO 6.0.2.1 Build ID: f7f06a8f319e4b62f9bc5095aa112a65d2f3ac89
Threads CPU : 2; OS : Windows 6.1; UI Render : par défaut; 
Locale : fr-FR (fr_FR); Calc: CL
Can you precise your OS, please?
Comment 2 Elyse Cordeau 2018-03-07 15:48:13 UTC
Created attachment 140442 [details]
The bug, step by step, with images
Comment 3 Elyse Cordeau 2018-03-07 15:52:34 UTC
Hi Jacques,

Thank you for your test!

I tested both on linux and windows and get the same behaviour.

Version: 6.0.2.1 (x64)
Build ID: f7f06a8f319e4b62f9bc5095aa112a65d2f3ac89
CPU threads: 2; OS: Windows 10.0; UI render: default; 
Locale: en-US (en_US); Calc: group

Version: 6.0.2.1
Build ID: f7f06a8f319e4b62f9bc5095aa112a65d2f3ac89
CPU threads: 4; OS: Linux 4.13; UI render: default; VCL: gtk2; 
Locale: fr-FR (fr_FR.UTF-8); Calc: group

But perhaps I did'nt explain it clearly (sorry for my english), so I added an attachment with images.
Comment 4 Xavier Van Wijmeersch 2018-03-07 18:30:10 UTC
confirm  with

Version: 6.1.0.0.alpha0+
Build ID: a790ee54319583897d82d4372243df870d4452a6
CPU threads: 8; OS: Linux 4.14; UI render: default; VCL: kde4; 
Locale: nl-BE (en_US.UTF-8); Calc: group
Comment 5 Jacques Guilleron 2018-03-07 18:59:07 UTC
This time, I reproduce it.
However, when I isolate + by putting it between quotes, I don't reproduce this effect. Do you agree? And it seems to happen only with this key/operator.
Comment 6 Jacques Guilleron 2018-03-07 23:09:20 UTC
Try this also with
LO  3.5.3.2 Version ID : 235ab8a-3802056-4a8fed3-2d66ea8-e241b80 under Windows 7 with the same behavior.
So probably inherited from OOo.
Comment 7 Xavier Van Wijmeersch 2018-03-08 07:52:38 UTC Comment hidden (obsolete)
Comment 8 Thomas Lendo 2018-03-13 22:30:35 UTC
Elyse, do you work on a patch for this as you are the assignee? Please only assign a bug to yourself if you work to fix it in the source code.

I downloaded the attached file and tried the steps in A15. As a result, the red colored text is only changed to blue during cell editing (then LibreOffice handles 'A1' as a formula reference to cell A1). After leaving the cell, the text is red again.

But if I colorize 'ffero' behind 'A1' in red, edit the cell and add a space at the end of the cell text and then go to another cell, then the red color of 'ffero' is gone.

Version: 6.1.0.0.alpha0+ 
Build ID: cab04bc39b5164ea74216cd849c3af5f5b298f79
CPU threads: 4; OS: Linux 4.13; UI render: default; VCL: gtk3; 
Locale: de-DE (de_DE.UTF-8); Calc: group
Comment 9 Xisco Faulí 2018-06-12 09:27:50 UTC Comment hidden (obsolete)
Comment 10 QA Administrators 2019-06-13 03:00:31 UTC Comment hidden (obsolete)
Comment 11 QA Administrators 2021-06-13 03:48:10 UTC Comment hidden (obsolete)
Comment 12 Stéphane Guillou (stragu) 2023-05-22 17:54:47 UTC
reproduced in recent master build:

Version: 7.6.0.0.alpha1+ (X86_64) / LibreOffice Community
Build ID: f4c24da1e7f11664e0d2f688d2531f068e4a3bc0
CPU threads: 8; OS: Linux 5.15; UI render: default; VCL: gtk3
Locale: en-AU (en_AU.UTF-8); UI: en-US
Calc: threaded

However, as you assumed correctly, this is due the contents of the cell being understood as a formula ("=" is usually used, but "+" and "-" can also do that).

It is true that it is awkward that the formatting can be kept until the "formula" is modified.
It is also possible to format a formula starting with "=", but it shouldn't be visible when finished editing because it usually displays the results (or an error).

Eike an UX team, kind of related to the confusion in bug 132026 and bug 129369, there's the bigger question: why doesn't a formula that starts with +/- behave more like a formula starting with "=", i.e. either giving the result of the formula or errorring if it's invalid?
Comment 13 Heiko Tietze 2023-05-23 10:12:18 UTC
Cannot confirm. Is View > Value Highlighting / Ctrl+F8 on or off? (If on all colors are gone.)
Comment 14 Eike Rathke 2023-05-23 11:16:14 UTC
Also can't confirm. Just works.

Version: 7.5.4.0.0+ (X86_64) / LibreOffice Community
Build ID: b6c0738f2a1906c2b5a967793e9b065a1b43d75e
Locale: en-CA (en_CA.UTF-8); UI: en-US

Also works in
Version: 7.6.0.0.alpha0+ (don't have a current 7.6.0.0.alpha1+ at hand).

Note that in the sample document only A4 has the Text format applied, A2,A3,A5 have the General number format applied but the cell content is text. Also note that while editing A3 the content is prefixed with an ' apostrophe. This may had been different 5 years ago when this bug was created. But that wouldn't explain why Stéphane could reproduce it with 7.6.0.0.alpha1+.


(In reply to Stéphane Guillou (stragu) from comment #12)
> why doesn't a formula that starts with
> +/- behave more like a formula starting with "=", i.e. either giving the
> result of the formula or errorring if it's invalid?
I don't understand the question. How do +/- and = differ?
Comment 15 Stéphane Guillou (stragu) 2023-05-23 12:48:00 UTC
(In reply to Heiko Tietze from comment #13)
> Cannot confirm. Is View > Value Highlighting / Ctrl+F8 on or off? (If on all
> colors are gone.)

Value highlighting is off for me.

I have noticed that using the formula bar vs editing directly in the cell does matter for reproducing the bug, and that this is not just about formulas in 7.6 anymore.

Steps:
1. Open Calc
2. enter the following string in a cell, but don't press Enter: + one A1 two
3. make "one" red, press Enter
 -> quote prefix is not added even though the formula is not valid; formatting persists
4. select cell, and _in the formula bar_ add a space at the end of the string
 -> partial direct formatting is lost; prefix is again hidden when out of edit mode

So it seems that editing the value in the formula bar automatically interprets it as a formula, and therefore removes the formatting, even if the end result is still an invalid formula.

This is the same in OOo 3.3, but note the differences between OOo 3.3 and LO 7.6:
- format lost in LO 7.6 even if there is no cell reference (using only "+ one two")
- format lost in LO 7.6 even if there is no +/- (using only "one two")
- format lost in OOo 3.3 even when editing directly in the cell

Somewhat related:

Steps:
1. Open Calc
2. enter the following string in a cell and press Enter: + one A1 two
 -> note the ' prefix is automatically added, because not a valid formula
3. make "one" red, press Enter
 -> quote prefix does not automatically hide anymore when out of edit mode
4. add a space at the end of the string
 -> partial direct formatting is lost; prefix is again hidden when out of edit mode

(In reply to Eike Rathke from comment #14)
> I don't understand the question. How do +/- and = differ?

I was thinking of the difference in output between these two formulas:
=2+test
+2+test

...but I realise now that a single quote should always be prepended when the formula is not valid, whereas an equal sign is prepended when it is. So scrap that comment :)
Comment 16 Heiko Tietze 2023-05-23 13:00:57 UTC
(In reply to Stéphane Guillou (stragu) from comment #15)
> 3. make "one" red, press Enter
>  -> quote prefix is not added even though the formula is not valid;
confirming

> 4. select cell, and _in the formula bar_ add a space at the end of the string
>  -> partial direct formatting is lost; prefix is again hidden when out of
> edit mode
not confirming

Version: 7.5.3.2 (X86_64) / LibreOffice Community
Build ID: 50(Build:2)
CPU threads: 8; OS: Linux 6.3; UI render: default; VCL: kf5 (cairo+xcb)
Locale: de-DE (en_US.UTF-8); UI: en-US
7.5.3-2
Calc: threaded

(In reply to Stéphane Guillou (stragu) from comment #12)
> why doesn't a formula that starts with +/- behave more like a formula
> starting with "=", i.e. either giving the result of the formula or 
> errorring if it's invalid?
Entering -1+2 does becomes 1 (=-1+2) and -1+z the string ('-1+z). What do you think should change?
Comment 17 Stéphane Guillou (stragu) 2023-05-23 13:13:41 UTC
(In reply to Heiko Tietze from comment #16)
> > 4. select cell, and _in the formula bar_ add a space at the end of the string
> >  -> partial direct formatting is lost; prefix is again hidden when out of
> > edit mode
> not confirming

Oof, it's GTK-only. Thanks for testing. Not reproduced on kf5 or gen.

> (In reply to Stéphane Guillou (stragu) from comment #12)
> Entering -1+2 does becomes 1 (=-1+2) and -1+z the string ('-1+z). What do
> you think should change?

Acknowledged in comment 15, please ignore that question :)
Comment 18 Eike Rathke 2023-05-23 13:41:43 UTC
(In reply to Stéphane Guillou (stragu) from comment #15)
> I have noticed that using the formula bar vs editing directly in the cell
> does matter for reproducing the bug, and that this is not just about
> formulas in 7.6 anymore.
Indeed, editing in the Input Line (what you call formula bar) discards all in-cell formatting, apparently the Input Line does not know about character attributes.

(In reply to Stéphane Guillou (stragu) from comment #17)
> Oof, it's GTK-only. Thanks for testing. Not reproduced on kf5 or gen.
Geez, that's even more twisted..


> 2. enter the following string in a cell, but don't press Enter: + one A1 two
> 3. make "one" red, press Enter
>  -> quote prefix is not added even though the formula is not valid;
Correct observation but wrong conclusion. It's not about the formula being valid or not, it's not a formula at all because entering attributed text forces a rich text edit cell instead of a formula cell.

> 4. select cell, and _in the formula bar_ add a space at the end of the string
>  -> partial direct formatting is lost; prefix is again hidden when out of
> edit mode
> 
> So it seems that editing the value in the formula bar automatically
> interprets it as a formula, and therefore removes the formatting, even if
> the end result is still an invalid formula.
Yes. Just that it removes the formatting regardless whether it would be a formula or not or a valid formula or not.


> Somewhat related:
> 
> Steps:
> 1. Open Calc
> 2. enter the following string in a cell and press Enter: + one A1 two
>  -> note the ' prefix is automatically added, because not a valid formula
No, because the cell content is text that with a non-Text number format because of the leading + could be interpreted as formula when editing. The cell content became text because the input didn't form a valid formula.

> 3. make "one" red, press Enter
>  -> quote prefix does not automatically hide anymore when out of edit mode
Because with the attributed characters a rich text cell is created of all input. We should maybe implement the same behaviour there as for any other text input: discard a leading ' apostrophe if the cell wasn't already formatted as text. On the other hand, such attributed content is never converted to numeric or other data types.

> 4. add a space at the end of the string
>  -> partial direct formatting is lost; prefix is again hidden when out of
> edit mode
Because editing in the Input Line removes attribution,,


> (In reply to Eike Rathke from comment #14)
> > I don't understand the question. How do +/- and = differ?
> 
> I was thinking of the difference in output between these two formulas:
> =2+test
> +2+test
> 
> ...but I realise now that a single quote should always be prepended when the
> formula is not valid, whereas an equal sign is prepended when it is. So
> scrap that comment :)
See above, it's actually text cell content vs formula content.
Comment 19 Eike Rathke 2023-05-23 14:13:00 UTC
So all this speculation about formula or not is completely moot, it's simply in-cell rich text attribution that when editing in the Input Line with gtk3 is not preserved for the EditEngine text of the cell content.

e.g. enter  one two  in a cell and format the word two as red and close with Enter, then edit the cell in the Input Line and as soon as a character is typed the cell content attribution is lost.

Let's add Caolán for this..
Caolán, an idea why that happens only for gtk3 but not kf5 or gen backend?
Comment 20 Stéphane Guillou (stragu) 2023-05-23 14:27:15 UTC
(In reply to Eike Rathke from comment #19)
> So all this speculation about formula or not is completely moot, it's simply
> in-cell rich text attribution that when editing in the Input Line with gtk3
> is not preserved for the EditEngine text of the cell content.
> 
> e.g. enter  one two  in a cell and format the word two as red and close with
> Enter, then edit the cell in the Input Line and as soon as a character is
> typed the cell content attribution is lost.
> 
> Let's add Caolán for this..
> Caolán, an idea why that happens only for gtk3 but not kf5 or gen backend?

OK, I've identified the formula bar regression and opened 155453 to track independently, and made it block this one. It is indeed from one of Caolán's commits in 7.2.

Let's keep this report open for the issues seen before 7.2.