element-x-android icon indicating copy to clipboard operation
element-x-android copied to clipboard

Plain text editor implementation based on markdown input

Open jmartinesp opened this issue 1 year ago • 5 comments

Type of change

  • [x] 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 https://github.com/matrix-org/matrix-rich-text-editor/pull/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

  • [x] Physical
  • [ ] Emulator
  • OS version(s): 14

Checklist

  • [ ] Changes have been tested on an Android device or Android emulator with API 23
  • [x] UI change has been tested on both light and dark themes
  • [ ] Accessibility has been taken into account. See https://github.com/element-hq/element-x-android/blob/develop/CONTRIBUTING.md#accessibility
  • [x] Pull request is based on the develop branch
  • [x] Pull request includes a new file under ./changelog.d. See https://github.com/element-hq/element-x-android/blob/develop/CONTRIBUTING.md#changelog
  • [x] Pull request includes screenshots or videos if containing UI changes
  • [ ] Pull request includes a sign off
  • [x] You've made a self review of your PR

jmartinesp avatar May 14 '24 11:05 jmartinesp

:iphone: 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

github-actions[bot] avatar May 14 '24 12:05 github-actions[bot]

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 :warning:
...tcomposer/components/markdown/MarkdownTextInput.kt 74.24% 1 Missing and 16 partials :warning:
...ries/textcomposer/model/MarkdownTextEditorState.kt 82.69% 2 Missing and 7 partials :warning:
...s/impl/messagecomposer/MessageComposerPresenter.kt 82.50% 4 Missing and 3 partials :warning:
...android/libraries/textcomposer/ComposerModeView.kt 92.63% 2 Missing and 5 partials :warning:
...id/libraries/textcomposer/model/TextEditorState.kt 75.00% 0 Missing and 6 partials :warning:
...oid/libraries/textcomposer/mentions/MentionSpan.kt 66.66% 0 Missing and 3 partials :warning:
...aries/textcomposer/mentions/MentionSpanProvider.kt 81.25% 2 Missing and 1 partial :warning:
...composer/components/markdown/StableCharSequence.kt 77.77% 2 Missing :warning:
...ages/impl/mentions/MentionSuggestionsPickerView.kt 87.50% 0 Missing and 1 partial :warning:
... 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     

:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.

codecov[bot] avatar May 14 '24 14:05 codecov[bot]

Warnings
:warning:

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

:warning:

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

:warning:

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

:warning:

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

:warning:

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

Messages
:book:

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

:book:

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

:book:

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

:book:

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

Generated by :no_entry_sign: dangerJS against ca4691e8056ec15e0d50b58ff2710ea40957ae51

ElementBot avatar May 16 '24 07:05 ElementBot

@bmarty your issue above should be fixed in https://github.com/element-hq/element-x-android/pull/2840/commits/b73a63b95595f3db486c38111595c81bcd30b5a1.

I also added changes for your other comments.

jmartinesp avatar May 16 '24 10:05 jmartinesp

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

jmartinesp avatar May 21 '24 10:05 jmartinesp

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

jmartinesp avatar May 21 '24 11:05 jmartinesp