Bug 34260 - Calc eats ' when the content is text.
Summary: Calc eats ' when the content is text.
Status: RESOLVED FIXED
Alias: None
Product: LibreOffice
Classification: Unclassified
Component: Calc (show other bugs)
Version:
(earliest affected)
unspecified
Hardware: Other All
: high normal
Assignee: Katarina Behrens
URL:
Whiteboard: target:3.4
Keywords:
Depends on:
Blocks:
 
Reported: 2011-02-14 08:12 UTC by Kohei Yoshida
Modified: 2011-03-04 10:34 UTC (History)
1 user (show)

See Also:
Crash report or crash signature:


Attachments
Proposed patch (2.68 KB, patch)
2011-03-04 08:21 UTC, Katarina Behrens
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Kohei Yoshida 2011-02-14 08:12:03 UTC
Simple example.  Type in a cell

'apple

and see Calc eat the first apostrophe (') in the formula input bar.  However, typing in

'1

retains the apostrophe in the formula input bar while not displaying it in the cell, which is a correct behavior.

Here, this apostrophe prefix is used to force cell content to be parsed as text, e.g. to force a number to be interpreted as text.  But we need to retain it in case the content is real text.
Comment 1 Kohei Yoshida 2011-02-14 08:15:04 UTC
A good place to start would be

ScViewFunc::EnterData()

That method is overloaded with several variants.  Pick the one that takes String as one of the arguments, and work your way down.  Somewhere, somehow we may be eating the apostrophe...
Comment 2 Kohei Yoshida 2011-02-16 07:54:49 UTC
BTW Katarina, we've made a deal with Caolan that, in exchange for him fixing our favorite Writer bugs, we fix his favorite Calc bugs in earnest.  And this is one of those bugs... :-)

So, bumping up the priority for this would be well appreciated. ;-)
Comment 3 Katarina Behrens 2011-02-16 08:38:38 UTC
> BTW Katarina, we've made a deal with Caolan that, in exchange for him fixing
> our favorite Writer bugs, we fix his favorite Calc bugs in earnest.  And this
> is one of those bugs... :-)
> 
> So, bumping up the priority for this would be well appreciated. ;-)

Fair enough, bumping prio then
Comment 4 Katarina Behrens 2011-03-04 08:19:03 UTC
So far, string cells beginning with ' were treated as follows: ScColumn::SetString (column3.cxx) stored n-1 chars (everything but ' char) into ScStringCell object. Later,  ScTabViewShell::UpdateInputHandler (tabvwsha.cxx) when re-constructing the string to show in the edit field, appended ' char again, but only(!) if the string was actually a number. The info that this cell needs a special treatment when it comes to trailing apostrophe was not stored anywhere and that's why it didn't work for strings such as "'foo".

So what I've done is that I introduced a bool flag to ScStringCell to somehow remember that this cell is "special" (ie. its content is indeed a string and this is enforced by ' char at zero position). Otherwise, I kept the logic (striping and prepending ' char, as needed).

Attaching patch in a while
Comment 5 Katarina Behrens 2011-03-04 08:21:52 UTC
Created attachment 44130 [details]
Proposed patch

This should fix the bug. Tested it a bit and it works for common cases. Please review, comment, complain etc.
Comment 6 Kohei Yoshida 2011-03-04 09:02:08 UTC
So, the history behind it is that, when you type '10 into a cell, the cell should interpret it as text, even though it's a number.

These days, we do the same by setting the cell format to Text, but we still do this for backward compatibility (I guess), and/or because Excel still does it.

Regarding the patch, I'm not too keen on adding a special flag with the cell instance itself.  Let me look around and see if we can do it another way...
Comment 7 Kohei Yoshida 2011-03-04 10:34:44 UTC
I fixed this.  There was a simpler way to handle this.

http://cgit.freedesktop.org/libreoffice/calc/commit/?id=dfbc969ff099ffae187998cfc5ad88fbb52120f0

BTW the unit test also detected an abuse of this behavior in the datapilot output creation code, which I removed with great pleasure. :-)