Closed Bug 462188 Opened 16 years ago Closed 16 years ago

Option-Delete / Ctrl-Backspace does not delete words in designmode textareas or Thunderbird message body editor

Categories

(Core :: DOM: Editor, defect, P1)

defect

Tracking

()

RESOLVED FIXED
mozilla1.9.2a1

People

(Reporter: dre, Assigned: thep)

References

()

Details

(Keywords: fixed1.9.1, regression, testcase, Whiteboard: [tb3needs])

Attachments

(3 files, 4 obsolete files)

User Agent: Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10.5; en-US; rv:1.9.1b2pre) Gecko/20081029 Minefield/3.1b2pre

Steps to Reproduce:
1. Visit sandbox forum of vBulletin site in URL field above (note it seems that all websites using vBulletin appear to be affected by this regression.  I've tested four that I know of.)
2. Log in with the credentials
     Username: "Test for Firefox"
     Password: "password"
3. Click the "New Thread" button
4. Type multiple words in the rich textarea
5. Attempt to use Command-Delete to delete a word

Actual Results:
At most, one space is deleted, words are never deleted.

Expected Results:
Any whitespace and the entire previous word up to the next instance of whitespace should be deleted.
Firefox 2.x, 3.0.x, and 3.1b1 exhibit this correct behavior 

I tried to reproduce this with the latest Windows nightly of Minefield, but it crashes upon clicking the "Log In" button after entering credentials in StR above.
Daniel, does disabling content jit prevent the crash?

We probably want to file a separate bug on the crash, and use this bug for the Command-Delete problem...  I'd much appreciate someone hunting down a one-day regression range here...
Disabling content jit makes the crash go away, I just filed bug 462219 for that crash.
So disabling jit on the latest nightly eliminated the crash for me as well.  Now that I can log in with the latest nightly on Windows, I can verify that the inability to delete words happens on Windows as well, using ctrl-backspace.
Setting platform/os to All/All since I can't select just Mac+Windows.
OS: Mac OS X → All
Hardware: Macintosh → All
It regressed between 2008-10-15 and 2008-10-16:
http://hg.mozilla.org/mozilla-central/pushloghtml?startdate=2008-10-14+04%3A00%3A00&enddate=2008-10-16+09%3A00%3A00
My guess is a regression from bug 157546.
Blocks: 157546
Flags: blocking1.9.1?
Keywords: regression, testcase
Blocks: 461716
Component: Layout: Form Controls → Editor
QA Contact: layout.form-controls → editor
Flags: blocking1.9.1? → blocking1.9.1+
Priority: -- → P2
No longer blocks: 461716
Trying to make the subject a little more specific and less un-related.
Summary: Using Command-Delete to delete words in Firefox on vBulletin rich textareas no longer works at some point after 3.1b1 → Command-Delete / Ctrl-Backspace does not delete words in designmode textareas or Thunderbird message body editor
This patch fixes my committed patch in Bug 157546. The order of selection extending has been restored back to previous state for the cases unrelated to the bug.
Thanks! Could you add this bug to the mochitests and request review from peterv?
Mochitest added according to roc's comment. Please review my patch. Thanks.
Attachment #348408 - Attachment is obsolete: true
Attachment #348542 - Flags: review?(peterv)
The test isn't going to work on Mac because Mac uses option-backspace to delete a word, not ctrl-backspace. So on Mac you should use altKey. Copy wordModifiers from test_word_movement.html and use that, that should do it.
Erm.. fixing title to reflect the correct metakey for Mac.  Should be Option-Delete (the "Alt" key), not Command (the "Mac" key)
Summary: Command-Delete / Ctrl-Backspace does not delete words in designmode textareas or Thunderbird message body editor → Option-Delete / Ctrl-Backspace does not delete words in designmode textareas or Thunderbird message body editor
OK. Updated the mochitest for Mac. Requesting for the review again.
Attachment #348542 - Attachment is obsolete: true
Attachment #348720 - Flags: review?(peterv)
Attachment #348542 - Flags: review?(peterv)
Whiteboard: [needs review (peterv)]
Some rationales for the patch, in case it helps the review process:

- ExtendSelectionForDelete() must be called after CheckBidiLevelForDeletion(), to prevent Bug 419406.

- Calling it before 'if (aAction == nsIEditor::eNone) return NS_OK;' will leave the cases that were not handled by WillDoAction() before applying the patch in Bug 157546 unhandled. And nsPlaintextEditor::DeleteSelection() will pass it on to DeleteSelectionImpl() as usual.

- ExtendSelectionForDelete() may have changed the selection. So, startNode and startOffset need to be updated

- Some selection extensions, such as for ePreviousWord direction, modify the selection start, rather than the end. So, both selection ends must be retrieved, not just the ending as done in Bug 157546.
I'm also experiencing this bug. It doesn't happen in the latest Firefox nightlies for me (Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10.5; en-US; rv:1.9.1b3pre) Gecko/20081206 Shiretoko/3.1b3pre), but it happens in the latest Thunderbird (Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10.5; en-US; rv:1.9.1b3pre) Gecko/20081205 Shredder/3.0b2pre). Option-Fn-Delete (deleting forward instead of backwards on my laptop) does work however.
Comment on attachment 348720 [details] [diff] [review]
Updated patch, fixing mochitest for Mac

There are several cases where after calling ExtendSelectionForDelete we still cancel the action (look for |*aCancel = PR_TRUE|). I think this can only happen for aAction==ePrevious and aAction==eToEndOfLine, but we would be changing the selection without deleting. Isn't that wrong?
(In reply to comment #20)
> (From update of attachment 348720 [details] [diff] [review])
> There are several cases where after calling ExtendSelectionForDelete we still
> cancel the action (look for |*aCancel = PR_TRUE|). I think this can only happen
> for aAction==ePrevious and aAction==eToEndOfLine, but we would be changing the
> selection without deleting. Isn't that wrong?

OK. But the difference between the two cases is that, for aAction==ePrevious, no selection was changed (or if actually changed as noted in the FIXME comment, aAction would be set to eNone), while it was actually changed for aAction==eToEndOfLine.

In the code before Bug 157546, the selection change would cause bCollapse to be false on start, and the whole "if (bCollapse) ..." block would not be executed at all. To retain that old execution path, bCollapse may also need to be refreshed and re-checked after the ExtendSelectionForDelete() call.

I'll prepare such patch soon. But could you suggest how to test the aAction==eToEndOfLine case? What shortcut is for such command?
Here is the patch as mentioned in comment #21.
Attachment #348720 - Attachment is obsolete: true
Attachment #353781 - Flags: review?(peterv)
Attachment #348720 - Flags: review?(peterv)
Please, consider adding a keyboard shortcut to delete the current line while in Mail Compose window!
(In reply to comment #21)
> In the code before Bug 157546, the selection change would cause bCollapse to be
> false on start, and the whole "if (bCollapse) ..." block would not be executed
> at all. To retain that old execution path, bCollapse may also need to be
> refreshed and re-checked after the ExtendSelectionForDelete() call.

I'm actually wondering if you should use an nsAutoSelectionReset to undo the changes to the selection when canceling.

> I'll prepare such patch soon. But could you suggest how to test the
> aAction==eToEndOfLine case? What shortcut is for such command?

platformHTMLBindings.xml says ctrl-k on OS X and Linux.
(In reply to comment #25)
> (In reply to comment #21)
> > In the code before Bug 157546, the selection change would cause bCollapse to be
> > false on start, and the whole "if (bCollapse) ..." block would not be executed
> > at all. To retain that old execution path, bCollapse may also need to be
> > refreshed and re-checked after the ExtendSelectionForDelete() call.
> 
> I'm actually wondering if you should use an nsAutoSelectionReset to undo the
> changes to the selection when canceling.

I'm afraid that would be too big change, which alters the logic of existing code. It may be too risky.

> > I'll prepare such patch soon. But could you suggest how to test the
> > aAction==eToEndOfLine case? What shortcut is for such command?
> 
> platformHTMLBindings.xml says ctrl-k on OS X and Linux.

Unfortunately, I haven't been successful overriding Minefield's ctrl-k shortcut for the search bar. And I don't have enough space to checkout and build Thunderbird for now.. Is there an easy way to disable the search bar shortcut?
(In reply to comment #27)
> I'm afraid that would be too big change, which alters the logic of existing
> code. It may be too risky.

I don't see where we were changing the selection *and* canceling in the existing code?
(In reply to comment #28)
> I don't see where we were changing the selection *and* canceling in the
> existing code?

No, there was no such attempt. So, I try to keep up with that logic, to bring back the previously working mechanism before applying patch in Bug 157546, i.e. attachment #342183 [details] [diff] [review], as explained in comment #21.

Before that patch was applied, selection was extended for aAction==eToEndOfLine in nsPlaintextEditor::DeleteSelection(), and aAction set to eNext, before entering WillDoAction(). So, nsHTMLEditRules::WillDeleteSelection() received such condition on entry in the previous code, which caused the whole "if (bCollapsed) ..." block to be skipped. Thus, re-checking bCollapse after ExtendSelectionForDelete() in the new code simply brought back the same execution steps.
Comment on attachment 353781 [details] [diff] [review]
updated patch, with bCollapsed re-checked

Ok, I see what you mean now.

On OS X ctrl-k works. You could try to use an iframe in designMode for the test. Or you could try to use a textarea and get its editor through .editor (probably need some privileges). Then you should be able to call deleteSelection(nsIEditor::eToEndOfLine) on the editor.
Attachment #353781 - Flags: superreview+
Attachment #353781 - Flags: review?(peterv)
Attachment #353781 - Flags: review+
I think we can land this without waiting for the extra to-end-of-line test.
Whiteboard: [needs review (peterv)] → [needs landing]
Whiteboard: [needs landing] → [needs landing][tb3needs]
I landed this on mozilla-central:
http://hg.mozilla.org/mozilla-central/rev/9b832d90d637

Not sure whether to mark fixed yet given the request for more tests...
And I had to back it out:
http://hg.mozilla.org/mozilla-central/rev/f5436f305f3a
http://hg.mozilla.org/mozilla-central/rev/58b777f8849a
due to test failures.

The tests passed on Mac.

On Windows, there was one failure:

*** 42583 ERROR TEST-UNEXPECTED-FAIL | /tests/layout/generic/test/test_backspace_delete.html | Delete next word broken in "text." - got [object Text], expected [object HTMLDivElement]

On Linux, there were 7 failures:

*** 42526 ERROR TEST-UNEXPECTED-FAIL | /tests/layout/generic/test/test_backspace_delete.html | Delete previous word broken in "You should not see this text." - got 29, expected 24
*** 42528 ERROR TEST-UNEXPECTED-FAIL | /tests/layout/generic/test/test_backspace_delete.html | Delete previous word broken in "You should not see this text." - got 29, expected 19
*** 42530 ERROR TEST-UNEXPECTED-FAIL | /tests/layout/generic/test/test_backspace_delete.html | Delete previous word broken in "You should not see this text." - got 29, expected 15
*** 42532 ERROR TEST-UNEXPECTED-FAIL | /tests/layout/generic/test/test_backspace_delete.html | Delete previous word broken in "You should not see this text." - got 29, expected 11
*** 42534 ERROR TEST-UNEXPECTED-FAIL | /tests/layout/generic/test/test_backspace_delete.html | Delete previous word broken in "You should not see this text." - got 29, expected 4
*** 42535 ERROR TEST-UNEXPECTED-FAIL | /tests/layout/generic/test/test_backspace_delete.html | Delete previous word broken in "You should not see this text." - got [object Text], expected [object HTMLDivElement]
*** 42536 ERROR TEST-UNEXPECTED-FAIL | /tests/layout/generic/test/test_backspace_delete.html | Delete previous word broken in "You should not see this text." - got 29, expected 0
The tests pass so far on my system (Debian unstable, amd64), with direct build from trunk fresh checkout today. (My previous builds were lost with the crashed harddisk. So, I'm forced to start from scratch.)
Those tests pass on my Linux VM with the patch. :-(
In Linux we respect the native keybindings. Maybe the keybindings are defined strangely on the Tinderbox VM so that ctrl-backspace doesn't work?
Attached patch fixSplinter Review
With this patch, I'm changing the test to use editor commands directly without going through key events. That should prevent any problems with key bindings. I also found a problem with testDeleteNextWord which I'm fixing in the patch, hence the need for more review.

-- In test_selection_move_commands.xul, runTest isn't really needed, it's left over from some copy-paste job

-- In nsHTMLEditRules.cpp, we shouldn't do "if (aAction == nsIEditor::eNone) return NS_OK;" after ExtendSelectionForDelete as we did in the last iteration of the patch. ExtendSelectionForDelete will set aAction to eNone if it successfully extended the selection and no more work needs to be done by the caller to extend the selection. We still need to *delete* the selection, though. In this case I think we can just ignore any changes to aAction by ExtendSelectionForDelete, since we're going to check bCollapsed again. This fixes the deleteNextWord tests, which I think wasn't being tested properly at all with the current tests, because we weren't checking editor.textContent in testDeleteNextWord.

-- Move test_backspace_delete to a XUL file so we can access the commandDispatcher. The tests themselves run in an IFRAME. I originally designed this setup for test_selection_move_commands.xul. The tests are basically the same except I added tests of editor.textContent in testDeletePrevWord and testDeleteNextWord. The tests for testDeleteNextWord need to specify that the editor makes the first space a  .
Attachment #353781 - Attachment is obsolete: true
Attachment #357604 - Flags: superreview?
Attachment #357604 - Flags: review?
Attachment #357604 - Flags: superreview?(peterv)
Attachment #357604 - Flags: superreview?
Attachment #357604 - Flags: review?(peterv)
Attachment #357604 - Flags: review?
(In reply to comment #38)
> -- In nsHTMLEditRules.cpp, we shouldn't do "if (aAction == nsIEditor::eNone)
> return NS_OK;" after ExtendSelectionForDelete as we did in the last iteration
> of the patch. ExtendSelectionForDelete will set aAction to eNone if it
> successfully extended the selection and no more work needs to be done by the
> caller to extend the selection. We still need to *delete* the selection,
> though. In this case I think we can just ignore any changes to aAction by
> ExtendSelectionForDelete, since we're going to check bCollapsed again. This
> fixes the deleteNextWord tests, which I think wasn't being tested properly at
> all with the current tests, because we weren't checking editor.textContent in
> testDeleteNextWord.

Just for clarification of my patch, the selection is actually deleted later by DeleteSelectionImpl() call in nsPlaintextEditor::DeleteSelection(), after nsHTMLEditRules::WillDoAction() returns. And in fact, the test still passes even when adding editor.textContent check to testDeleteNextWord on my machine.

BTW, I'll try your patch soon. It looks cleaner not to rely on cross-function workflow. I was just too reluctant to try different execution paths.
Keywords: checkin-needed
Whiteboard: [needs landing][tb3needs] → [needs review][tb3needs]
(In reply to comment #39)
> Just for clarification of my patch, the selection is actually deleted later by
> DeleteSelectionImpl() call in nsPlaintextEditor::DeleteSelection(), after
> nsHTMLEditRules::WillDoAction() returns.

Yes, that's how I understood the patch. What exactly was broken by doing this?
I'm not sure, I didn't know it should still work via DeleteSelectionImpl. But the tests were failing. I guess I'll fire up the VM again...
Comment on attachment 357604 [details] [diff] [review]
fix

I'll + this, it'd be nice to know the answer to comment 41, but if it works let's just take it.
Attachment #357604 - Flags: superreview?(peterv)
Attachment #357604 - Flags: superreview+
Attachment #357604 - Flags: review?(peterv)
Attachment #357604 - Flags: review+
This landed, http://hg.mozilla.org/mozilla-central/rev/10dfe13222aa, and I suspect it made mochitest hang, so I'm backing this out. I don't get precise error information, the last thing in the logs are tests that come shortly before the libeditor ones.

Backout is http://hg.mozilla.org/mozilla-central/rev/df6affd823b8.
FWIW, we're green again after that backout now. There were other test failures landing on top, and things went green slower than I thought, so I can't totally rule out that the mochitest timeout was an artifact of system load or anything. Someone with better understanding of those mechanics would need to look.
It certainly does look like this caused the timeouts, although it makes no sense to be mostly hanging in postMessage tests --- I'm pretty sure that we don't do any buffering that would cause us to misreport the hang position.
Needless to say, when I apply the patch, mochitests don't hang on my machine :-(.
This is Theppitak's code, with my XUL test conversion. The tests failed on my Mac, which sent me off bug-hunting which led to my additional code changes, but the real cause of the failures was that when my test deletes the last word via  testDeletePrevWord(editor,  0, ""), the editor inserts a bogus empty node, and the setting of .innerHTML in the next test isn't noticed by the editor so it thinks the content is still empty and bad things happen from there. So I worked around that bug again by toggling designMode after setting .innerHTML. Now the tests all pass.

I did notice, though, that the testDeleteNextWord tests are actually producing the wrong content output. They should have a leading  , not a leading normal space, so that a space is visible at the start of the line when you delete the first word (on Mac you need this at least, to match other Mac apps). My patch above actually fixed this bug. But for now, the minimal code change is probably best.

Since the last checkin of Theppitak's patch did not seem to cause mochitest hangs, I think we should try relanding this version and see what happens.
I haven't checked this, I see a hang in editor/libeditor/base/tests/test_selection_move_commands.xul but haven't been able to debug it yet.
The problem with the hanging test was the removal of the runTest function without removing the yields in the rest of the code. Removing both runTest and the yields made some tests fail, so I've just removed the changes to test_selection_move_commands.xul. They were orthogonal to this bug anyway.

Landed on trunk, and mochitests pass.

http://hg.mozilla.org/mozilla-central/rev/11e029835944
Status: NEW → RESOLVED
Closed: 16 years ago
Resolution: --- → FIXED
http://hg.mozilla.org/releases/mozilla-1.9.1/rev/0226bdfe6b36

(In reply to comment #48)
> I did notice, though, that the testDeleteNextWord tests are actually producing
> the wrong content output. They should have a leading  , not a leading
> normal space, so that a space is visible at the start of the line when you
> delete the first word (on Mac you need this at least, to match other Mac apps).

We should file a bug on this, right?
Flags: in-testsuite+
Keywords: fixed1.9.1
Whiteboard: [needs review][tb3needs] → [tb3needs]
Target Milestone: --- → mozilla1.9.2a1
(In reply to comment #50)
> The problem with the hanging test was the removal of the runTest function
> without removing the yields in the rest of the code. Removing both runTest and
> the yields made some tests fail, so I've just removed the changes to
> test_selection_move_commands.xul. They were orthogonal to this bug anyway.

Sorry! Too bad that didn't fail on my machine :-(

> Landed on trunk, and mochitests pass.
> 
> http://hg.mozilla.org/mozilla-central/rev/11e029835944

Yay!!! Thanks!

(In reply to comment #51)
> (In reply to comment #48)
> > I did notice, though, that the testDeleteNextWord tests are actually producing
> > the wrong content output. They should have a leading  , not a leading
> > normal space, so that a space is visible at the start of the line when you
> > delete the first word (on Mac you need this at least, to match other Mac apps).
> 
> We should file a bug on this, right?

Yes.
Can somebody please confirm it is the same bug as described in this minimal testcase:

http://komiks.xf.cz/bug/cannot_delete.html

It is still present in Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.2a1pre) Gecko/20090425 Minefield/3.6a1pre

Or should i file a new bug?
Nice testcase, thanks Dusan.

It seems that must be a different bug, as this bug should be fixed in that version (and the discription sounds a little different).

Can you file a new bug, please?
>> Can you file a new bug, please?

Done: #490554
See Also: → 1293498
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: