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

Alt text: Alt text counter #529

Merged
merged 4 commits into from
Jan 14, 2025
Merged

Alt text: Alt text counter #529

merged 4 commits into from
Jan 14, 2025

Conversation

AdamGrzybkowski
Copy link
Contributor

Closes #502

Description

This PR adds a little counter to show the remaining characters count for the alt text. Once the limit is reached the alt text won't be modified.

alt_text_limit.mp4

Testing Steps

  1. Launch the QE
  2. Open the avatar's menu and tap Alt text
  3. Add new characters to the input field to reach the limit
  4. Confirm no more chars can be added
  5. Remove the text completely
  6. Confirm the counter shows 125
  7. Paste a text that's longer than 125 chars
  8. Confirm only the first 125 chars were copied

@AdamGrzybkowski AdamGrzybkowski added Enhance Enhancement [Feature] Gravatar-Quickeditor Gravatar Quick Editor module labels Jan 10, 2025
@AdamGrzybkowski AdamGrzybkowski added this to the 2.3.0 milestone Jan 10, 2025
@wpmobilebot
Copy link
Collaborator

wpmobilebot commented Jan 10, 2025

📲 You can test the changes from this Pull Request in Gravatar Demo by scanning the QR code below to install the corresponding build.
App Name Gravatar Demo
Commit69bef4c
Direct Downloadgravatar-demo-prototype-build-pr529-69bef4c.apk

Comment on lines +10 to +13
val isSaveButtonEnabled: Boolean
get() = altText != initialAltText && !isUpdating
Copy link
Contributor Author

Choose a reason for hiding this comment

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

We don't need to set this manually, so I moved it here and set it conditionally.

Comment on lines 120 to 224
viewModel.onEvent(AltTextEvent.AvatarAltTextSaveTapped)
advanceUntilIdle()

viewModel.uiState.test {
skipItems(2)
expectMostRecentItem()
viewModel.onEvent(AltTextEvent.AvatarAltTextSaveTapped)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think this is a bit more future-proof as we are only testing the states after AvatarAltTextSaveTapped event without skipping fixed numbers of states.

@AdamGrzybkowski AdamGrzybkowski force-pushed the adam/502_char_count branch 2 times, most recently from a1b1423 to ea42255 Compare January 10, 2025 12:35
Copy link
Member

@mlumeau mlumeau left a comment

Choose a reason for hiding this comment

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

I noticed a couple of things while testing:

  • When I hit 0 in the counter, move the caret to the middle of the paragraph and start typing again, it erases the end of the text. Is that on purpose?
  • This is maybe worth creating another issue but when adding multiple new lines at some point the "save" button disappears with no way to bring it back.
Screen_recording_20250110_144921.mp4

@AdamGrzybkowski
Copy link
Contributor Author

When I hit 0 in the counter, move the caret to the middle of the paragraph and start typing again, it erases the end of the text. Is that on purpose?

Not on purpose, but that's what the take(125) does now. I'm open to whether this is ok for us or not.

This is maybe worth creating another issue but when adding multiple new lines at some point the "save" button disappears with no way to bring it back.

Yes, this is unrelated. #533

@hamorillo
Copy link
Contributor

Not on purpose, but that's what the take(125) does now. I'm open to whether this is ok for us or not.

That behavior can create some misunderstandings. However, I agree it's not easy to handle; for example, what if I have five left characters and I paste 20 characters in the middle? We have to consider those cases.

For example, Revolut handles that with a negative counter. When you reach the limit, you are not allowed to add any more characters.

@AdamGrzybkowski
Copy link
Contributor Author

I wouldn't complicate things too much. Here's my suggestion:

  • Disallow adding extra characters when the alt text reaches the limit regardless of the cursor position.
  • Keep the first 125 chars from the inserted text when the limit is not reached. That would mean some text could be lost if the cursor was in the middle (current behavior).

WDYT?

@mlumeau
Copy link
Member

mlumeau commented Jan 13, 2025

I wouldn't complicate things too much. Here's my suggestion:

  • Disallow adding extra characters when the alt text reaches the limit regardless of the cursor position.
  • Keep the first 125 chars from the inserted text when the limit is not reached. That would mean some text could be lost if the cursor was in the middle (current behavior).

WDYT?

Sounds good to me! I doubt we'll get many complaints about this obscure edge case anyway.

@AdamGrzybkowski
Copy link
Contributor Author

@mlumeau @hamorillo Done.

Copy link
Member

@mlumeau mlumeau left a comment

Choose a reason for hiding this comment

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

👍 LGTM. I noticed a tiny weird thing, totally not blocking: the caret is still moving when trying to insert text at limit.

Copy link
Contributor

@hamorillo hamorillo left a comment

Choose a reason for hiding this comment

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

I was writing a similar comment to Maxime's about the cursor moving without inserting any text. 🙂

@@ -188,7 +198,26 @@ internal fun AltTextPage(
textStyle = LocalTextStyle.current.copy(color = MaterialTheme.colorScheme.onSurface),
modifier = Modifier
.fillMaxWidth()
.padding(start = 16.dp, top = 8.dp, bottom = 8.dp),
.fillMaxHeight(),
Copy link
Contributor

Choose a reason for hiding this comment

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

⛏ I think we can replace it with fillMaxSize()

@AdamGrzybkowski
Copy link
Contributor Author

I noticed a tiny weird thing, totally not blocking: the caret is still moving when trying to insert text at limit.

Yeah, I noticed that. The thing is we don't control the cursor position and to do that we have to keep that in the ViewModel. I did a quick try and it's a pain, to be honest. I will merge this for now and we can improve this later if we feel like it's a big issue.

@AdamGrzybkowski AdamGrzybkowski merged commit ddebd75 into trunk Jan 14, 2025
17 checks passed
@AdamGrzybkowski AdamGrzybkowski deleted the adam/502_char_count branch January 14, 2025 12:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Enhance Enhancement [Feature] Gravatar-Quickeditor Gravatar Quick Editor module
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Quick Editor: Alt Text - Limit to 125 the number of characters
4 participants