Skip to content

Commit d82694f

Browse files
committed
changed method isUserOperationPartiallyObservedInSequence to be implemented directly by superclass UserOperationEvent as realised implementation is the same across sequence models
1 parent de8f125 commit d82694f

File tree

3 files changed

+31
-63
lines changed

3 files changed

+31
-63
lines changed

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

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,38 @@ abstract class UserOperationEvent(var sequence: EventSequence<TextWatcherEvent>
1212
sequence.clear()
1313
}
1414

15+
fun isUserOperationPartiallyObservedInSequence(sequence: EventSequence<TextWatcherEvent>): Boolean {
16+
for (i in sequence.indices) {
17+
18+
val eventHolder = this.sequence[i]
19+
val observableEvent = sequence[i]
20+
21+
// if time distance between any of the events is longer than 50 millis, discard this as this pattern is
22+
// likely not produced by the platform, but rather the user.
23+
// WARNING! When debugging with breakpoints, you should disable this check as time can exceed the 50 MS limit and
24+
// create undesired behavior.
25+
if (i > 0) { // only try to compare when we have at least 2 events, so we can compare with the previous one
26+
val timestampForPreviousEvent = sequence[i - 1].timestamp
27+
val timeDistance = observableEvent.timestamp - timestampForPreviousEvent
28+
if (timeDistance > ObservationQueue.MAXIMUM_TIME_BETWEEN_EVENTS_IN_PATTERN_MS) {
29+
return false
30+
}
31+
}
32+
33+
eventHolder.beforeEventData = observableEvent.beforeEventData
34+
eventHolder.onEventData = observableEvent.onEventData
35+
eventHolder.afterEventData = observableEvent.afterEventData
36+
37+
// return immediately as soon as we realize the pattern diverges
38+
if (!eventHolder.testFitsBeforeOnAndAfter()) {
39+
return false
40+
}
41+
}
42+
43+
return true
44+
}
45+
1546
abstract fun isUserOperationObservedInSequence(sequence: EventSequence<TextWatcherEvent>) : Boolean
16-
abstract fun isUserOperationPartiallyObservedInSequence(sequence: EventSequence<TextWatcherEvent>) : Boolean
1747
abstract fun buildReplacementEventWithSequenceData(sequence: EventSequence<TextWatcherEvent>) : TextWatcherEvent
1848
}
1949

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

Lines changed: 0 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -77,37 +77,6 @@ class API26InWordSpaceInsertionEvent : UserOperationEvent() {
7777
return false
7878
}
7979

80-
override fun isUserOperationPartiallyObservedInSequence(sequence: EventSequence<TextWatcherEvent>): Boolean {
81-
for (i in sequence.indices) {
82-
83-
val eventHolder = this.sequence[i]
84-
val observableEvent = sequence[i]
85-
86-
// if time distance between any of the events is longer than 50 millis, discard this as this pattern is
87-
// likely not produced by the platform, but rather the user.
88-
// WARNING! When debugging with breakpoints, you should disable this check as time can exceed the 50 MS limit and
89-
// create undesired behavior.
90-
if (i > 0) { // only try to compare when we have at least 2 events, so we can compare with the previous one
91-
val timestampForPreviousEvent = sequence[i - 1].timestamp
92-
val timeDistance = observableEvent.timestamp - timestampForPreviousEvent
93-
if (timeDistance > ObservationQueue.MAXIMUM_TIME_BETWEEN_EVENTS_IN_PATTERN_MS) {
94-
return false
95-
}
96-
}
97-
98-
eventHolder.beforeEventData = observableEvent.beforeEventData
99-
eventHolder.onEventData = observableEvent.onEventData
100-
eventHolder.afterEventData = observableEvent.afterEventData
101-
102-
// return immediately as soon as we realize the pattern diverges
103-
if (!eventHolder.testFitsBeforeOnAndAfter()) {
104-
return false
105-
}
106-
}
107-
108-
return true
109-
}
110-
11180
override fun buildReplacementEventWithSequenceData(sequence: EventSequence<TextWatcherEvent>): TextWatcherEvent {
11281
val builder = TextWatcherEventInsertText.Builder()
11382
// here make it all up as a unique event that does the insert as usual, as we'd get it on older APIs

aztec/src/main/kotlin/org/wordpress/aztec/watchers/event/sequence/known/space/API26PrependNewLineOnStyledTextEvent.kt

Lines changed: 0 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -72,37 +72,6 @@ class API26PrependNewLineOnStyledTextEvent : UserOperationEvent() {
7272
return false
7373
}
7474

75-
override fun isUserOperationPartiallyObservedInSequence(sequence: EventSequence<TextWatcherEvent>): Boolean {
76-
for (i in sequence.indices) {
77-
78-
val eventHolder = this.sequence[i]
79-
val observableEvent = sequence[i]
80-
81-
// if time distance between any of the events is longer than 50 millis, discard this as this pattern is
82-
// likely not produced by the platform, but rather the user.
83-
// WARNING! When debugging with breakpoints, you should disable this check as time can exceed the 50 MS limit and
84-
// create undesired behavior.
85-
if (i > 0) { // only try to compare when we have at least 2 events, so we can compare with the previous one
86-
val timestampForPreviousEvent = sequence[i - 1].timestamp
87-
val timeDistance = observableEvent.timestamp - timestampForPreviousEvent
88-
if (timeDistance > ObservationQueue.MAXIMUM_TIME_BETWEEN_EVENTS_IN_PATTERN_MS) {
89-
return false
90-
}
91-
}
92-
93-
eventHolder.beforeEventData = observableEvent.beforeEventData
94-
eventHolder.onEventData = observableEvent.onEventData
95-
eventHolder.afterEventData = observableEvent.afterEventData
96-
97-
// return immediately as soon as we realize the pattern diverges
98-
if (!eventHolder.testFitsBeforeOnAndAfter()) {
99-
return false
100-
}
101-
}
102-
103-
return true
104-
}
105-
10675
override fun buildReplacementEventWithSequenceData(sequence: EventSequence<TextWatcherEvent>): TextWatcherEvent {
10776
val builder = TextWatcherEventInsertText.Builder()
10877
// here make it all up as a unique event that does the insert as usual, as we'd get it on older APIs

0 commit comments

Comments
 (0)