Page MenuHomePhabricator

VisualEditor: Command-x (cut) triggers browser's Undo (Command-z) in Safari
Closed, ResolvedPublic

Description

Intention:
Move a section of a page by cutting it out of one place and pasting it into the right place.

Steps to Reproduce:

  1. Close an unwanted browser tab.
  2. Select several paragraphs in VisualEditor.
  3. Press Command-x to cut (not just copy) the material.
  4. Notice that the just-closed browser window has reappeared. (Command-z/Undo in Safari reopens a tab that you just closed.)

Reproducible: Always

I am unable to reproduce this in Firefox, presumably because selecting text within VisualEditor seems to clear (or otherwise make unavailable) the 'undo' buffer. So even if VisualEditor is telling Firefox to undo something, Firefox believes that there there's nothing to undo.


Version: unspecified
Severity: normal
See Also:
https://bugzilla.wikimedia.org/show_bug.cgi?id=57217

Details

Reference
bz58724

Event Timeline

Ick. This feels like a pretty poor browser bug here…

aditya wrote:

Patch to prevent undo on cut

Here's a patch that avoids the 'undo' execCommand and fixes the issue for me in Chromium 36.0.1985.125 (Linux).

I'm assuming that the timeout was originally intended to let the code in that block be safely executed only after the browser manipulated (deleted) the selection. It appears that this no longer works and the code is processed before the text is actually deleted.

Therefore this change uses preventDefault() to not let the browser do it's thing, and directly handles the entire removal with a transaction.

This is my first patch to VE, sorry if I made any obvious mistakes. :)

Attached:

Change 156593 had a related patch set uploaded by Catrope:
Avoid undo when processing a cut event.

https://gerrit.wikimedia.org/r/156593

Change 156733 had a related patch set uploaded by Catrope:
Avoid undo when processing a cut event.

https://gerrit.wikimedia.org/r/156733

Change 156593 abandoned by Catrope:
Avoid undo when processing a cut event.

Reason:
Duplicate of https://gerrit.wikimedia.org/r/156593

https://gerrit.wikimedia.org/r/156593

Change 156593 restored by Catrope:
Avoid undo when processing a cut event.

Reason:
Whoops, obviously this isn't a duplicate of itself...

https://gerrit.wikimedia.org/r/156593

Change 156733 abandoned by Catrope:
Avoid undo when processing a cut event.

Reason:
Duplicate of https://gerrit.wikimedia.org/r/156593

https://gerrit.wikimedia.org/r/156733

Change 156776 had a related patch set uploaded by Esanders:
Remove unnecessary execCommand('undo') from onCut

https://gerrit.wikimedia.org/r/156776

Change 156776 merged by jenkins-bot:
Remove unnecessary execCommand('undo') from onCut

https://gerrit.wikimedia.org/r/156776