Skip to content

Commit

Permalink
Squashed 'libs/editor/' changes from 41a1010..7be0b57
Browse files Browse the repository at this point in the history
7be0b57 Merge pull request #342 from wordpress-mobile/issue/340-wrap-new-post-links-in-paragraphs
6decc08 Wrap links in a new paragraph when the post is empty
04e0570 Merge pull request #338 from wordpress-mobile/issue/fix-travis-and-kill-jacoco
0372a90 Merge pull request #332 from wordpress-mobile/issue/307-expand-selection-to-word-when-creating-a-link
76883ef Update travis config to use build tools 23.0.3
e0b6a7d remove jacoco code coverage
5670205 homemade selection expansion
5749a16 Merge branch 'develop' into issue/307-expand-selection-to-word-when-creating-a-link
1b4a632 Expand selection to the word when creating a link and nothing is selected

git-subtree-dir: libs/editor
git-subtree-split: 7be0b577ed7c57301cda9fd99f1d1ca9f2a49dd3
  • Loading branch information
maxme committed Apr 11, 2016
1 parent d2f7ed4 commit 52910dd
Show file tree
Hide file tree
Showing 6 changed files with 57 additions and 42 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ android:
- extra-android-support
- platform-tools
- tools
- build-tools-23.0.2
- build-tools-23.0.3
- android-23

env:
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ Finally, update `[PROJECT_ROOT]\.git\info\exclude` to ignore the symlink locally

This project has both unit testing and integration testing, maintained and run separately.

Unit testing is done with the [Robolectric framework](http://robolectric.org/). To run unit tests simply run `gradlew testDebug`. Code coverage reports can be generated via [JaCoCo.](http://www.eclemma.org/jacoco/) To generate them locally run `gradlew jacocoTestReport`.
Unit testing is done with the [Robolectric framework](http://robolectric.org/). To run unit tests simply run `gradlew testDebug`.

Integration testing is done with the [Android testing framework](http://developer.android.com/tools/testing/testing_android.html). To run integration tests run `gradlew connectedAndroidTest`.

Expand Down
36 changes: 1 addition & 35 deletions WordPressEditor/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ buildscript {
}

apply plugin: 'com.android.library'
apply plugin: 'jacoco'
apply plugin: 'maven'
apply plugin: 'signing'

Expand Down Expand Up @@ -119,43 +118,10 @@ uploadArchives {
}

//
// Testing and code coverage
// Testing
//

android.testOptions.unitTests.all {
include '**/*Test.class'
exclude '**/ApplicationTest.class'
}

jacoco {
toolVersion = "0.7.1.201405082137"
}

// Use these to define which classes to include and exclude from code coverage analysis
def coverageSourceDirs = [ 'src/main/java' ]
def coverageExclusions = [ '**/R.class',
'**/R$*.class',
'**/*$ViewInjector*.*',
'**/BuildConfig.*',
'**/Manifest*.*',
'**/Legacy**.class',
'**/legacy/**/*.class' ]

task jacocoTestReport(type: JacocoReport, dependsOn: "testDebug") {
group = "Reporting"
description = "Generate Jacoco coverage reports"

classDirectories = fileTree(
dir: 'build/intermediates/classes/debug',
excludes: coverageExclusions
)

additionalSourceDirs = files(coverageSourceDirs)
sourceDirectories = files(coverageSourceDirs)
executionData = files('build/jacoco/testDebug.exec')

reports {
xml.enabled = true
html.enabled = true
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -529,7 +529,7 @@ public void onClick(View v) {
} else {
// Visual mode
mGetSelectedTextCountDownLatch = new CountDownLatch(1);
mWebView.execJavaScriptFromString("ZSSEditor.execFunctionForResult('getSelectedText');");
mWebView.execJavaScriptFromString("ZSSEditor.execFunctionForResult('getSelectedTextToLinkify');");
try {
if (mGetSelectedTextCountDownLatch.await(1, TimeUnit.SECONDS)) {
dialogBundle.putString(LinkDialogFragment.LINK_DIALOG_ARG_TEXT, mJavaScriptResult);
Expand Down Expand Up @@ -1251,7 +1251,7 @@ public void onGetHtmlResponse(Map<String, String> inputArgs) {
}
}
break;
case "getSelectedText":
case "getSelectedTextToLinkify":
mJavaScriptResult = inputArgs.get("result");
mGetSelectedTextCountDownLatch.countDown();
break;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ public void executeCallback(String callbackId, String params) {
responseIds.add("id");
responseIds.add("contents");
break;
case "getSelectedText":
case "getSelectedTextToLinkify":
responseIds.add("result");
break;
case "getFailedMedia":
Expand Down
53 changes: 51 additions & 2 deletions libs/editor-common/assets/ZSSRichTextEditor.js
Original file line number Diff line number Diff line change
Expand Up @@ -400,10 +400,53 @@ ZSSEditor.resetSelectionOnField = function(fieldId) {

ZSSEditor.getSelectedText = function() {
var selection = window.getSelection();

return selection.toString();
};

ZSSEditor.canExpandBackward = function(range) {
var caretRange = range.cloneRange();
if (range.startOffset == 0) {
return false;
}
caretRange.setStart(range.startContainer, range.startOffset - 1);
caretRange.setEnd(range.startContainer, range.startOffset);
if (!caretRange.toString().match(/\w/)) {
return false;
}
return true;
};

ZSSEditor.canExpandForward = function(range) {
var caretRange = range.cloneRange();
if (range.endOffset == range.endContainer.length) {
return false;
}
caretRange.setStart(range.endContainer, range.endOffset);
caretRange.setEnd(range.endContainer, range.endOffset + 1);
if (!caretRange.toString().match(/\w/)) {
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.getCaretArguments = function() {
var caretInfo = this.getYCaretInfo();

Expand Down Expand Up @@ -770,7 +813,13 @@ ZSSEditor.insertHTMLWrappedInParagraphTags = function(html) {
// Needs addClass method

ZSSEditor.insertLink = function(url, title) {
this.insertHTML('<a href="' + url + '">' + title + "</a>");
var html = '<a href="' + url + '">' + title + "</a>";

if (this.getFocusedField().getHTML().length == 0) {
html = '<' + this.defaultParagraphSeparator + '>' + html;
}

this.insertHTML(html);
};

ZSSEditor.updateLink = function(url, title) {
Expand Down

0 comments on commit 52910dd

Please sign in to comment.