[go: nahoru, domu]

Skip to content

Commit

Permalink
Squashed 'libs/editor/' changes from f1f6d10..a35d654
Browse files Browse the repository at this point in the history
a35d654 0.8 version bump
7c242ad Merge pull request #330 from wordpress-mobile/issue/299-exit-blockquote
c0a8f79 Merge branch 'develop' into issue/299-exit-blockquote
dd267de Merge pull request #329 from wordpress-mobile/issue/302-fix-dom-errors
dc084a2 Don't process the second Enter when exiting a blockquote, to avoid adding an extra new line
8a2f91e Allow double Enter press to exit a blockquote
400a5f7 Sanitize all calls to window.getSelection() that are followed by getRangeAt(), which can cause a DOM error
607c010 Fix typo in node traversal method
f2d468f If getFocusedField can't select the current contenteditable div, force focus on the content field
d2e8a78 Avoid DOM error console logs by adding some null checks
cf01d93 Merge commit 'c6efe0a9190244d40e64300efc9cca56ae5acd5c' into develop
ab52e25 Merge branch 'develop' into issue/120editor-initial-focus
6301484 Show the software keyboard once the DOM has loaded
359edf6 Focus on the title field when opening posts

git-subtree-dir: libs/editor
git-subtree-split: a35d654234ed2691a62289d9f554333446f1fa0d
  • Loading branch information
aforcier committed Apr 1, 2016
1 parent c6efe0a commit 4c9324c
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 16 deletions.
4 changes: 2 additions & 2 deletions WordPressEditor/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ android {
buildToolsVersion "23.0.2"

defaultConfig {
versionCode 6
versionName "0.6"
versionCode 8
versionName "0.8"
minSdkVersion 14
targetSdkVersion 23
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -968,11 +968,14 @@ public void run() {
button.setChecked(false);
}

boolean editorHasFocus = false;

// Add any media files that were placed in a queue due to the DOM not having loaded yet
if (mWaitingMediaFiles.size() > 0) {
// Image insertion will only work if the content field is in focus
// (for a new post, no field is in focus until user action)
mWebView.execJavaScriptFromString("ZSSEditor.getField('zss_field_content').focus();");
editorHasFocus = true;

for (Map.Entry<String, MediaFile> entry : mWaitingMediaFiles.entrySet()) {
appendMediaFile(entry.getValue(), entry.getKey(), null);
Expand All @@ -985,6 +988,7 @@ public void run() {
// Gallery insertion will only work if the content field is in focus
// (for a new post, no field is in focus until user action)
mWebView.execJavaScriptFromString("ZSSEditor.getField('zss_field_content').focus();");
editorHasFocus = true;

for (MediaGallery mediaGallery : mWaitingGalleries) {
appendGallery(mediaGallery);
Expand All @@ -993,6 +997,14 @@ public void run() {
mWaitingGalleries.clear();
}

if (!editorHasFocus) {
mWebView.execJavaScriptFromString("ZSSEditor.focusFirstEditableField();");
}

// Show the keyboard
((InputMethodManager)getActivity().getSystemService(Context.INPUT_METHOD_SERVICE))
.showSoftInput(mWebView, InputMethodManager.SHOW_IMPLICIT);

ProfilingUtils.split("EditorFragment.onDomLoaded completed");
ProfilingUtils.dump();
ProfilingUtils.stop();
Expand Down
59 changes: 45 additions & 14 deletions libs/editor-common/assets/ZSSRichTextEditor.js
Original file line number Diff line number Diff line change
Expand Up @@ -193,13 +193,22 @@ ZSSEditor.getField = function(fieldId) {

ZSSEditor.getFocusedField = function() {
var currentField = $(this.closerParentNodeWithName('div'));
var currentFieldId = currentField.attr('id');
var currentFieldId;

while (currentField
&& (!currentFieldId || this.editableFields[currentFieldId] == null)) {
currentField = this.closerParentNodeStartingAtNode('div', currentField);
if (currentField) {
currentFieldId = currentField.attr('id');
}

while (currentField && (!currentFieldId || this.editableFields[currentFieldId] == null)) {
currentField = this.closerParentNodeStartingAtNode('div', currentField);
if (currentField) {
currentFieldId = currentField.attr('id');
}
}

if (!currentFieldId) {
ZSSEditor.resetSelectionOnField('zss_field_content');
currentFieldId = 'zss_field_content';
}

return this.editableFields[currentFieldId];
Expand Down Expand Up @@ -357,6 +366,9 @@ ZSSEditor.stylesCallback = function(stylesArray) {

ZSSEditor.backupRange = function(){
var selection = window.getSelection();
if (selection.rangeCount < 1) {
return;
}
var range = selection.getRangeAt(0);

ZSSEditor.currentSelection =
Expand Down Expand Up @@ -411,7 +423,6 @@ ZSSEditor.getCaretArguments = function() {
};

ZSSEditor.getJoinedFocusedFieldIdAndCaretArguments = function() {

var joinedArguments = ZSSEditor.getJoinedCaretArguments();
var idArgument = "id=" + ZSSEditor.getFocusedField().getNodeId();

Expand All @@ -430,6 +441,9 @@ ZSSEditor.getJoinedCaretArguments = function() {

ZSSEditor.getCaretYPosition = function() {
var selection = window.getSelection();
if (selection.rangeCount == 0) {
return 0;
}
var range = selection.getRangeAt(0);
var span = document.createElement("span");
// Ensure span has dimensions and position by
Expand Down Expand Up @@ -543,7 +557,7 @@ ZSSEditor.setStrikeThrough = function() {
var mustHandleWebKitIssue = (isDisablingStrikeThrough
&& ZSSEditor.isCommandEnabled(commandName));

if (mustHandleWebKitIssue) {
if (mustHandleWebKitIssue && window.getSelection().rangeCount > 0) {
var troublesomeNodeNames = ['del'];

var selection = window.getSelection();
Expand Down Expand Up @@ -2730,6 +2744,9 @@ ZSSEditor.closerParentNode = function() {

var parentNode = null;
var selection = window.getSelection();
if (selection.rangeCount < 1) {
return null;
}
var range = selection.getRangeAt(0).cloneRange();

var currentNode = range.commonAncestorContainer;
Expand All @@ -2752,15 +2769,15 @@ ZSSEditor.closerParentNodeStartingAtNode = function(nodeName, startingNode) {
nodeName = nodeName.toLowerCase();

var parentNode = null;
var currentNode = startingNode,parentElement;
var currentNode = startingNode.parentElement;

while (currentNode) {

if (currentNode.nodeName == document.body.nodeName) {
break;
}

if (currentNode.nodeName.toLowerCase() == nodeName
if (currentNode.nodeName && currentNode.nodeName.toLowerCase() == nodeName
&& currentNode.nodeType == document.ELEMENT_NODE) {
parentNode = currentNode;

Expand All @@ -2779,6 +2796,9 @@ ZSSEditor.closerParentNodeWithName = function(nodeName) {

var parentNode = null;
var selection = window.getSelection();
if (selection.rangeCount < 1) {
return null;
}
var range = selection.getRangeAt(0).cloneRange();

var referenceNode = range.commonAncestorContainer;
Expand Down Expand Up @@ -2820,6 +2840,9 @@ ZSSEditor.parentTags = function() {

var parentTags = [];
var selection = window.getSelection();
if (selection.rangeCount < 1) {
return null;
}
var range = selection.getRangeAt(0);

var currentNode = range.commonAncestorContainer;
Expand Down Expand Up @@ -2937,21 +2960,29 @@ ZSSField.prototype.handleKeyDownEvent = function(e) {
} else if (this.isMultiline()) {
this.wrapCaretInParagraphIfNecessary();

// If enter was pressed to end a UL or OL, let's double check and handle it accordingly if so
if (wasEnterPressed) {
sel = window.getSelection();
node = $(sel.anchorNode);
children = $(sel.anchorNode.childNodes);
var sel = window.getSelection();
if (sel.rangeCount < 1) {
return null;
}
var node = $(sel.anchorNode);
var children = $(sel.anchorNode.childNodes);
var parentNode = rangy.getSelection().anchorNode.parentNode;

// If enter was pressed to end a UL or OL, let's double check and handle it accordingly if so
if (sel.isCollapsed && node.is(NodeName.LI) && (!children.length ||
(children.length == 1 && children.first().is(NodeName.BR)))) {
e.preventDefault();
var parentNode = rangy.getSelection().anchorNode.parentNode;
if (parentNode && parentNode.nodeName === NodeName.OL) {
ZSSEditor.setOrderedList();
} else if (parentNode && parentNode.nodeName === NodeName.UL) {
ZSSEditor.setUnorderedList();
}
// Exit blockquote when the user presses Enter inside a blockquote on a new line
// (main use case is to allow double Enter to exit blockquote)
} else if (sel.isCollapsed && sel.baseOffset == 0 && parentNode && parentNode.nodeName == 'BLOCKQUOTE') {
e.preventDefault();
ZSSEditor.setBlockquote();
}
}
}
Expand Down Expand Up @@ -3211,7 +3242,7 @@ ZSSField.prototype.wrapCaretInParagraphIfNecessary = function()
if (parentNodeShouldBeParagraph) {
var selection = window.getSelection();

if (selection) {
if (selection && selection.rangeCount > 0) {
var range = selection.getRangeAt(0);

if (range.startContainer == range.endContainer) {
Expand Down

0 comments on commit 4c9324c

Please sign in to comment.