Skip to content

Commit 8293e13

Browse files
committed
Merge branch 'develop' into issue/610-api26-style-lost-prepend-new-line
# Conflicts: # aztec/src/main/kotlin/org/wordpress/aztec/watchers/event/buckets/API26Bucket.kt
2 parents b7b0d32 + e6fc800 commit 8293e13

File tree

7 files changed

+139
-4
lines changed

7 files changed

+139
-4
lines changed

app/src/androidTest/kotlin/org/wordpress/aztec/demo/Actions.kt

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -156,4 +156,22 @@ object Actions {
156156
}
157157
}
158158
}
159+
160+
fun setSelection(start: Int, end: Int): ViewAction {
161+
return object : ViewAction {
162+
override fun getConstraints(): Matcher<View> {
163+
return allOf(isDisplayed(), isAssignableFrom(EditText::class.java))
164+
}
165+
166+
override fun getDescription(): String {
167+
return "Set Aztec text selection to the specified range"
168+
}
169+
170+
override fun perform(uiController: UiController?, view: View?) {
171+
if (view is AztecText) {
172+
view.setSelection(start, end)
173+
}
174+
}
175+
}
176+
}
159177
}

app/src/androidTest/kotlin/org/wordpress/aztec/demo/pages/EditorPage.kt

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,13 @@ class EditorPage : BasePage() {
9797
return this
9898
}
9999

100+
fun selectText(start: Int, end: Int): EditorPage {
101+
editor.perform(Actions.setSelection(start, end))
102+
label("Selected text")
103+
104+
return this
105+
}
106+
100107
/**
101108
* Using selectAllText() + delete() do not work as intended. This method
102109
* will select all the text in the editor and then delete that text.
Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
package org.wordpress.aztec.demo.tests
2+
3+
import android.support.test.rule.ActivityTestRule
4+
import org.junit.Before
5+
import org.junit.Rule
6+
import org.junit.Test
7+
import org.wordpress.aztec.AztecText
8+
import org.wordpress.aztec.demo.BaseTest
9+
import org.wordpress.aztec.demo.MainActivity
10+
import org.wordpress.aztec.demo.R
11+
import org.wordpress.aztec.demo.pages.EditorPage
12+
import org.wordpress.aztec.plugins.CssUnderlinePlugin
13+
14+
class CssUnderlineFormattingTests : BaseTest() {
15+
16+
@Rule
17+
@JvmField
18+
var mActivityTestRule = ActivityTestRule(MainActivity::class.java)
19+
20+
@Before
21+
fun init() {
22+
val aztecText = mActivityTestRule.activity.findViewById<AztecText>(R.id.aztec)
23+
aztecText.plugins.add(CssUnderlinePlugin())
24+
}
25+
26+
@Test
27+
fun testSimpleCssUnderlineFormatting() {
28+
val text1 = "some"
29+
val text2 = "text"
30+
val html = "$text1<span style=\"text-decoration: underline\">$text2</span>"
31+
32+
EditorPage()
33+
.insertText(text1)
34+
.toggleUnderline()
35+
.insertText(text2)
36+
.toggleHtml()
37+
.verifyHTML(html)
38+
}
39+
40+
@Test
41+
fun testRegularUnderlineFormattingPreservation() {
42+
val text1 = "some"
43+
val text2 = "text"
44+
val html = "$text1<u>$text2</u>"
45+
46+
EditorPage()
47+
.toggleHtml()
48+
.insertHTML(html)
49+
.toggleHtml()
50+
.toggleHtml()
51+
.verifyHTML(html)
52+
}
53+
54+
@Test
55+
fun testTogglingUnderlineFormatting() {
56+
val text1 = "some"
57+
val text2 = "text"
58+
val html = "$text1<u>$text2</u>"
59+
val expectedHtml = "$text1<span style=\"text-decoration: underline\">$text2</span>"
60+
61+
EditorPage()
62+
.toggleHtml()
63+
.insertHTML(html)
64+
.toggleHtml()
65+
.selectText(4, 8)
66+
.toggleUnderline()
67+
.toggleHtml()
68+
.verifyHTML("$text1$text2")
69+
.toggleHtml()
70+
.selectText(4, 8)
71+
.toggleUnderline()
72+
.toggleHtml()
73+
.verifyHTML(expectedHtml)
74+
}
75+
76+
@Test
77+
fun testSimpleSplittingRegularUnderlineFormatting() {
78+
val text1 = "some"
79+
val text2 = "text"
80+
val html = "$text1<u>$text2</u>"
81+
val expectedHtml = "$text1<span style=\"text-decoration: underline\">te</span>\n\n" +
82+
"<span style=\"text-decoration: underline\">xt</span>"
83+
84+
EditorPage()
85+
.toggleHtml()
86+
.insertHTML(html)
87+
.toggleHtml()
88+
.setCursorPositionAtEnd()
89+
.moveCursorLeftAsManyTimes(2)
90+
.insertNewLine()
91+
.toggleHtml()
92+
.verifyHTML(expectedHtml)
93+
}
94+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
package org.wordpress.aztec.watchers.event.buckets
2+
3+
import org.wordpress.aztec.watchers.event.sequence.known.space.API25InWordSpaceInsertionEvent
4+
5+
class API25Bucket : Bucket() {
6+
init {
7+
// constructor - here add all identified sequences for this bucket
8+
userOperations.add(API25InWordSpaceInsertionEvent())
9+
//mUserOperations.add(new ...);
10+
//mUserOperations.add(new ...);
11+
//mUserOperations.add(new ...);
12+
}
13+
}

aztec/src/main/kotlin/org/wordpress/aztec/watchers/event/buckets/API26Bucket.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
package org.wordpress.aztec.watchers.event.buckets
22

3-
import org.wordpress.aztec.watchers.event.sequence.known.space.API26InWordSpaceInsertionEvent
3+
import org.wordpress.aztec.watchers.event.sequence.known.space.API25InWordSpaceInsertionEvent
44
import org.wordpress.aztec.watchers.event.sequence.known.space.API26PrependNewLineOnStyledSpecialTextEvent
55
import org.wordpress.aztec.watchers.event.sequence.known.space.API26PrependNewLineOnStyledTextEvent
66

77
class API26Bucket : Bucket() {
88
init {
99
// constructor - here add all identified sequences for this bucket
10-
userOperations.add(API26InWordSpaceInsertionEvent())
10+
userOperations.add(API25InWordSpaceInsertionEvent())
1111
userOperations.add(API26PrependNewLineOnStyledTextEvent())
1212
userOperations.add(API26PrependNewLineOnStyledSpecialTextEvent())
1313
//mUserOperations.add(new ...);

aztec/src/main/kotlin/org/wordpress/aztec/watchers/event/sequence/ObservationQueue.kt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package org.wordpress.aztec.watchers.event.sequence
22

33
import android.os.Build
44
import org.wordpress.aztec.watchers.event.IEventInjector
5+
import org.wordpress.aztec.watchers.event.buckets.API25Bucket
56
import org.wordpress.aztec.watchers.event.buckets.API26Bucket
67
import org.wordpress.aztec.watchers.event.buckets.Bucket
78
import org.wordpress.aztec.watchers.event.text.TextWatcherEvent
@@ -12,6 +13,8 @@ class ObservationQueue(val injector: IEventInjector) : EventSequence<TextWatcher
1213
init {
1314
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
1415
buckets.add(API26Bucket())
16+
} else if (Build.VERSION.SDK_INT == Build.VERSION_CODES.N_MR1) {
17+
buckets.add(API25Bucket())
1518
}
1619
/*
1720
remember to add here any other buckets and init logic as suitable, depending on the context

aztec/src/main/kotlin/org/wordpress/aztec/watchers/event/sequence/known/space/API26InWordSpaceInsertionEvent.kt renamed to aztec/src/main/kotlin/org/wordpress/aztec/watchers/event/sequence/known/space/API25InWordSpaceInsertionEvent.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import org.wordpress.aztec.watchers.event.text.TextWatcherEvent
1111
/*
1212
This case implements the behavior observed in https://github.com/wordpress-mobile/AztecEditor-Android/issues/555
1313
*/
14-
class API26InWordSpaceInsertionEvent : UserOperationEvent() {
14+
class API25InWordSpaceInsertionEvent : UserOperationEvent() {
1515
private val SPACE = ' '
1616
private val SPACE_STRING = "" + SPACE
1717

@@ -34,7 +34,7 @@ class API26InWordSpaceInsertionEvent : UserOperationEvent() {
3434
val builderStep4 = TextWatcherEventInsertText.Builder()
3535
val step4 = builderStep4.build()
3636

37-
// add each of the steps that make up for the identified API26InWordSpaceInsertionEvent here
37+
// add each of the steps that make up for the identified API25InWordSpaceInsertionEvent here
3838
clear()
3939
addSequenceStep(step1)
4040
addSequenceStep(step2)

0 commit comments

Comments
 (0)