Skip to content

Commit 5a21fb5

Browse files
authored
Merge pull request #1111 from wordpress-mobile/dodroid-433-the-editor-fails-to-add-checklist-indentation
Fix lists indentation issues
2 parents 6bc0048 + ed286d7 commit 5a21fb5

File tree

5 files changed

+77
-4
lines changed

5 files changed

+77
-4
lines changed

app/src/main/kotlin/org/wordpress/aztec/demo/MainActivity.kt

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,8 @@ import org.wordpress.aztec.plugins.wpcomments.toolbar.PageToolbarButton
6666
import org.wordpress.aztec.source.SourceViewEditText
6767
import org.wordpress.aztec.toolbar.AztecToolbar
6868
import org.wordpress.aztec.toolbar.IAztecToolbarClickListener
69+
import org.wordpress.aztec.toolbar.ToolbarAction
70+
import org.wordpress.aztec.toolbar.ToolbarItems
6971
import org.wordpress.aztec.util.AztecLog
7072
import org.xml.sax.Attributes
7173
import java.io.File
@@ -459,6 +461,28 @@ open class MainActivity : AppCompatActivity(),
459461
}
460462
})
461463

464+
toolbar.enableTaskList()
465+
466+
toolbar.setToolbarItems(
467+
ToolbarItems.BasicLayout(
468+
ToolbarAction.HEADING,
469+
ToolbarAction.LIST,
470+
ToolbarAction.INDENT,
471+
ToolbarAction.OUTDENT,
472+
ToolbarAction.QUOTE,
473+
ToolbarAction.BOLD,
474+
ToolbarAction.ITALIC,
475+
ToolbarAction.LINK,
476+
ToolbarAction.UNDERLINE,
477+
ToolbarAction.STRIKETHROUGH,
478+
ToolbarAction.ALIGN_LEFT,
479+
ToolbarAction.ALIGN_CENTER,
480+
ToolbarAction.ALIGN_RIGHT,
481+
ToolbarAction.HORIZONTAL_RULE,
482+
ToolbarItems.PLUGINS,
483+
ToolbarAction.HTML
484+
))
485+
462486
aztec = Aztec.with(visualEditor, sourceEditor, toolbar, this)
463487
.setImageGetter(GlideImageLoader(this))
464488
.setVideoThumbnailGetter(GlideVideoThumbnailLoader(this))

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

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ import org.wordpress.aztec.spans.AztecListItemSpan
55
import org.wordpress.aztec.spans.AztecListSpan
66
import org.wordpress.aztec.spans.AztecOrderedListSpan
77
import org.wordpress.aztec.spans.AztecOrderedListSpanAligned
8+
import org.wordpress.aztec.spans.AztecTaskListSpan
9+
import org.wordpress.aztec.spans.AztecTaskListSpanAligned
810
import org.wordpress.aztec.spans.AztecUnorderedListSpan
911
import org.wordpress.aztec.spans.AztecUnorderedListSpanAligned
1012
import org.wordpress.aztec.spans.IAztecBlockSpan
@@ -96,6 +98,14 @@ class ListFormatter(editor: AztecText) : AztecFormatter(editor) {
9698
is AztecOrderedListSpan -> AztecOrderedListSpan(updatedNestingLevel, attributes, listStyle)
9799
is AztecUnorderedListSpanAligned -> AztecUnorderedListSpanAligned(updatedNestingLevel, attributes, listStyle, alignment)
98100
is AztecUnorderedListSpan -> AztecUnorderedListSpan(updatedNestingLevel, attributes, listStyle)
101+
is AztecTaskListSpanAligned -> {
102+
val context = getContext() ?: return null
103+
AztecTaskListSpanAligned(updatedNestingLevel, attributes, context, listStyle, alignment)
104+
}
105+
is AztecTaskListSpan -> {
106+
val context = getContext() ?: return null
107+
AztecTaskListSpan(updatedNestingLevel, attributes, context, listStyle)
108+
}
99109
else -> null
100110
}
101111
}

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

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,9 +38,23 @@ abstract class AztecListSpan(override var nestingLevel: Int,
3838
val listText = text.subSequence(spanStart, spanEnd) as Spanned
3939

4040
if (end - spanStart - 1 >= 0 && end - spanStart <= listText.length) {
41-
val hasSublist = listText.getSpans(end - spanStart - 1, end - spanStart, AztecListSpan::class.java)
42-
.any { it.nestingLevel > nestingLevel }
43-
if (hasSublist) {
41+
// When outdenting an empty list item, a nested list span may begin at the
42+
// exact start of this line due to span boundary updates. That should not
43+
// suppress the indicator for the current line. Ignore sublists whose start
44+
// coincides with the current line start.
45+
val potentialSublists = listText.getSpans(end - spanStart - 1, end - spanStart, AztecListSpan::class.java)
46+
val hasBlockingSublist = potentialSublists.any { sub ->
47+
if (sub.nestingLevel <= nestingLevel) return@any false
48+
val subStart = listText.getSpanStart(sub)
49+
val lineStart = (listText.subSequence(0, end - spanStart) as Spanned)
50+
.lastIndexOf('\n') + 1
51+
// Only treat as blocking if the nested list actually starts after the line start
52+
// (i.e., the next line belongs to a deeper list). If it starts exactly at the
53+
// line start, we are at the first character of that nested block, which should
54+
// still show the current line indicator.
55+
subStart > lineStart
56+
}
57+
if (hasBlockingSublist) {
4458
return null
4559
}
4660
}

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,8 @@ open class AztecTaskListSpan(
6868
) : AztecListSpan(nestingLevel, listStyle.verticalPadding) {
6969
private var toggled: Boolean = false
7070
private var contextRef: WeakReference<Context> = WeakReference(context)
71+
72+
internal fun getContext(): Context? = contextRef.get()
7173
override val TAG = "ul"
7274

7375
override val startTag: String

build.gradle

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@ allprojects {
3030
}
3131
tasks.withType(KotlinCompile).all {
3232
kotlinOptions {
33-
jvmTarget = JavaVersion.VERSION_1_8
3433
allWarningsAsErrors = true
3534
}
3635
}
@@ -43,6 +42,30 @@ task clean(type: Delete) {
4342
}
4443

4544
subprojects {
45+
plugins.withId("com.android.application") {
46+
android {
47+
compileOptions {
48+
sourceCompatibility JavaVersion.VERSION_1_8
49+
targetCompatibility JavaVersion.VERSION_1_8
50+
}
51+
}
52+
}
53+
plugins.withId("com.android.library") {
54+
android {
55+
compileOptions {
56+
sourceCompatibility JavaVersion.VERSION_1_8
57+
targetCompatibility JavaVersion.VERSION_1_8
58+
}
59+
}
60+
}
61+
plugins.withId("org.jetbrains.kotlin.android") {
62+
tasks.withType(KotlinCompile).configureEach {
63+
kotlinOptions {
64+
jvmTarget = "1.8"
65+
}
66+
}
67+
}
68+
4669
configurations {
4770
ktlint
4871
}

0 commit comments

Comments
 (0)