Skip to content

Commit 23bd4f2

Browse files
authored
Merge pull request #628 from wordpress-mobile/issue/527-quote-issues
Issue/527 quote issues
2 parents 7d1a5a4 + eca3e0a commit 23bd4f2

File tree

26 files changed

+624
-133
lines changed

26 files changed

+624
-133
lines changed

app/src/androidTest/kotlin/org/wordpress/aztec/demo/tests/MixedTextFormattingTests.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,7 @@ class MixedTextFormattingTests : BaseTest() {
176176
@Test
177177
fun testRemoveQuoteFormatting() {
178178
val text = "some text"
179-
val html = "<blockquote>$text</blockquote>\n$text"
179+
val html = "$text\n<br>\n$text"
180180

181181
EditorPage()
182182
.toggleQuote()

app/src/main/AndroidManifest.xml

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -27,12 +27,6 @@
2727

2828
</activity>
2929

30-
<activity
31-
android:name=".NonCalypsoActivity"
32-
android:windowSoftInputMode="adjustResize|stateHidden"
33-
android:theme="@style/MainActivityTheme" >
34-
</activity>
35-
3630
<!-- Provider for exposing file URIs on Android 7+ -->
3731
<provider
3832
android:name="android.support.v4.content.FileProvider"

aztec/src/main/java/org/wordpress/aztec/Html.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,9 @@
3333

3434
import org.ccil.cowan.tagsoup.HTMLSchema;
3535
import org.ccil.cowan.tagsoup.Parser;
36-
import org.wordpress.aztec.plugins.html2visual.IHtmlContentHandler;
3736
import org.wordpress.aztec.plugins.IAztecPlugin;
3837
import org.wordpress.aztec.plugins.html2visual.IHtmlCommentHandler;
38+
import org.wordpress.aztec.plugins.html2visual.IHtmlContentHandler;
3939
import org.wordpress.aztec.plugins.html2visual.IHtmlPreprocessor;
4040
import org.wordpress.aztec.plugins.html2visual.IHtmlTextHandler;
4141
import org.wordpress.aztec.spans.AztecCodeSpan;
@@ -52,7 +52,6 @@
5252
import org.wordpress.aztec.spans.AztecUnderlineSpan;
5353
import org.wordpress.aztec.spans.CommentSpan;
5454
import org.wordpress.aztec.spans.FontSpan;
55-
import org.wordpress.aztec.spans.IAztecBlockSpan;
5655
import org.wordpress.aztec.spans.IAztecInlineSpan;
5756
import org.wordpress.aztec.spans.IAztecParagraphStyle;
5857
import org.wordpress.aztec.spans.UnknownClickableSpan;

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

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,11 @@ class AztecParser(val plugins: List<IAztecPlugin> = ArrayList()) {
133133
val parent = IAztecNestable.getParent(spanned, SpanWrapper(spanned, it))
134134

135135
// a list item "repels" a child list so the list will appear in the next line
136-
val repelling = it is AztecListSpan && parent?.span is AztecListItemSpan
136+
val parentListItem = spanned.getSpans(spanned.getSpanStart(it), spanned.getSpanEnd(it), AztecListItemSpan::class.java)
137+
.filter { item -> item.nestingLevel < it.nestingLevel }
138+
.sortedBy { item -> item.nestingLevel }
139+
.firstOrNull()
140+
val repelling = it is AztecListSpan && parentListItem != null
137141

138142
val spanStart = spanned.getSpanStart(it)
139143
val spanEnd = spanned.getSpanEnd(it)
@@ -160,6 +164,10 @@ class AztecParser(val plugins: List<IAztecPlugin> = ArrayList()) {
160164
return@forEach
161165
}
162166

167+
if (repelling && spanStart > 0 && spanned[spanStart - 1] == '\n' && spanStart - 1 >= spanned.getSpanStart(parentListItem)) {
168+
return@forEach
169+
}
170+
163171
// well, it seems we need a visual newline so, add one and mark it as such
164172
spanned.insert(spanStart, "\n")
165173

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

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,6 @@ import org.xml.sax.Attributes
5050
import java.util.ArrayList
5151

5252
class AztecTagHandler(val context: Context, val plugins: List<IAztecPlugin> = ArrayList()) : Html.TagHandler {
53-
private var order = 0
54-
5553
private val loadingDrawable: Drawable
5654

5755
init {

aztec/src/main/kotlin/org/wordpress/aztec/formatting/BlockFormatter.kt

Lines changed: 210 additions & 66 deletions
Large diffs are not rendered by default.

aztec/src/main/kotlin/org/wordpress/aztec/handlers/BlockHandler.kt

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,11 @@ abstract class BlockHandler<SpanType : IAztecBlockSpan>(val clazz: Class<SpanTyp
2424
var newlineIndex: Int = -1
2525
var nestingLevel = 0
2626
var markerIndex: Int = -1
27+
var isReplay = false
2728

28-
override fun handleTextChanged(text: Spannable, inputStart: Int, count: Int, nestingLevel: Int) {
29+
override fun handleTextChanged(text: Spannable, inputStart: Int, count: Int, nestingLevel: Int, isReplay: Boolean) {
2930
this.text = text
30-
31+
this.isReplay = isReplay
3132
this.nestingLevel = nestingLevel
3233

3334
// use charsNew to get the spans at the input point. It appears to be more reliable vs the whole Editable.
@@ -92,9 +93,10 @@ abstract class BlockHandler<SpanType : IAztecBlockSpan>(val clazz: Class<SpanTyp
9293
}
9394

9495
// prev newline needs to be at the same nesting level to account for "double-enter"
96+
val prevNewlineNesting = IAztecNestable.getNestingLevelAt(text, newlineIndex - 1, newlineIndex)
97+
val currentNewlineNesting = IAztecNestable.getNestingLevelAt(text, newlineIndex, newlineIndex + 1)
9598
if (text[newlineIndex - 1] == Constants.NEWLINE
96-
&& IAztecNestable.getNestingLevelAt(text, newlineIndex - 1, newlineIndex) ==
97-
IAztecNestable.getNestingLevelAt(text, newlineIndex, newlineIndex + 1)
99+
&& (prevNewlineNesting == currentNewlineNesting || prevNewlineNesting > currentNewlineNesting && !isReplay)
98100
&& atEndOfBlock) {
99101
return PositionType.EMPTY_LINE_AT_BLOCK_END
100102
}

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

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,8 +52,7 @@ object Format {
5252
if (isCalypsoFormat) {
5353
val htmlWithoutSourceFormatting = toCalypsoHtml(html)
5454
val doc = Jsoup.parseBodyFragment(htmlWithoutSourceFormatting.replace("\n", "")).outputSettings(Document.OutputSettings().prettyPrint(false))
55-
val modified = doc.body().html()
56-
return modified
55+
return doc.body().html()
5756
} else {
5857
return replaceAll(html, "\\s*<(/?($block)(.*?))>\\s*", "<$1>")
5958
}

aztec/src/main/kotlin/org/wordpress/aztec/spans/AztecHeadingSpan.kt

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,15 +18,14 @@ class AztecHeadingSpan @JvmOverloads constructor(
1818
override var attributes: AztecAttributes,
1919
var headerStyle: BlockFormatter.HeaderStyle = BlockFormatter.HeaderStyle(0),
2020
override var align: Layout.Alignment? = null
21-
) : MetricAffectingSpan(), IAztecBlockSpan, LineHeightSpan, UpdateLayout {
21+
) : MetricAffectingSpan(), IAztecLineBlockSpan, LineHeightSpan, UpdateLayout {
2222
override val TAG: String
2323
get() = heading.tag
2424

2525
override var endBeforeBleed: Int = -1
2626
override var startBeforeCollapse: Int = -1
2727

2828
var textFormat: ITextFormat = AztecTextFormat.FORMAT_HEADING_1
29-
get() = field
3029
set(value) {
3130
field = value
3231
heading = textFormatToHeading(value)

aztec/src/main/kotlin/org/wordpress/aztec/spans/AztecListItemSpan.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import org.wordpress.aztec.AztecAttributes
55

66
class AztecListItemSpan(override var nestingLevel: Int,
77
override var attributes: AztecAttributes = AztecAttributes(),
8-
override var align: Layout.Alignment? = null) : IAztecBlockSpan {
8+
override var align: Layout.Alignment? = null) : IAztecCompositeBlockSpan {
99
override val TAG = "li"
1010

1111
override var endBeforeBleed: Int = -1

0 commit comments

Comments
 (0)