Lundalogik / lime-elements

Provides reusable web components for Lime CRM
https://lundalogik.github.io/lime-elements/versions/latest
Other
38 stars 11 forks source link

fix(text-editor): selected text now used for copying link text #3054

Closed LawrenceBorst closed 3 months ago

LawrenceBorst commented 3 months ago

Fixes Lundalogik/crm-feature#4213

The problem here is that when we select some text, the text may only be part of the text node. However, in the selection handler (ProseMirror view transaction callback) we copy the text from the whole node.

So if you mark your text like <b>alpha</b> beta gamma, and you select "gamma", what will be pasted is "beta gamma" because they occupy the same text node.

There is a slight change with how things used to be done. It used to only check for the node in which we find the selected text. But now we recurse over all nodes. This fixes a separate issue where, say, in the previous example, you selected "alpha beta" (note that alpha is in bold), you would only get the text "beta".

How to Test

We can test manually. The important things are that: 1) When selecting only partial text in a text node, not the whole text is pasted 2) When there's a selection crossing several nodes, all of the text is used

Edge cases include empty selection, selection of the whole text node, partial text node, selection with one side touching the end of the node, selection crossing several nodes. Try editing around a bit as well--if the document becomes "broken" (unparseable) ProseMirror will fail to paste the value into the editor, and the editor becomes unusuable.

With ProseMirror it's always important to check the emitted value.

Review:

Browsers tested:

(Check any that applies, it's ok to leave boxes unchecked if testing something didn't seem relevant.)

Windows:

Linux:

macOS:

Mobile:

github-actions[bot] commented 3 months ago

Documentation has been published to https://lundalogik.github.io/lime-elements/versions/PR-3054/

lime-opensource commented 3 months ago

:tada: This PR is included in version 37.53.3 :tada:

The release is available on:

Your semantic-release bot :package::rocket: