Skip to content
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

Plain text editor implementation based on markdown input #2840

Merged
merged 21 commits into from
May 21, 2024

Conversation

jmartinesp
Copy link
Contributor

@jmartinesp jmartinesp commented May 14, 2024

Type of change

  • Feature
  • Bugfix
  • Technical
  • Other :

Content

  • Added MarkdownTextInput, a TextInput counterpart that uses a simple EditText under the hood, instead of the RTE library. This will be the default editor unless the user explicitly enables rich text formatting.
  • Added MarkdownTextEditorState to act as a way to interact with the EditText from Compose code.
  • Wrapped both RichTextEditorState and MarkdownTextEditorState into a TextEditorState sealed interface with some helper functions.
  • Moved the parsing of the current editor state to send a message to MessageComposerPresenter from the View, as well as adding mention spans to the plain text editor. Sadly, this means having to add a MentionSpanProvider to presenter, which makes it more difficult to test. I also had to add isTesting and showFormatting properties to the presenter so it can be easily tested. I'll probably iterate on this later.
  • Removed the 'enable rich text editor' option from advanced settings, replaced it with a build config option in MessageComposerConfig in the appconfig module.

Known issues:

  • Mentions can't be converted from/to plain text and rich text yet. I'll handle this in another PR.
  • We probably want to keep track of whether the text formatting mode was last enabled so we can restore the text editor with that same value when navigating from one room to the other. This will also be handled in another PR.

Needs matrix-org/matrix-rich-text-editor#978.

Motivation and context

The RTE library has been problematic for some users, most of which didn't want to use rich text at all, so enabling

Screenshots / GIFs

I made the 2 editors look exactly the same, even replaced the editor used in some previews and the golden screenshots didn't change.

Tests

Thoroughly test the plain text editor and enabling / disabling text formatting, editing messages, replying to messages, etc.

Tested devices

  • Physical
  • Emulator
  • OS version(s): 14

Checklist

Copy link
Contributor

github-actions bot commented May 14, 2024

📱 Scan the QR code below to install the build (arm64 only) for this PR.
QR code
If you can't scan the QR code you can install the build via this link: https://i.diawi.com/3dEnhM

@jmartinesp jmartinesp added Record-Screenshots Runs the 'Record Screenshots' CI job and adds a commit with any new screenshots found. labels May 14, 2024
@github-actions github-actions bot removed Record-Screenshots Runs the 'Record Screenshots' CI job and adds a commit with any new screenshots found. labels May 14, 2024
Copy link

codecov bot commented May 14, 2024

Codecov Report

Attention: Patch coverage is 82.59861% with 75 lines in your changes are missing coverage. Please review.

Project coverage is 74.34%. Comparing base (cddb02f) to head (ca4691e).

Files Patch % Lines
...ent/android/libraries/textcomposer/TextComposer.kt 77.33% 3 Missing and 14 partials ⚠️
...tcomposer/components/markdown/MarkdownTextInput.kt 74.24% 1 Missing and 16 partials ⚠️
...ries/textcomposer/model/MarkdownTextEditorState.kt 82.69% 2 Missing and 7 partials ⚠️
...s/impl/messagecomposer/MessageComposerPresenter.kt 82.50% 4 Missing and 3 partials ⚠️
...android/libraries/textcomposer/ComposerModeView.kt 92.63% 2 Missing and 5 partials ⚠️
...id/libraries/textcomposer/model/TextEditorState.kt 75.00% 0 Missing and 6 partials ⚠️
...oid/libraries/textcomposer/mentions/MentionSpan.kt 66.66% 0 Missing and 3 partials ⚠️
...aries/textcomposer/mentions/MentionSpanProvider.kt 81.25% 2 Missing and 1 partial ⚠️
...composer/components/markdown/StableCharSequence.kt 77.77% 2 Missing ⚠️
...ages/impl/mentions/MentionSuggestionsPickerView.kt 87.50% 0 Missing and 1 partial ⚠️
... and 3 more
Additional details and impacted files
@@             Coverage Diff             @@
##           develop    #2840      +/-   ##
===========================================
+ Coverage    74.30%   74.34%   +0.03%     
===========================================
  Files         1530     1536       +6     
  Lines        36526    36734     +208     
  Branches      7055     7123      +68     
===========================================
+ Hits         27142    27309     +167     
- Misses        5698     5700       +2     
- Partials      3686     3725      +39     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@jmartinesp jmartinesp force-pushed the misc/jme/plain-text-editor branch 2 times, most recently from 5445910 to dc32b1b Compare May 15, 2024 07:53
@jmartinesp jmartinesp changed the title WIP: plain text editor implementation Plain text editor implementation based on markdown input May 15, 2024
@jmartinesp jmartinesp added the Record-Screenshots Runs the 'Record Screenshots' CI job and adds a commit with any new screenshots found. label May 15, 2024
@github-actions github-actions bot removed the Record-Screenshots Runs the 'Record Screenshots' CI job and adds a commit with any new screenshots found. label May 15, 2024
@jmartinesp jmartinesp marked this pull request as ready for review May 15, 2024 09:24
@jmartinesp jmartinesp requested a review from a team as a code owner May 15, 2024 09:24
@jmartinesp jmartinesp requested review from bmarty and removed request for a team May 15, 2024 09:24
@jmartinesp jmartinesp added the Run-Maestro Starts a Maestro Cloud session to run integration tests label May 16, 2024
@github-actions github-actions bot removed the Run-Maestro Starts a Maestro Cloud session to run integration tests label May 16, 2024
@jmartinesp jmartinesp added the Run-Maestro Starts a Maestro Cloud session to run integration tests label May 16, 2024
@github-actions github-actions bot removed the Run-Maestro Starts a Maestro Cloud session to run integration tests label May 16, 2024
@ElementBot
Copy link
Collaborator

ElementBot commented May 16, 2024

Warnings
⚠️

gradle/libs.versions.toml#L6 - A newer version of com.android.tools.build:gradle than 8.4.0 is available: 8.4.1

⚠️

gradle/libs.versions.toml#L12 - A newer version of androidx.core:core-ktx than 1.13.0 is available: 1.13.1

⚠️

gradle/libs.versions.toml#L18 - A newer version of androidx.datastore:datastore-preferences than 1.0.0 is available: 1.1.1

⚠️

gradle/libs.versions.toml#L21 - A newer version of androidx.lifecycle:lifecycle-runtime-ktx than 2.7.0 is available: 2.8.0

⚠️

gradle/libs.versions.toml#L22 - A newer version of androidx.activity:activity-compose than 1.8.2 is available: 1.9.0

Messages
📖

gradle/libs.versions.toml#L136 - There are multiple dependencies junit:junit but with different version

📖

gradle/libs.versions.toml#L138 - There are multiple dependencies androidx.test.ext:junit but with different version

📖

gradle/libs.versions.toml#L207 - There are multiple dependencies junit:junit but with different version

📖

gradle/libs.versions.toml#L208 - There are multiple dependencies androidx.test.ext:junit but with different version

Generated by 🚫 dangerJS against ca4691e

Copy link
Member

@bmarty bmarty left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, 2 small remarks after a static review, I will test it this morning.

}
}
is TextEditorState.Markdown -> {
val placeholder = if (composerMode.inThread) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe extract the placeholder computation to limit code duplication?

import io.element.android.libraries.core.extensions.orEmpty

@Stable
class ImmutableCharSequence(initialText: CharSequence = "") {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The name is a bit confusing me, since the CharSequence is actually mutable. Maybe rename to StableCharSequence?

Copy link
Member

@bmarty bmarty left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Doing some test. The Markdown composer is working as expected, but when in Rich, the composer is not emptied when the message is sent, so user can sent the same message several times.

image

Probably related, but if instead of sending again I close the rich text mode, the application crashes

java.lang.IndexOutOfBoundsException: setSpan (1 ... 1) ends beyond length 0

@jmartinesp
Copy link
Contributor Author

jmartinesp commented May 16, 2024

@bmarty your issue above should be fixed in b73a63b.

I also added changes for your other comments.

@jmartinesp jmartinesp requested a review from bmarty May 16, 2024 10:17
@jmartinesp jmartinesp added the Run-Maestro Starts a Maestro Cloud session to run integration tests label May 16, 2024
@github-actions github-actions bot removed the Run-Maestro Starts a Maestro Cloud session to run integration tests label May 16, 2024
Copy link
Member

@bmarty bmarty left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, working as expected now!

@jmartinesp
Copy link
Contributor Author

Nice! I'll release a RTE version compatible with these changes and merge the PR.

Copy link

sonarcloud bot commented May 21, 2024

Quality Gate Passed Quality Gate passed

Issues
0 New issues
0 Accepted issues

Measures
0 Security Hotspots
No data about Coverage
0.0% Duplication on New Code

See analysis details on SonarCloud

@jmartinesp jmartinesp added the Run-Maestro Starts a Maestro Cloud session to run integration tests label May 21, 2024
@github-actions github-actions bot removed the Run-Maestro Starts a Maestro Cloud session to run integration tests label May 21, 2024
@jmartinesp jmartinesp enabled auto-merge (squash) May 21, 2024 11:36
@jmartinesp jmartinesp disabled auto-merge May 21, 2024 11:58
@jmartinesp jmartinesp merged commit 880ebb4 into develop May 21, 2024
25 of 26 checks passed
@jmartinesp jmartinesp deleted the misc/jme/plain-text-editor branch May 21, 2024 11:58
@jmartinesp
Copy link
Contributor Author

The Maestro job got stuck after finishing so it was in a limbo. I just force merged.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants