-
Notifications
You must be signed in to change notification settings - Fork 116
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
Update Heading, Preformat, and HiddenHtml Spans to allow view-level alignment #899
Conversation
Working great for me in the wordpress-mobile/gutenberg-mobile#1990 PR. |
A general question to see if I understand the "view level" alignment correctly @mchowning, does that mean that when using |
cb03932
to
707699c
Compare
You're understanding it exactly right @hypest , an
Obviously this could change, but as the blocks are currently defined it is not possible to have more than a single alignment attribute in the blocks I have seen. Even if a single block did have multiple alignments in it though, we could still use If the parts of the block with different alignments were in a single Aztec view, we would have to use I wouldn't be surprised if there were quite a few bugs we would need to fix to use |
It's not clear to me what should happen if we set the alignment mode to "view level" but the html fed to Aztec still has alignment attributes. Would that be a supported combination? Can we add a test or two to capture those cases and show what the expected outcome is? |
I'm still confused about the whole situation with the alignment, and left a comment on the original PR regarding the overriding of the view gravity. |
We had a chat over Zoom and decided to:
|
Just tested with Pullquote block PR, works great 🎉 |
Tested on Verse block, works like a charm 🎉. |
61402e5
to
40c1c2b
Compare
👋 @hypest ! I think this is ready for another review. Note that with the changes to gutenberg-mobile since I originally opened this PR, it is now much easier to test this in Gutenberg using wordpress-mobile/gutenberg-mobile#2006 than it was when I originally opened this PR (no more using different branches to test different blocks).
I have added this handling for all Spans that both (1) extend
I was not able to come up with a solution I liked for this. Assuming we do not set the Happy to try out any ideas you might have though. We could address this with Dagger, but that feels extremely excessive to me.
I parameterized the I realize this isn't exactly what you had in mind, but I thought it was a nice way to get some pretty robust coverage of the |
val typeIsAssignableTo = { clazz: KClass<out Any> -> clazz.java.isAssignableFrom(type.java) } | ||
return when { | ||
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) | ||
else -> createParagraphSpan(nestingLevel, alignmentApproach, attrs) | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Heads up that this is a small change to the logic so that it accommodates subclasses (i.e., AztecOrderedListSpanAligned
should match AztecOrderedListSpan
).
@@ -240,7 +254,7 @@ class BlockFormatter(editor: AztecText, val listStyle: ListStyle, val quoteStyle | |||
// 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) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The 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 spanType
of, for example Object
would have returned true
before since an AztecListItemSpan
can be assigned to an Object
. With my change, we are instead checking that it is either an AztecListItemSpan
or a subclass.
Not a block-element but, should the
Fair. I have nothing concrete on my mind to try. I think we can go ahead with what is implemented and iterate if/when we run across a promising concrete idea for how to simplify.
Good one! I'd be surprised if the current tests fail actually. What I had in mind regarding tests was whether we can introduce a test the resulting html in the case where the input html has alignments in certain words but the global setting is VIEW_BASED. For example, if we feed the following html to a VIEW_BASED Aztec instance, what will be the output html?
When the setting is SPAN_LEVEL, I'd expect the output to be identical to the input, but for VIEW_BASED, shouldn't the individual alignments be lost? |
2a4406d
to
cc8c9e8
Compare
I was wondering why the tests (279cfeb) would succeed, and tried out a manual test: I changed the default alignment approach to Was that manual test invalid perhaps Matt? WDYT? |
I went ahead and gave
Added some tests that verify that the html makes the FWIW, It appears that the html is still output with the appropriate alignment regardless of the alignment approach because the alignment is saved as part of the span's
Good point, the For these reasons, I think it's better to just disable updating alignment through Exploring this has given me a feel for how we can better handle this through our css parsing capabilities (and why that is preferable). |
Yeap, that's why my investigation led me too, noticed that we do check sometime if the span is a I felt that the combination of
Yeah, I guess we are closing in on the "same page" at this point. That would be quite a different solution than this PR's though, right? I think what could be more workable at this stage, and to unblock the Gutenberg side work that needs this PR, is to go with the current implementation and perhaps only rename the
Good one! |
Needed for the block editor
We have not implemented proper handling for using toggleFormat with VIEW_LEVEL alignment, so instead of having it half-work (updating the visual appearance of the text but not updating the html), just disabling it entirely.
0b93da0
to
ea627b6
Compare
Yes, very different. I think it is better to just proceed with this approach at this time because it's done, working, and consistent with what iOS is doing. I do think it's worthwhile trying to find a way to switch to css sooner rather than later, but I'm not sure how soon we'll have the time for that. I will try to do some work on it soon.
I like that idea! Made the change. |
CHANGELOG.md
Outdated
@@ -1,5 +1,9 @@ | |||
# Changelog | |||
|
|||
## [1.3.42](https://github.com/wordpress-mobile/AztecEditor-Android/releases/tag/v1.3.42) | |||
### Changed | |||
- Update Heading, Preformat, and HiddenHtml span classes to allow view level alignment (#899) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Now that a lot more spans have received the two-classes treatment, maybe we need to mention them here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM code-wise! I think we can have this implementation in before we can come up with another.
Description
These changes enable view-level (i.e., gravity) alignment within Aztec. I discuss the reasons this is needed in the description to my earlier PR making this change for the
ParagraphSpan
. In order to understand the changes in this PR, you probably should read that description first.This PR builds upon the changes in the first PR to have an explicit parameter (
AlignmentApproach
) that determines whether span-based or view-based alignment is used. The value of that parameter is determined insideAztecText
based on whether the viewisInGutenbergMode
so that it will be span-based for Aztec, and view-based for gutenberg.This PR updates the following span classes to enable view-level alignment
AztecHeadingSpan
,HiddenHtmlBlockSpan
, andAztecPreformatSpan
. This will allow us to enable alignment for (at least) the Heading, Quote, Pullquote, and Verse blocks on Gutenberg.There are quite a few changes in this PR, but most of them are simple updates to argument parameters and renamings. I have made an effort to break the changes up into logical commits, so it may be easier to review this by looking at the commits individually.
Related gutenberg-mobile PR: wordpress-mobile/gutenberg-mobile#2006
Testing
Alignment works in Gutenberg Mobile
This can be tested via the related gutenberg-mobile PR, which includes testing instructions in the description.
Aztec regressions
My changes should not cause any behavior changes in the Aztec editor, but we need to do some testing to verify this.
Make sure strings will be translated
strings.xml
as a part of the integration PR.