Skip to content

Commit

Permalink
Squashed 'libs/editor/' changes from a92ad9d..260a0d5
Browse files Browse the repository at this point in the history
260a0d5 Merge pull request #428 from wordpress-mobile/issue/204-start-post-formatted-text
fb29391 Merge pull request #430 from wordpress-mobile/issue/429-html-regex-crash
438932b Fix #429 HTML mode styling crash
445938d Merge pull request #427 from wordpress-mobile/issue/417-format-current-word
d38b4ab Merge branch 'develop' into issue/204-start-post-formatted-text
709b82f Merge branch 'develop' into issue/417-format-current-word
4758e2a Fix #204 by persisting inline styles when typing in an empty post
4b86c90 Merge pull request #426 from wordpress-mobile/sync-wpandroid
e4b4565 When applying inline formatting, apply the style to the entire word adjacent to the cursor
cb9f57c Bumped targetSdkVersion to 24
13043cb Bumped support library versions to 24
60fb931 Updated Travis config for Android 24
72ae111 Merge commit '7cee07f51ba62c3415d15fb71b0d83c7f507f843' into sync-editor
9faeee7 Merge pull request #425 from wordpress-mobile/fix-example-image
7a44419 Remove unused strings from the editor and merge them with the main strings.xml file for i18n
5031c47 Fixed issue where partial text selections would be expanded to the full word when linking
314e706 Extracted cursor expansion part of getSelectedTextToLinkify into a separate method
9005ef3 Merge branch 'release/5.5' into develop
fc4c730 Fix broken image link in example post
61b592c Merge commit 'd0d8dd46c2b8223d66ec3e80578788d1b6cd8b85' into release/5.5
e7289ce Adjusted spacing and styling for text expansion JS methods
e6a29b5 Merge branch 'develop' into issue/3924-method-count
a008e48 Merge branch 'release/5.5' into develop
a7395aa Merge commit '49ac39827552c17c8d5b65eca236a55961cf6814' into release/5.5
0c7e9f1 Merge commit '1cf141b3362c5c44f27a8b65775d3db27ac5756a' into release/5.5
5123e3c Merge branch 'release/5.5' into develop
b15d049 Merge commit '65eec31755233d054ff01bf729eea6d233f6d7df' into release/5.5
9e8fc97 Merge commit '2fc5d53d4ba45ed45c806a5ac0772458a4ef403e' into release/5.5
aab8458 update compileSdkVersion and buildToolsVersion in every subtrees
3c57356 update gradle wrapper to 2.14
3d748d5 onFeaturedImageChanged signature changed: long instead of int
a3a53d3 Merge branch 'hotfix/5.4.2' into release/5.5
19170dc Use a long for featured image IDs

git-subtree-dir: libs/editor
git-subtree-split: 260a0d5ba0eae70b44d4ccc826d2a2025f344280
  • Loading branch information
maxme committed Jun 29, 2016
1 parent d0d8dd4 commit ced2637
Show file tree
Hide file tree
Showing 14 changed files with 108 additions and 54 deletions.
10 changes: 7 additions & 3 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,20 +1,24 @@
language: android
jdk: oraclejdk7
jdk: oraclejdk8

android:
components:
- extra-android-m2repository
- extra-android-support
- platform-tools
- tools
- build-tools-23.0.3
- android-23
- build-tools-24.0.0
- android-24

env:
global:
- GRADLE_OPTS="-XX:MaxPermSize=4g -Xmx4g"
- ANDROID_SDKS=android-16
- ANDROID_TARGET=android-16

before_install:
# TODO: Remove the following line when Travis' platform-tools are updated to v24+
- echo yes | android update sdk -a --filter platform-tools --no-ui --force

script:
- ./gradlew build
12 changes: 6 additions & 6 deletions WordPressEditor/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,14 @@ repositories {
android {
publishNonDefault true

compileSdkVersion 23
buildToolsVersion "23.0.3"
compileSdkVersion 24
buildToolsVersion "24.0.0"

defaultConfig {
versionCode 12
versionName "1.2"
minSdkVersion 16
targetSdkVersion 23
targetSdkVersion 24
}
buildTypes {
release {
Expand All @@ -45,9 +45,9 @@ android {
}

dependencies {
compile 'com.android.support:appcompat-v7:23.4.0'
compile 'com.android.support:support-v4:23.4.0'
compile 'com.android.support:design:23.4.0'
compile 'com.android.support:appcompat-v7:24.0.0'
compile 'com.android.support:support-v4:24.0.0'
compile 'com.android.support:design:24.0.0'
compile 'org.wordpress:utils:1.10.0'

// Test libraries
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ protected void onCreate(Bundle savedInstanceState) {
@Override
public void onEditorFragmentInitialized() {
mEditorFragment.setTitle("A title");
mEditorFragment.setContent(Utils.getHtmlFromFile(this, "example-content.html"));
mEditorFragment.setContent(Utils.getHtmlFromFile(this, "example/example-content.html"));
}

@Override
Expand All @@ -58,7 +58,7 @@ public void onMediaUploadCancelClicked(String mediaId, boolean delete) {
}

@Override
public void onFeaturedImageChanged(int mediaId) {
public void onFeaturedImageChanged(long mediaId) {

}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ public static MediaType fromString(String value) {

protected EditorFragmentListener mEditorFragmentListener;
protected boolean mFeaturedImageSupported;
protected int mFeaturedImageId;
protected long mFeaturedImageId;
protected String mBlogSettingMaxImageWidth;
protected ImageLoader mImageLoader;
protected boolean mDebugModeEnabled;
Expand Down Expand Up @@ -101,7 +101,7 @@ public void setBlogSettingMaxImageWidth(String blogSettingMaxImageWidth) {
mBlogSettingMaxImageWidth = blogSettingMaxImageWidth;
}

public void setFeaturedImageId(int featuredImageId) {
public void setFeaturedImageId(long featuredImageId) {
mFeaturedImageId = featuredImageId;
}

Expand Down Expand Up @@ -142,7 +142,7 @@ public interface EditorFragmentListener {
void onAddMediaClicked();
void onMediaRetryClicked(String mediaId);
void onMediaUploadCancelClicked(String mediaId, boolean delete);
void onFeaturedImageChanged(int mediaId);
void onFeaturedImageChanged(long mediaId);
void onVideoPressInfoRequested(String videoId);
String onAuthHeaderRequested(String url);
// TODO: remove saveMediaFile, it's currently needed for the legacy editor
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,12 @@ protected void updateSpans(Spannable content, SpanRange spanRange) {
if (spanStart > content.length() || spanEnd > content.length()) {
AppLog.d(T.EDITOR, "The specified span range was beyond the Spannable's length");
return;
} else if (spanStart >= spanEnd) {
// If the span start is after the end position (probably due to a multi-line deletion), selective
// re-styling won't work
// Instead, do a clean re-styling of the whole document
spanStart = 0;
spanEnd = content.length();
}

HtmlStyleUtils.clearSpans(content, spanStart, spanEnd);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,8 @@ public static void styleHtmlForDisplay(@NonNull Spannable content, int start, in
* @param regex the pattern to match for styling
*/
private static void applySpansByRegex(Spannable content, int start, int end, String regex) {
if (content == null || start < 0 || end < 0 || start > content.length() || end > content.length()) {
if (content == null || start < 0 || end < 0 || start > content.length() || end > content.length() ||
start >= end) {
AppLog.d(AppLog.T.EDITOR, "applySpansByRegex() received invalid input");
return;
}
Expand Down
9 changes: 0 additions & 9 deletions WordPressEditor/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -59,13 +59,6 @@
<item>Right</item>
</string-array>

<string-array name="image_size_array">
<item>Thumbnail</item>
<item>Medium</item>
<item>Large</item>
<item>Full Size</item>
</string-array>

<!-- Accessibility - format bar button descriptions -->
<string name="format_bar_description_bold">Bold</string>
<string name="format_bar_description_italic">Italic</string>
Expand All @@ -81,9 +74,7 @@
<string name="visual_editor">Visual editor</string>
<string name="image_thumbnail">Image thumbnail</string>


<string name="editor_failed_uploads_switch_html">Some media uploads have failed. You can\'t switch to HTML mode
in this state. Remove all failed uploads and continue?</string>
<string name="editor_remove_failed_uploads">Remove failed uploads</string>
<string name="send_link">Send link</string>
</resources>
6 changes: 3 additions & 3 deletions example/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,13 @@ repositories {
apply plugin: 'com.android.application'

android {
compileSdkVersion 23
buildToolsVersion "23.0.3"
compileSdkVersion 24
buildToolsVersion "24.0.0"

defaultConfig {
applicationId "org.wordpress.editorexample"
minSdkVersion 16
targetSdkVersion 23
targetSdkVersion 24
versionCode 1
versionName "1.0"
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ public void onMediaUploadCancelClicked(String mediaId, boolean delete) {
}

@Override
public void onFeaturedImageChanged(int mediaId) {
public void onFeaturedImageChanged(long mediaId) {

}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ protected void onCreate(Bundle savedInstanceState) {
Bundle bundle = new Bundle();
bundle.putString(EditorExampleActivity.TITLE_PARAM, getString(R.string.example_post_visual_title));
bundle.putString(EditorExampleActivity.CONTENT_PARAM, Utils.getHtmlFromFile(mActivity,
"example-content.html"));
"example/example-content.html"));
bundle.putString(EditorExampleActivity.TITLE_PLACEHOLDER_PARAM,
getString(R.string.example_post_title_placeholder));
bundle.putString(EditorExampleActivity.CONTENT_PLACEHOLDER_PARAM,
Expand Down
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-2.10-all.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-2.14-all.zip
98 changes: 75 additions & 23 deletions libs/editor-common/assets/ZSSRichTextEditor.js
Original file line number Diff line number Diff line change
Expand Up @@ -436,19 +436,38 @@ ZSSEditor.getSelectedText = function() {
return selection.toString();
};

ZSSEditor.selectWordAroundCursor = function() {
var selection = window.getSelection();
// If there is no text selected, try to expand it to the word under the cursor
if (selection.rangeCount == 1) {
var range = selection.getRangeAt(0);
if (range.startOffset == range.endOffset) {
while (ZSSEditor.canExpandBackward(range)) {
range.setStart(range.startContainer, range.startOffset - 1);
}
while (ZSSEditor.canExpandForward(range)) {
range.setEnd(range.endContainer, range.endOffset + 1);
}
selection.removeAllRanges();
selection.addRange(range);
}
}
return selection;
};

ZSSEditor.canExpandBackward = function(range) {
// Can't expand if focus is not a text node
if (!range.endContainer.nodeType == 3) {
return false;
}
var caretRange = range.cloneRange();
if (range.startOffset == 0) {
return false;
return false;
}
caretRange.setStart(range.startContainer, range.startOffset - 1);
caretRange.setEnd(range.startContainer, range.startOffset);
if (!caretRange.toString().match(/\w/)) {
return false;
return false;
}
return true;
};
Expand All @@ -459,35 +478,22 @@ ZSSEditor.canExpandForward = function(range) {
return false;
}
var caretRange = range.cloneRange();
if (range.endOffset == range.endContainer.length) {
return false;
if (range.endOffset == range.endContainer.length) {
return false;
}
caretRange.setStart(range.endContainer, range.endOffset);
if (range.endOffset )
caretRange.setEnd(range.endContainer, range.endOffset + 1);
var strin = caretRange.toString();
if (range.endOffset) {
caretRange.setEnd(range.endContainer, range.endOffset + 1);
}
if (!caretRange.toString().match(/\w/)) {
return false;
return false;
}
return true;
};

ZSSEditor.getSelectedTextToLinkify = function() {
var selection = window.getSelection();
var element = ZSSEditor.getField("zss_field_content");
// If there is no text selected, try to expand it to the word under the cursor
if (selection.rangeCount == 1) {
var range = selection.getRangeAt(0);
while (ZSSEditor.canExpandBackward(range)) {
range.setStart(range.startContainer, range.startOffset - 1);
}
while (ZSSEditor.canExpandForward(range)) {
range.setEnd(range.endContainer, range.endOffset + 1);
}
selection.removeAllRanges();
selection.addRange(range);
}
return selection.toString();
ZSSEditor.selectWordAroundCursor();
return document.getSelection().toString();
};

ZSSEditor.getCaretArguments = function() {
Expand Down Expand Up @@ -600,26 +606,31 @@ ZSSEditor.getYCaretInfo = function() {
// MARK: - Styles

ZSSEditor.setBold = function() {
ZSSEditor.selectWordAroundCursor();
document.execCommand('bold', false, null);
ZSSEditor.sendEnabledStyles();
};

ZSSEditor.setItalic = function() {
ZSSEditor.selectWordAroundCursor();
document.execCommand('italic', false, null);
ZSSEditor.sendEnabledStyles();
};

ZSSEditor.setSubscript = function() {
ZSSEditor.selectWordAroundCursor();
document.execCommand('subscript', false, null);
ZSSEditor.sendEnabledStyles();
};

ZSSEditor.setSuperscript = function() {
ZSSEditor.selectWordAroundCursor();
document.execCommand('superscript', false, null);
ZSSEditor.sendEnabledStyles();
};

ZSSEditor.setStrikeThrough = function() {
ZSSEditor.selectWordAroundCursor();
var commandName = 'strikeThrough';
var isDisablingStrikeThrough = ZSSEditor.isCommandEnabled(commandName);

Expand Down Expand Up @@ -668,6 +679,7 @@ ZSSEditor.setStrikeThrough = function() {
};

ZSSEditor.setUnderline = function() {
ZSSEditor.selectWordAroundCursor();
document.execCommand('underline', false, null);
ZSSEditor.sendEnabledStyles();
};
Expand Down Expand Up @@ -826,6 +838,7 @@ ZSSEditor.setOutdent = function() {
};

ZSSEditor.setTextColor = function(color) {
ZSSEditor.selectWordAroundCursor();
ZSSEditor.restoreRange();
document.execCommand("styleWithCSS", null, true);
document.execCommand('foreColor', false, color);
Expand All @@ -835,6 +848,7 @@ ZSSEditor.setTextColor = function(color) {
};

ZSSEditor.setBackgroundColor = function(color) {
ZSSEditor.selectWordAroundCursor();
ZSSEditor.restoreRange();
document.execCommand("styleWithCSS", null, true);
document.execCommand('hiliteColor', false, color);
Expand Down Expand Up @@ -2584,6 +2598,31 @@ ZSSEditor.sendEnabledStyles = function(e) {
ZSSEditor.stylesCallback(items);
};

ZSSEditor.storeInlineStylesAsFunctions = function() {
var styles = [];

if (ZSSEditor.isCommandEnabled('bold')) {
styles.push(ZSSEditor.setBold);
}
if (ZSSEditor.isCommandEnabled('italic')) {
styles.push(ZSSEditor.setItalic);
}
if (ZSSEditor.isCommandEnabled('strikeThrough')) {
styles.push(ZSSEditor.setStrikeThrough);
}
if (ZSSEditor.isCommandEnabled('underline')) {
styles.push(ZSSEditor.setUnderline);
}
if (ZSSEditor.isCommandEnabled('subscript')) {
styles.push(ZSSEditor.setSubscript);
}
if (ZSSEditor.isCommandEnabled('superscript')) {
styles.push(ZSSEditor.setSuperscript);
}

return styles;
};

// MARK: - Commands: High Level Editing

/**
Expand Down Expand Up @@ -3628,6 +3667,14 @@ ZSSField.prototype.wrapCaretInParagraphIfNecessary = function() {
closerParentNode.removeChild(closerParentNode.firstChild);
}

var storedStyles = [];
if (this.getWrappedDomNode().innerHTML.length == 0) {
// If the post is empty, store any active in-line formatting so it can be re-applied after the
// DOM manipulations are completed
// (Fix for https://github.com/wordpress-mobile/WordPress-Editor-Android/issues/204)
storedStyles = ZSSEditor.storeInlineStylesAsFunctions();
}

var paragraph = document.createElement("div");
var textNode = document.createTextNode("&#x200b;");

Expand All @@ -3638,6 +3685,11 @@ ZSSField.prototype.wrapCaretInParagraphIfNecessary = function() {

selection.removeAllRanges();
selection.addRange(range);

// Re-apply inline styles that were cleared
storedStyles.map(function(styleFunction) {
styleFunction();
});
}
}
}
Expand Down
Binary file added libs/editor-common/assets/example/cowboy-cat.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading

0 comments on commit ced2637

Please sign in to comment.