Skip to content

Commit 52910dd

Browse files
committed
Squashed 'libs/editor/' changes from 41a1010..7be0b57
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
1 parent d2f7ed4 commit 52910dd

File tree

6 files changed

+57
-42
lines changed

6 files changed

+57
-42
lines changed

.travis.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ android:
77
- extra-android-support
88
- platform-tools
99
- tools
10-
- build-tools-23.0.2
10+
- build-tools-23.0.3
1111
- android-23
1212

1313
env:

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ Finally, update `[PROJECT_ROOT]\.git\info\exclude` to ignore the symlink locally
2828

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

31-
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`.
31+
Unit testing is done with the [Robolectric framework](http://robolectric.org/). To run unit tests simply run `gradlew testDebug`.
3232

3333
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`.
3434

WordPressEditor/build.gradle

Lines changed: 1 addition & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ buildscript {
88
}
99

1010
apply plugin: 'com.android.library'
11-
apply plugin: 'jacoco'
1211
apply plugin: 'maven'
1312
apply plugin: 'signing'
1413

@@ -119,43 +118,10 @@ uploadArchives {
119118
}
120119

121120
//
122-
// Testing and code coverage
121+
// Testing
123122
//
124123

125124
android.testOptions.unitTests.all {
126125
include '**/*Test.class'
127126
exclude '**/ApplicationTest.class'
128127
}
129-
130-
jacoco {
131-
toolVersion = "0.7.1.201405082137"
132-
}
133-
134-
// Use these to define which classes to include and exclude from code coverage analysis
135-
def coverageSourceDirs = [ 'src/main/java' ]
136-
def coverageExclusions = [ '**/R.class',
137-
'**/R$*.class',
138-
'**/*$ViewInjector*.*',
139-
'**/BuildConfig.*',
140-
'**/Manifest*.*',
141-
'**/Legacy**.class',
142-
'**/legacy/**/*.class' ]
143-
144-
task jacocoTestReport(type: JacocoReport, dependsOn: "testDebug") {
145-
group = "Reporting"
146-
description = "Generate Jacoco coverage reports"
147-
148-
classDirectories = fileTree(
149-
dir: 'build/intermediates/classes/debug',
150-
excludes: coverageExclusions
151-
)
152-
153-
additionalSourceDirs = files(coverageSourceDirs)
154-
sourceDirectories = files(coverageSourceDirs)
155-
executionData = files('build/jacoco/testDebug.exec')
156-
157-
reports {
158-
xml.enabled = true
159-
html.enabled = true
160-
}
161-
}

WordPressEditor/src/main/java/org/wordpress/android/editor/EditorFragment.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -529,7 +529,7 @@ public void onClick(View v) {
529529
} else {
530530
// Visual mode
531531
mGetSelectedTextCountDownLatch = new CountDownLatch(1);
532-
mWebView.execJavaScriptFromString("ZSSEditor.execFunctionForResult('getSelectedText');");
532+
mWebView.execJavaScriptFromString("ZSSEditor.execFunctionForResult('getSelectedTextToLinkify');");
533533
try {
534534
if (mGetSelectedTextCountDownLatch.await(1, TimeUnit.SECONDS)) {
535535
dialogBundle.putString(LinkDialogFragment.LINK_DIALOG_ARG_TEXT, mJavaScriptResult);
@@ -1251,7 +1251,7 @@ public void onGetHtmlResponse(Map<String, String> inputArgs) {
12511251
}
12521252
}
12531253
break;
1254-
case "getSelectedText":
1254+
case "getSelectedTextToLinkify":
12551255
mJavaScriptResult = inputArgs.get("result");
12561256
mGetSelectedTextCountDownLatch.countDown();
12571257
break;

WordPressEditor/src/main/java/org/wordpress/android/editor/JsCallbackReceiver.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -211,7 +211,7 @@ public void executeCallback(String callbackId, String params) {
211211
responseIds.add("id");
212212
responseIds.add("contents");
213213
break;
214-
case "getSelectedText":
214+
case "getSelectedTextToLinkify":
215215
responseIds.add("result");
216216
break;
217217
case "getFailedMedia":

libs/editor-common/assets/ZSSRichTextEditor.js

Lines changed: 51 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -400,10 +400,53 @@ ZSSEditor.resetSelectionOnField = function(fieldId) {
400400

401401
ZSSEditor.getSelectedText = function() {
402402
var selection = window.getSelection();
403-
404403
return selection.toString();
405404
};
406405

406+
ZSSEditor.canExpandBackward = function(range) {
407+
var caretRange = range.cloneRange();
408+
if (range.startOffset == 0) {
409+
return false;
410+
}
411+
caretRange.setStart(range.startContainer, range.startOffset - 1);
412+
caretRange.setEnd(range.startContainer, range.startOffset);
413+
if (!caretRange.toString().match(/\w/)) {
414+
return false;
415+
}
416+
return true;
417+
};
418+
419+
ZSSEditor.canExpandForward = function(range) {
420+
var caretRange = range.cloneRange();
421+
if (range.endOffset == range.endContainer.length) {
422+
return false;
423+
}
424+
caretRange.setStart(range.endContainer, range.endOffset);
425+
caretRange.setEnd(range.endContainer, range.endOffset + 1);
426+
if (!caretRange.toString().match(/\w/)) {
427+
return false;
428+
}
429+
return true;
430+
};
431+
432+
ZSSEditor.getSelectedTextToLinkify = function() {
433+
var selection = window.getSelection();
434+
var element = ZSSEditor.getField("zss_field_content");
435+
// If there is no text selected, try to expand it to the word under the cursor
436+
if (selection.rangeCount == 1) {
437+
var range = selection.getRangeAt(0);
438+
while (ZSSEditor.canExpandBackward(range)) {
439+
range.setStart(range.startContainer, range.startOffset - 1);
440+
}
441+
while (ZSSEditor.canExpandForward(range)) {
442+
range.setEnd(range.endContainer, range.endOffset + 1);
443+
}
444+
selection.removeAllRanges();
445+
selection.addRange(range);
446+
}
447+
return selection.toString();
448+
};
449+
407450
ZSSEditor.getCaretArguments = function() {
408451
var caretInfo = this.getYCaretInfo();
409452

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

772815
ZSSEditor.insertLink = function(url, title) {
773-
this.insertHTML('<a href="' + url + '">' + title + "</a>");
816+
var html = '<a href="' + url + '">' + title + "</a>";
817+
818+
if (this.getFocusedField().getHTML().length == 0) {
819+
html = '<' + this.defaultParagraphSeparator + '>' + html;
820+
}
821+
822+
this.insertHTML(html);
774823
};
775824

776825
ZSSEditor.updateLink = function(url, title) {

0 commit comments

Comments
 (0)