-
Notifications
You must be signed in to change notification settings - Fork 121
Update Heading, Preformat, and HiddenHtml Spans to allow view-level alignment #899
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 1 commit
06cc656
3376a83
0d95d65
f5ab51e
667a448
b996947
d697b0b
d2d8a5d
7701b32
88589b6
2cad3ce
1238849
3875c09
bff8cac
ea627b6
49237c7
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
- Loading branch information
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -29,8 +29,11 @@ import org.wordpress.aztec.spans.IAztecNestable | |
| import org.wordpress.aztec.spans.ParagraphSpan | ||
| import org.wordpress.aztec.spans.createAztecQuoteSpan | ||
| import org.wordpress.aztec.spans.createHeadingSpan | ||
| import org.wordpress.aztec.spans.createListItemSpan | ||
| import org.wordpress.aztec.spans.createOrderedListSpan | ||
| import org.wordpress.aztec.spans.createParagraphSpan | ||
| import org.wordpress.aztec.spans.createPreformatSpan | ||
| import org.wordpress.aztec.spans.createUnorderedListSpan | ||
| import org.wordpress.aztec.util.SpanWrapper | ||
| import java.util.Arrays | ||
| import kotlin.reflect.KClass | ||
|
|
@@ -251,7 +254,7 @@ class BlockFormatter(editor: AztecText, | |
| // when removing style from multiple selected lines, if the last selected line is empty | ||
| // or at the end of editor the selection wont include the trailing newline/EOB marker | ||
| // that will leave us with orphan <li> tag, so we need to shift index to the right | ||
| val hasLingeringEmptyListItem = spanType.isAssignableFrom(AztecListItemSpan::class.java) | ||
| val hasLingeringEmptyListItem = AztecListItemSpan::class.java.isAssignableFrom(spanType) | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is a change to the logic, but I think it was incorrect before because a |
||
| && editableText.length > end | ||
| && (editableText[end] == '\n' || editableText[end] == Constants.END_OF_BUFFER_MARKER) | ||
|
|
||
|
|
@@ -294,8 +297,8 @@ class BlockFormatter(editor: AztecText, | |
| // TODO: Come up with a better way to init spans and get their classes (all the "make" methods) | ||
| fun makeBlock(textFormat: ITextFormat, nestingLevel: Int, attrs: AztecAttributes = AztecAttributes()): List<IAztecBlockSpan> { | ||
| when (textFormat) { | ||
| AztecTextFormat.FORMAT_ORDERED_LIST -> return Arrays.asList(AztecOrderedListSpan(nestingLevel, attrs, listStyle), AztecListItemSpan(nestingLevel + 1)) | ||
| AztecTextFormat.FORMAT_UNORDERED_LIST -> return Arrays.asList(AztecUnorderedListSpan(nestingLevel, attrs, listStyle), AztecListItemSpan(nestingLevel + 1)) | ||
| AztecTextFormat.FORMAT_ORDERED_LIST -> return Arrays.asList(createOrderedListSpan(nestingLevel, alignmentApproach, attrs, listStyle), createListItemSpan(nestingLevel + 1, alignmentApproach)) | ||
| AztecTextFormat.FORMAT_UNORDERED_LIST -> return Arrays.asList(createUnorderedListSpan(nestingLevel, alignmentApproach, attrs, listStyle), createListItemSpan(nestingLevel + 1, alignmentApproach)) | ||
| AztecTextFormat.FORMAT_QUOTE -> return Arrays.asList(createAztecQuoteSpan(nestingLevel, attrs, alignmentApproach, quoteStyle)) | ||
| AztecTextFormat.FORMAT_HEADING_1, | ||
| AztecTextFormat.FORMAT_HEADING_2, | ||
|
|
@@ -339,9 +342,9 @@ class BlockFormatter(editor: AztecText, | |
| private fun <T : KClass<out IAztecBlockSpan>> makeBlockSpan(type: T, textFormat: ITextFormat, nestingLevel: Int, attrs: AztecAttributes = AztecAttributes()): IAztecBlockSpan { | ||
| val typeIsAssignableTo = { clazz: KClass<out Any> -> clazz.java.isAssignableFrom(type.java) } | ||
| return when { | ||
| typeIsAssignableTo(AztecOrderedListSpan::class) -> AztecOrderedListSpan(nestingLevel, attrs, listStyle) | ||
| typeIsAssignableTo(AztecUnorderedListSpan::class) -> AztecUnorderedListSpan(nestingLevel, attrs, listStyle) | ||
| typeIsAssignableTo(AztecListItemSpan::class) -> AztecListItemSpan(nestingLevel, attrs) | ||
| typeIsAssignableTo(AztecOrderedListSpan::class) -> createOrderedListSpan(nestingLevel, alignmentApproach, attrs, listStyle) | ||
| typeIsAssignableTo(AztecUnorderedListSpan::class) -> createUnorderedListSpan(nestingLevel, alignmentApproach, attrs, listStyle) | ||
| typeIsAssignableTo(AztecListItemSpan::class) -> createListItemSpan(nestingLevel, alignmentApproach, attrs) | ||
| typeIsAssignableTo(AztecQuoteSpan::class) -> createAztecQuoteSpan(nestingLevel, attrs, alignmentApproach, quoteStyle) | ||
| typeIsAssignableTo(AztecHeadingSpan::class) -> createHeadingSpan(nestingLevel, textFormat, attrs, alignmentApproach, headerStyle) | ||
| typeIsAssignableTo(AztecPreformatSpan::class) -> createPreformatSpan(nestingLevel, alignmentApproach, attrs, preformatStyle) | ||
|
|
@@ -651,7 +654,7 @@ class BlockFormatter(editor: AztecText, | |
| BlockHandler.set(editableText, listSpan, start, end) | ||
| // special case for styling single empty lines | ||
| if (end - start == 1 && (editableText[end - 1] == '\n' || editableText[end - 1] == Constants.END_OF_BUFFER_MARKER)) { | ||
| ListItemHandler.newListItem(editableText, start, end, listSpan.nestingLevel + 1) | ||
| ListItemHandler.newListItem(editableText, start, end, listSpan.nestingLevel + 1, alignmentApproach) | ||
| } else { | ||
| val listEnd = if (end == editableText.length) end else end - 1 | ||
| val listContent = editableText.substring(start, listEnd) | ||
|
|
@@ -666,7 +669,12 @@ class BlockFormatter(editor: AztecText, | |
| if ((start + it) != editableText.length) it + 1 else it // include the newline or not | ||
| } | ||
|
|
||
| ListItemHandler.newListItem(editableText, start + lineStart, start + lineEnd, listSpan.nestingLevel + 1) | ||
| ListItemHandler.newListItem( | ||
| editableText, | ||
| start + lineStart, | ||
| start + lineEnd, | ||
| listSpan.nestingLevel + 1, | ||
| alignmentApproach) | ||
| } | ||
| } | ||
| } | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,14 +1,36 @@ | ||
| package org.wordpress.aztec.spans | ||
|
|
||
| import android.text.Layout | ||
| import org.wordpress.aztec.AlignmentApproach | ||
| import org.wordpress.aztec.AztecAttributes | ||
|
|
||
| class AztecListItemSpan(override var nestingLevel: Int, | ||
| override var attributes: AztecAttributes = AztecAttributes(), | ||
| override var align: Layout.Alignment? = null | ||
| ) : IAztecAlignmentSpan, IAztecCompositeBlockSpan { | ||
| fun createListItemSpan(nestingLevel: Int, | ||
| alignmentApproach: AlignmentApproach, | ||
| attributes: AztecAttributes = AztecAttributes()) : IAztecBlockSpan = | ||
| when (alignmentApproach) { | ||
| AlignmentApproach.SPAN_LEVEL -> AztecListItemSpanAligned(nestingLevel, attributes, null) | ||
| AlignmentApproach.VIEW_LEVEL -> AztecListItemSpan(nestingLevel, attributes) | ||
| } | ||
|
|
||
| /** | ||
| * We need to have two classes for handling alignment at either the Span-level (ListItemSpanAligned) | ||
| * or the View-level (ListItemSpan). IAztecAlignment implements AlignmentSpan, which has a | ||
| * getAlignment method that returns a non-null Layout.Alignment. The Android system checks for | ||
| * AlignmentSpans and, if present, overrides the view's gravity with their value. Having a class | ||
| * that does not implement AlignmentSpan allows the view's gravity to control. These classes should | ||
| * be created using the createListItemSpan(...) methods. | ||
| */ | ||
| open class AztecListItemSpan( | ||
| override var nestingLevel: Int, | ||
| override var attributes: AztecAttributes) : IAztecCompositeBlockSpan { | ||
| override val TAG = "li" | ||
|
|
||
| override var endBeforeBleed: Int = -1 | ||
| override var startBeforeCollapse: Int = -1 | ||
| } | ||
|
|
||
| class AztecListItemSpanAligned( | ||
| nestingLevel: Int, | ||
| attributes: AztecAttributes, | ||
| override var align: Layout.Alignment? | ||
| ) : AztecListItemSpan(nestingLevel, attributes), IAztecAlignmentSpan |
Uh oh!
There was an error while loading. Please reload this page.