Improve client-side edit stash change detection
authorOri Livneh <ori@wikimedia.org>
Tue, 14 Jun 2016 19:58:20 +0000 (12:58 -0700)
committerOri.livneh <ori@wikimedia.org>
Tue, 14 Jun 2016 21:43:13 +0000 (21:43 +0000)
commiteca800c7f02023030a8e97bfc611d222f0edcdb3
tree41e518e6c00fc24d53fad7579e1d7b507bccb271
parenta0bc1a2def5d1d23a0f91ee4aa8f12a40535b6a6
Improve client-side edit stash change detection

The keypress event does not fire for backspace or delete in IE, Chrome, or
Safari, which means we are missing out on stash opportunities when the last
action is to delete some text. Fix that by listening for the keyup event
instead.

Also add an isChanged() check before calling pending.abort(), because there are
a lot of special keys that don't modify the text, and not all of them are coded
consistently on different platforms (think volume up/down, mute, function keys,
etc.), so we can't be exhaustive, and should instead fall back to actually
checking for changes. Otherwise we risk aborting stash requests when the user
has not changed the text.

Lastly, rename 'onTextChanged' to 'onEditorIdle', which is more accurate.
On undo / rollback, onTextChanged will return true the first time it is called,
even though the text had not changed in that case.

Useful sources:

* Key codes of keydown and keyup events:
  http://www.javascripter.net/faq/keycodes.htm
* Quirksmode: detecting keystrokes
  http://www.quirksmode.org/js/keys.html
* Why isn't backspace being detected using jquery keypress event?
  http://stackoverflow.com/q/4418562

Change-Id: Idfad8407c8e905d8de80bc54379545f1b586fc88
resources/src/mediawiki.action/mediawiki.action.edit.stash.js