Skip to content

Commit b7b0d32

Browse files
committed
Merge branch 'develop' into issue/610-api26-style-lost-prepend-new-line
2 parents ffcaed0 + fe41693 commit b7b0d32

File tree

9 files changed

+58
-51
lines changed

9 files changed

+58
-51
lines changed

.firebase.secrets.json.enc

2.31 KB
Binary file not shown.

.travis.yml

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,21 @@ env:
2020
- ANDROID_TARGET=android-16
2121

2222
before_install:
23-
# TODO: Remove the following line when Travis' platform-tools are updated to v24+
24-
- echo yes | android update sdk -a --filter platform-tools --no-ui --force
23+
# Decrypt secret.json (firebase access)
24+
- openssl aes-256-cbc -K $encrypted_3480988b28c1_key -iv $encrypted_3480988b28c1_iv -in .firebase.secrets.json.enc -out .firebase.secrets.json -d
2525

2626
script:
27-
- ./gradlew build
27+
# Build
28+
- ./gradlew assemble assembleAndroidTest
29+
# Run unit tests
30+
- ./gradlew test
31+
# Android lint
2832
- ./gradlew lint
33+
# Kotlin lint and checkstyle
2934
- ./gradlew ktlint
35+
# Download and setup gcloud
36+
- wget https://dl.google.com/dl/cloudsdk/channels/rapid/downloads/google-cloud-sdk-185.0.0-linux-x86_64.tar.gz
37+
- tar xf google-cloud-sdk-185.0.0-linux-x86_64.tar.gz
38+
- ./google-cloud-sdk/bin/gcloud auth activate-service-account --key-file .firebase.secrets.json
39+
# Run connected tests
40+
- ./google-cloud-sdk/bin/gcloud firebase test android run --type instrumentation --app app/build/outputs/apk/debug/app-debug.apk --test app/build/outputs/apk/androidTest/debug/app-debug-androidTest.apk --device model=Nexus5X,version=26,locale=en,orientation=portrait --project api-project-108380595987 --timeout 10m --verbosity info & while kill -0 $! 2> /dev/null; do echo -n .; sleep 10; done

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,10 @@
44
- Plugin that detects and hides Gutenberg editor blocks in the visual editor
55
- Plugin that adds support for CSS-style underline formatting
66

7+
## [1.0.1](https://github.com/wordpress-mobile/AztecEditor-Android/releases/tag/v1.0.1) - 2018-01-22
8+
### Fixed
9+
- Crash when pasting certain text
10+
711
## [1.0](https://github.com/wordpress-mobile/AztecEditor-Android/releases/tag/v1.0) - 2018-01-11
812
### Fixed
913
- Various problems when editing captions

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,7 @@ class EditorPage : BasePage() {
180180
label("Inserting media")
181181

182182
Thread.sleep(200)
183-
galleryButton.perform(click())
183+
galleryButton.perform(Actions.invokeClick())
184184
label("Chose gallery")
185185

186186
Thread.sleep(200)
@@ -415,4 +415,4 @@ class EditorPage : BasePage() {
415415
UNORDERED(onData(hasToString("Unordered List"))),
416416
ORDERED(onData(hasToString("Ordered List")))
417417
}
418-
}
418+
}

aztec/src/main/kotlin/org/wordpress/aztec/AztecText.kt

Lines changed: 14 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -397,7 +397,7 @@ class AztecText : AppCompatEditText, TextWatcher, UnknownHtmlSpan.OnUnknownHtmlT
397397
var wasStyleRemoved = false
398398
if (event.action == KeyEvent.ACTION_DOWN && event.keyCode == KeyEvent.KEYCODE_DEL) {
399399
if (!consumeHistoryEvent) {
400-
history.beforeTextChanged(toFormattedHtml())
400+
history.beforeTextChanged(this@AztecText)
401401
}
402402
wasStyleRemoved = blockFormatter.tryRemoveBlockStyleFromFirstLine()
403403

@@ -411,10 +411,6 @@ class AztecText : AppCompatEditText, TextWatcher, UnknownHtmlSpan.OnUnknownHtmlT
411411
setText("")
412412
enableTextChangedListener()
413413
}
414-
415-
if (!consumeHistoryEvent) {
416-
history.handleHistory(this@AztecText)
417-
}
418414
}
419415
return wasStyleRemoved
420416
}
@@ -464,7 +460,7 @@ class AztecText : AppCompatEditText, TextWatcher, UnknownHtmlSpan.OnUnknownHtmlT
464460
override fun beforeTextChanged(text: CharSequence, start: Int, count: Int, after: Int) {
465461
if (!isViewInitialized) return
466462
if (!isTextChangedListenerDisabled() && !consumeHistoryEvent) {
467-
history.beforeTextChanged(toFormattedHtml())
463+
history.beforeTextChanged(this@AztecText)
468464
}
469465
}
470466
override fun onTextChanged(text: CharSequence, start: Int, before: Int, count: Int) {
@@ -480,8 +476,6 @@ class AztecText : AppCompatEditText, TextWatcher, UnknownHtmlSpan.OnUnknownHtmlT
480476
if (consumeHistoryEvent) {
481477
consumeHistoryEvent = false
482478
}
483-
484-
history.handleHistory(this@AztecText)
485479
}
486480
}
487481
addTextChangedListener(historyLoggingWatcher)
@@ -790,7 +784,7 @@ class AztecText : AppCompatEditText, TextWatcher, UnknownHtmlSpan.OnUnknownHtmlT
790784
}
791785

792786
fun toggleFormatting(textFormat: ITextFormat) {
793-
history.beforeTextChanged(toFormattedHtml())
787+
history.beforeTextChanged(this@AztecText)
794788

795789
when (textFormat) {
796790
AztecTextFormat.FORMAT_PARAGRAPH,
@@ -816,8 +810,6 @@ class AztecText : AppCompatEditText, TextWatcher, UnknownHtmlSpan.OnUnknownHtmlT
816810
.forEach { it.toggle() }
817811
}
818812
}
819-
820-
history.handleHistory(this)
821813
}
822814

823815
fun contains(format: ITextFormat, selStart: Int = selectionStart, selEnd: Int = selectionEnd): Boolean {
@@ -857,7 +849,7 @@ class AztecText : AppCompatEditText, TextWatcher, UnknownHtmlSpan.OnUnknownHtmlT
857849
}
858850

859851
private fun isEventObservableCandidate() : Boolean {
860-
return (!bypassObservationQueue && (watchersNestingLevel == 1))
852+
return (observationQueue.hasActiveBuckets() && !bypassObservationQueue && (watchersNestingLevel == 1))
861853
}
862854

863855
override fun beforeTextChanged(text: CharSequence, start: Int, count: Int, after: Int) {
@@ -910,13 +902,17 @@ class AztecText : AppCompatEditText, TextWatcher, UnknownHtmlSpan.OnUnknownHtmlT
910902
// Helper ======================================================================================
911903

912904
fun consumeCursorPosition(text: SpannableStringBuilder): Int {
913-
var cursorPosition = Math.min(selectionStart, length())
905+
var cursorPosition = Math.min(selectionStart, text.length)
914906

915907
text.getSpans(0, text.length, AztecCursorSpan::class.java).forEach {
916908
cursorPosition = text.getSpanStart(it)
917909
text.removeSpan(it)
918910
}
919911

912+
// Make sure the cursor position is a valid one
913+
cursorPosition = Math.min(cursorPosition, text.length)
914+
cursorPosition = Math.max(0, cursorPosition)
915+
920916
return cursorPosition
921917
}
922918

@@ -936,10 +932,12 @@ class AztecText : AppCompatEditText, TextWatcher, UnknownHtmlSpan.OnUnknownHtmlT
936932
it.textView = this
937933
}
938934

935+
val cursorPosition = consumeCursorPosition(builder)
936+
setSelection(0)
937+
939938
setTextKeepState(builder)
940939
enableTextChangedListener()
941940

942-
val cursorPosition = consumeCursorPosition(builder)
943941
setSelection(cursorPosition)
944942

945943
loadImages()
@@ -1259,7 +1257,7 @@ class AztecText : AppCompatEditText, TextWatcher, UnknownHtmlSpan.OnUnknownHtmlT
12591257
val clip = clipboard.primaryClip
12601258

12611259
if (clip != null) {
1262-
history.beforeTextChanged(toFormattedHtml())
1260+
history.beforeTextChanged(this@AztecText)
12631261

12641262
disableTextChangedListener()
12651263

@@ -1290,8 +1288,6 @@ class AztecText : AppCompatEditText, TextWatcher, UnknownHtmlSpan.OnUnknownHtmlT
12901288
val newHtml = oldHtml.replace(Constants.REPLACEMENT_MARKER_STRING, textToPaste + "<" + AztecCursorSpan.AZTEC_CURSOR_TAG + ">")
12911289

12921290
fromHtml(newHtml)
1293-
history.handleHistory(this@AztecText)
1294-
12951291
inlineFormatter.joinStyleSpans(0, length())
12961292
}
12971293
}
@@ -1311,15 +1307,14 @@ class AztecText : AppCompatEditText, TextWatcher, UnknownHtmlSpan.OnUnknownHtmlT
13111307
}
13121308

13131309
fun link(url: String, anchor: String) {
1314-
history.beforeTextChanged(toFormattedHtml())
1310+
history.beforeTextChanged(this@AztecText)
13151311
if (TextUtils.isEmpty(url) && linkFormatter.isUrlSelected()) {
13161312
removeLink()
13171313
} else if (linkFormatter.isUrlSelected()) {
13181314
linkFormatter.editLink(url, anchor, linkFormatter.getUrlSpanBounds().first, linkFormatter.getUrlSpanBounds().second)
13191315
} else {
13201316
linkFormatter.addLink(url, anchor, selectionStart, selectionEnd)
13211317
}
1322-
history.handleHistory(this)
13231318
}
13241319

13251320
fun removeLink() {

aztec/src/main/kotlin/org/wordpress/aztec/History.kt

Lines changed: 18 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ class History(val historyEnabled: Boolean, val historySize: Int) {
1919

2020
private val mainHandler = Handler(Looper.getMainLooper())
2121
private val historyRunnable: HistoryRunnable?
22-
private var inputLastTmp = ""
2322
private var textChangedPending = false
2423

2524
// Time in ms to wait before applying change history to the stack
@@ -33,21 +32,30 @@ class History(val historyEnabled: Boolean, val historySize: Int) {
3332
}
3433
}
3534

36-
fun beforeTextChanged(text: String) {
35+
fun beforeTextChanged(editText: EditText) {
3736
if (historyEnabled && !historyWorking) {
3837
mainHandler.removeCallbacks(historyRunnable)
3938
if (!textChangedPending) {
4039
textChangedPending = true
41-
historyRunnable?.text = text
40+
historyRunnable?.text =
41+
when (editText) {
42+
is AztecText -> editText.toFormattedHtml()
43+
is SourceViewEditText -> editText.text.toString()
44+
else -> ""
45+
}
46+
historyRunnable?.editText = editText
4247
}
4348
mainHandler.postDelayed(historyRunnable, historyThrottleTime)
4449
}
4550
}
4651

47-
protected fun doHandleHistory(inputBeforeTmp: String) {
52+
protected fun doHandleHistory(inputBefore: String, editText: EditText?) {
4853
textChangedPending = false
49-
inputBefore = inputBeforeTmp
50-
inputLast = inputLastTmp
54+
inputLast = when (editText) {
55+
is AztecText -> editText.toFormattedHtml()
56+
is SourceViewEditText -> editText.text.toString()
57+
else -> ""
58+
}
5159

5260
if (inputLast == inputBefore) {
5361
return
@@ -68,18 +76,6 @@ class History(val historyEnabled: Boolean, val historySize: Int) {
6876
updateActions()
6977
}
7078

71-
fun handleHistory(editText: EditText) {
72-
if (!historyEnabled || historyWorking) {
73-
return
74-
}
75-
76-
if (editText is AztecText) {
77-
inputLastTmp = editText.toFormattedHtml()
78-
} else if (editText is SourceViewEditText) {
79-
inputLastTmp = editText.text.toString()
80-
}
81-
}
82-
8379
/**
8480
* Useful for replacing the last history item after background
8581
* processing has completed. Example: uploading media.
@@ -89,11 +85,10 @@ class History(val historyEnabled: Boolean, val historySize: Int) {
8985
return
9086
}
9187
if (editText is AztecText) {
92-
inputLastTmp = editText.toFormattedHtml()
88+
inputLast = editText.toFormattedHtml()
9389
} else if (editText is SourceViewEditText) {
94-
inputLastTmp = editText.text.toString()
90+
inputLast = editText.text.toString()
9591
}
96-
inputLast = inputLastTmp
9792
}
9893

9994
fun redo(editText: EditText) {
@@ -197,9 +192,9 @@ class History(val historyEnabled: Boolean, val historySize: Int) {
197192
*/
198193
inner class HistoryRunnable(val history: History) : Runnable {
199194
var text: String = ""
200-
195+
var editText: EditText? = null
201196
override fun run() {
202-
history.doHandleHistory(text)
197+
history.doHandleHistory(text, editText)
203198
}
204199
}
205200
}

aztec/src/main/kotlin/org/wordpress/aztec/source/SourceViewEditText.kt

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ class SourceViewEditText : android.support.v7.widget.AppCompatEditText, TextWatc
124124

125125
override fun beforeTextChanged(text: CharSequence, start: Int, count: Int, after: Int) {
126126
if (!isTextChangedListenerDisabled()) {
127-
history?.beforeTextChanged(text.toString())
127+
history?.beforeTextChanged(this)
128128
}
129129

130130
styleTextWatcher?.beforeTextChanged(text, start, count, after)
@@ -139,8 +139,6 @@ class SourceViewEditText : android.support.v7.widget.AppCompatEditText, TextWatc
139139
enableTextChangedListener()
140140
return
141141
}
142-
143-
history?.handleHistory(this)
144142
styleTextWatcher?.afterTextChanged(text)
145143
}
146144

aztec/src/main/kotlin/org/wordpress/aztec/watchers/BlockElementWatcher.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ open class BlockElementWatcher(aztecText: AztecText) : TextWatcher {
3636
// save the text state before the funky business, then skip the history
3737
val aztecText = aztecTextRef.get()
3838
aztecText?.let {
39-
aztecText.history.beforeTextChanged(aztecText.toFormattedHtml())
39+
aztecText.history.beforeTextChanged(it)
4040
aztecText.consumeHistoryEvent = false
4141

4242
spans.forEach {

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,10 @@ class ObservationQueue(val injector: IEventInjector) : EventSequence<TextWatcher
1818
*/
1919
}
2020

21+
fun hasActiveBuckets() : Boolean {
22+
return buckets.size > 0
23+
}
24+
2125
override fun add(element: TextWatcherEvent): Boolean {
2226
synchronized(this@ObservationQueue) {
2327
val added: Boolean = super.add(element)

0 commit comments

Comments
 (0)