Last Comment Bug 471319 - undoing the last action of a textbox immediately after emptytext was displayed inserts a line feed (breaks search textbox)
: undoing the last action of a textbox immediately after emptytext was displaye...
Status: RESOLVED FIXED
:
Product: Core
Classification: Components
Component: Editor (show other bugs)
: Trunk
: All All
: -- normal (vote)
: mozilla12
Assigned To: Graeme McCutcheon [:graememcc]
:
Mentors:
Depends on: 503838 471776 547224
Blocks: 328056 388811 406095
  Show dependency treegraph
 
Reported: 2008-12-28 02:36 PST by Henrik Skupin (:whimboo)
Modified: 2012-01-06 04:41 PST (History)
13 users (show)
roc: wanted1.9.1+
graeme.mccutcheon: in‑testsuite+
See Also:
Crash Signature:
(edit)
QA Whiteboard:
Iteration: ---
Points: ---
Has Regression Range: ---
Has STR: ---


Attachments
Patch v1 (10.00 KB, patch)
2009-01-01 07:53 PST, Graeme McCutcheon [:graememcc]
no flags Details | Diff | Splinter Review
Patch v2 - slightly better tests (8.72 KB, patch)
2009-07-09 10:41 PDT, Graeme McCutcheon [:graememcc]
timeless: review+
Details | Diff | Splinter Review
Patch v3 - comments addressed (8.69 KB, patch)
2009-07-13 11:03 PDT, Graeme McCutcheon [:graememcc]
no flags Details | Diff | Splinter Review
Patch v4 - updated to trunk, change test to chrome test (7.93 KB, patch)
2011-12-15 02:13 PST, Graeme McCutcheon [:graememcc]
ehsan: review+
Details | Diff | Splinter Review

Description Henrik Skupin (:whimboo) 2008-12-28 02:36:06 PST
Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10.5; en-US; rv:1.9.2a1pre) Gecko/20081227 Minefield/3.2a1pre ID:20081227020350

Using a search widget with the emptyText attribute set, will be broken when you initially select the undo entry within the context menu. The clear button gets hidden and no results are returned even without a filter set (value="").

As Dao mentioned this bug could probably be fixed by a patch on bug 418874 but I feel safer in having it as it's own bug. A comment can get lost but we will remember that bug. So marking it as depended.

Here are the STR:
1. Open "Tools | Add-ons"
2. Open the context menu of the search text box under "Get Add-ons" and select Undo
3. Focus the text box and hit enter

=> No results are returned

1. Open the preferences and go to the applications pane
2. Open the context menu of the search text box and select Undo

=> The clearButton gets hidden and no MIME types are listed anymore. You have to reopen the pref panel to be able to search again.
Comment 1 Dão Gottwald [:dao] 2008-12-28 03:03:41 PST
(In reply to comment #0)
> As Dao mentioned this bug could probably be fixed by a patch on bug 418874

No, I was confused by the fact that you commented in that bug. This doesn't seem to be related.
Comment 2 Henrik Skupin (:whimboo) 2008-12-28 03:34:56 PST
Ok. Now that you have changed the summary I have to add one more hint. It only appears for the latest undo action. If you are changing the value several times and start searches, it will still work if you are undoing a value change. But when undoing the last change it will break. That's the same as when you hit undo on the initial state.
Comment 3 Henrik Skupin (:whimboo) 2008-12-28 03:38:26 PST
And if you compare the given examples above by using the about:config search field, you can see it does only happen on search widgets where emptyText is set. So it is related in some way.
Comment 4 Dão Gottwald [:dao] 2008-12-28 03:48:54 PST
(In reply to comment #3)
> And if you compare the given examples above by using the about:config search
> field, you can see it does only happen on search widgets where emptyText is
> set.

That's only partly true -- in about:config, you still get the clear icon instead of the search glass.
Do you want this bug to cover that issue?
Comment 5 Henrik Skupin (:whimboo) 2008-12-28 04:04:45 PST
Due to instant searching we don't have the search glass at all. But you are right. If you think its better to file a new bug on that part, I can create one. Otherwise we can cover both things here. It's up to you.
Comment 6 Dão Gottwald [:dao] 2008-12-28 04:33:22 PST
Yeah, a new bug is better, since the underlying issue is different.
Comment 7 Henrik Skupin (:whimboo) 2008-12-28 06:51:18 PST
Filed as bug 471330.
Comment 8 Graeme McCutcheon [:graememcc] 2009-01-01 07:53:42 PST
Created attachment 355029 [details] [diff] [review]
Patch v1

When the editor is empty it inserts a bogus <br> node as a placeholder.

Now, the textbox creates a batch to ensure the user can't undo the displaying of the empty text. So, what's happening is this:

1) Bogus <br> node inserted
2) TRANSACTION STARTS
3) Bogus <br> node deleted
4) textbox's emptytext inserted
{user clicks on textbox or it gets focus in some other way}
5) textbox's emptytext deleted
6) Bogus <br> node inserted
7) TRANSACTION ENDS

So, when doing or undoing this transaction, there is a bogus <br> node at each endpoint of the transaction.

The problem arises because the plaintext editor's undo/redo handling code doesn't handle this case. It assumes that if there was a bogus node before undoing a transaction, then there won't be one after undoing the transaction. As the above shows, when using the transaction manager's batching facilities this is not necessarily true.
Comment 9 Graeme McCutcheon [:graememcc] 2009-01-01 09:32:38 PST
Of course, with Henrik's STR, undo shouldn't even be enabled in the context menu at that point... filed as bug 471776
Comment 10 Henrik Skupin (:whimboo) 2009-02-02 08:48:16 PST
Peterv, if you would have time for a review that would be great.
Comment 11 Henrik Skupin (:whimboo) 2009-02-15 12:02:10 PST
Who else could review the patch? Seems like there is no way to reach Peter right now.
Comment 12 Graeme McCutcheon [:graememcc] 2009-03-18 08:52:22 PDT
In fact, you don't even need to mess with transactions to hit this bug. Bug 328056 is basically the same problem.
Comment 13 Henrik Skupin (:whimboo) 2009-03-18 09:07:26 PDT
Graeme, does it mean bug 328056 will be also solved by your patch?
Comment 14 Graeme McCutcheon [:graememcc] 2009-03-18 09:15:24 PDT
Should be, yes.
Comment 15 Graeme McCutcheon [:graememcc] 2009-07-09 10:41:14 PDT
Created attachment 387672 [details] [diff] [review]
Patch v2 - slightly better tests

So to clarify, the problem is that nsTextEditRules::Did[Un/Re]do assumes if there is a bogus node before, there isn't after, and vice versa. This assumption can be false for two reasons: 1) Transactions, and 2) the Can[Un/Re]do check in nsEditor may return false, and so the editor may do nothing.

Perhaps in addition to this, it may be worth nsPlaintextEditor etc performing a CanUndo check, and not pre/post notifying the rules if the action cannot succeed. This would have to be implemented consistently for all the actions where this is the case (cut etc).
Comment 16 timeless 2009-07-10 02:26:37 PDT
Comment on attachment 387672 [details] [diff] [review]
Patch v2 - slightly better tests

you don't have to address any of these comments. and they're only about the test. i'm commenting since i feel obligated to comment about the entire patch, not just the code fix (thanks for working on editor by the way, it needs the love).

so, most of our code uses "recognize" (hits: 20:1, files: 14:1)

>+        if (t1 instanceof Components.interfaces.nsIDOMNSEditableElement)
>+          t1Editor = t1.editor;
>+
>+        // Did the editor recognise the new bogus node?
>+        t1Editor.undo(1);

this style of doing instanceof and then only conditionally setting the next variable that you need seems odd.

I'd rather (but this is up to you):
t1.QueryInterface(Components.interfaces.nsIDOMNSEditableElement);
t1Editor = t1.editor;
...

Otherwise you get an exception later (t1Editor.undo(1)) and have to backtrack and realize that implicit QI failed

>+        // Test 2: Redo on an empty editor should not result in the bogus node
>+        // not being recognised as such

... should not result in editor forgetting that its bogus node is bogus

(double negatives are painful for human parsers)
Comment 17 timeless 2009-07-10 02:33:56 PDT
neil suggests:

... should not forget about the bogus node
Comment 18 Peter Van der Beken [:peterv] 2009-07-13 02:21:22 PDT
I think we really should fix the problems the right way and remove these "bogus" nodes instead of adding hacks upon hacks to deal with them (I personally think we should not take any more of these patches). Same for bug 318065 and bug 483651.
Comment 19 Graeme McCutcheon [:graememcc] 2009-07-13 11:02:19 PDT
I certainly have no problem with the desire to get the real fix of killing the bogus node etc. As I'm sure they'll attest, after a thread in dev.planning where bz and roc talked about this and noted it would be unlikely anyone in MoCo could be assigned to it any time soon, I emailed them about one day wanting to attempt such a fix myself (although I made it somewhat non-commital - the amount of free time I have to volunteer being the limiting factor as to whether I would ever be able to spend enough time to do this). I'm not thoughtlessly layering on additional hacks without having thought about the wider problem.

318065 and 483651 could reasonably classified as hacks upon hacks, but I'd say this is really a logic-correctness fix. That of course could just be a too proud patch author quibbling over semantics. And given no definite timescale for a real fix, I wonder how much taking this hurts us versus having to hope that until we do fix it our users never thoughtlessly press Ctrl-Z in an empty HTML input. Yes, ultimately it's a workaround, but for a pretty general case, and I don't see that taking it significantly increases the maintenance overhead on what is already ill-maintained code.

Anyway, I'll attach the patch I would have pushed with the comments are addressed: I'll leave it for others to decide whether it makes it in the tree or not.
Comment 20 Graeme McCutcheon [:graememcc] 2009-07-13 11:03:06 PDT
Created attachment 388241 [details] [diff] [review]
Patch v3 - comments addressed
Comment 21 Peter Van der Beken [:peterv] 2009-07-13 13:14:50 PDT
(In reply to comment #19)
> I'm not
> thoughtlessly layering on additional hacks without having thought about the
> wider problem.

I never implied that.

> I don't see that taking it significantly increases the maintenance overhead
> on what is already ill-maintained code.

You're assuming there won't be any regressions from this fix, I hope you're right. Note that I'm not questioning the quality of your patches, but we're starting to have a history of regressions with this code and I'm just trying to raise that I think that points to the fragility of the architecture and we need to fix it.
Comment 22 Graeme McCutcheon [:graememcc] 2011-12-15 02:13:34 PST
Created attachment 581921 [details] [diff] [review]
Patch v4 - updated to trunk, change test to chrome test

Re-requesting review, primarily to check Ehsan is OK with taking this.

Since the original patch went up, use of enablePrivilege has been discouraged for new tests, so have switched the test to a chrome test.
Comment 23 :Ehsan Akhgari 2011-12-21 14:40:49 PST
Comment on attachment 581921 [details] [diff] [review]
Patch v4 - updated to trunk, change test to chrome test

Peter's comments on us needing to fix the bogus node mess withstanding, I think not taking this fix will do more harm than good.  So, r=me.
Comment 24 :Ehsan Akhgari 2012-01-03 14:42:35 PST
Graeme, do you need help in sending this patch to try and landing it?  If yes, please let me know and I'll help you.  :-)
Comment 25 Graeme McCutcheon [:graememcc] 2012-01-05 13:44:36 PST
(In reply to Ehsan Akhgari [:ehsan] from comment #24)
> Graeme, do you need help in sending this patch to try and landing it?  If
> yes, please let me know and I'll help you.  :-)

Somehow never spotted the r+ bugmail!

https://hg.mozilla.org/integration/mozilla-inbound/rev/0ac1cbff2a67
Comment 26 Marco Bonardo [::mak] 2012-01-06 04:41:30 PST
https://hg.mozilla.org/mozilla-central/rev/0ac1cbff2a67

Note You need to log in before you can comment on or make changes to this bug.