wordpress-mobile / AztecEditor-Android

A reusable native Android rich text editor component.
Mozilla Public License 2.0
675 stars 112 forks source link

Add UrlPastePlugin.kt to handle pasted links #1001

Closed planarvoid closed 1 year ago

planarvoid commented 1 year ago

In this PR I'm adding a plugin option to handle pasted text. This could be useful to override the default behaviour of handling any links. I'm also adding UrlPastePlugin which makes sure that when you paste an URL over selected text, it makes the whole thing into a link instead of replacing the selected text with a link.

Before you start make sure you add the following code to aztec in your MainActivity

aztec.addPlugin(UrlPastePlugin())

Test

  1. Run the app
  2. Copy link from your browser
  3. Long press within the text
  4. Paste content of your clipboard
  5. Notice the pasted text is a link
  6. Click on the link
  7. Notice it's recognized by the toolbar as a link

Test

  1. Run the app
  2. Copy link from your browser
  3. Select a word in the text
  4. Long press on it
  5. Paste content of your clipboard
  6. Notice the previously selected text is now a link
  7. Click on the link
  8. Notice it's recognized by the toolbar as a link

Test

  1. Run the app
  2. Copy something that's not a link
  3. Long press within the text
  4. Paste content of your clipboard
  5. Notice the pasted text is not a link

Test

  1. Run the app
  2. Copy something that's not a link
  3. Select a word in the text
  4. Long press on it
  5. Paste content of your clipboard
  6. Notice the selected text is replaced by the pasted text and is not a link

Review

@khaykov

Make sure strings will be translated: