[go: nahoru, domu]

Skip to content

Commit

Permalink
Squashed 'libs/editor/' changes from 2c183ac..68d15ed
Browse files Browse the repository at this point in the history
68d15ed Merge pull request #390 from wordpress-mobile/issue/389-first-line-autocorrect
2bd069c Fix #389, autocorrect breaking paragraphs at start of posts under some circumstances

git-subtree-dir: libs/editor
git-subtree-split: 68d15eddb07a9fe6c64fff629f03733bb2ded627
  • Loading branch information
maxme committed Jun 3, 2016
1 parent e8a087f commit 0e7e33b
Showing 1 changed file with 18 additions and 5 deletions.
23 changes: 18 additions & 5 deletions libs/editor-common/assets/ZSSRichTextEditor.js
Original file line number Diff line number Diff line change
Expand Up @@ -3169,6 +3169,7 @@ ZSSField.prototype.handleFocusEvent = function(e) {
ZSSField.prototype.handleKeyDownEvent = function(e) {

var wasEnterPressed = (e.keyCode == '13');
var isHardwareKeyboardPaste = (e.ctrlKey && e.keyCode == '86');

// Handle keyDownEvent actions that need to happen after the event has completed (and the field has been modified)
setTimeout(this.afterKeyDownEvent, 20, e.target.innerHTML, e);
Expand Down Expand Up @@ -3201,18 +3202,30 @@ ZSSField.prototype.handleKeyDownEvent = function(e) {
// incorrectly, so we skip it in this case.
//
// 3. On all APIs, hardware pasting (CTRL + V) doesn't automatically wrap the paste in paragraph tags in
// new posts. ZSSField.handlePasteEvent() does not address this problem. It's the same fix as #2 above, but we
// have to extend the `containsParagraphSeparators` check to all APIs, not just API19 and below, to fix
// hardware pasting.
// new posts. ZSSField.handlePasteEvent() won't fix the wrapping for hardware pastes if
// wrapCaretInParagraphIfNecessary() goes through first, so we need to skip it in that case.
// For API < 19, this is fixed implicitly by the 'containsParagraphSeparators' check, but for newer APIs we
// specifically detect hardware keyboard pastes and skip paragraph wrapping in that case
// case skip calling wrapCaretInParagraphIfNecessary().
//
// Previously, the check was 'if (containsParagraphSeparators)' for all API levels, but this turns out to cause
// an autocorrect issue for new posts on API 23+:
// https://github.com/wordpress-mobile/WordPress-Editor-Android/issues/389
// That issue can be fixed by allowing wrapCaretInParagraphIfNecessary() to go through when adding text to an
// empty post on those API levels, as long as we exclude the special case of hardware keyboard pasting
//
// We're using 'nativeState.androidApiLevel>19' rather than >22 because, even though the bug only appears on
// 23+ at the time of writing, it's entirely possible a future System WebView or Keyboard update will introduce
// the bug on 21+.
var containsParagraphSeparators = this.getWrappedDomNode().innerHTML.search(
'<' + ZSSEditor.defaultParagraphSeparator) > -1;
if (containsParagraphSeparators) {
if (containsParagraphSeparators || (nativeState.androidApiLevel > 19 && !isHardwareKeyboardPaste)) {
this.wrapCaretInParagraphIfNecessary();
}

if (wasEnterPressed) {
// Wrap the existing text in paragraph tags if necessary (this should only be needed if
// wrapCaretInParagraphIfNecessary() was skipped earlier (API19))
// wrapCaretInParagraphIfNecessary() was skipped earlier)
var currentHtml = this.getWrappedDomNode().innerHTML;
if (currentHtml.search('<' + ZSSEditor.defaultParagraphSeparator) == -1) {
ZSSEditor.focusedField.setHTML(Util.wrapHTMLInTag(currentHtml, ZSSEditor.defaultParagraphSeparator));
Expand Down

0 comments on commit 0e7e33b

Please sign in to comment.