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
The caret divides the marker with inline styles #502
Comments
May be the same what I described in #500 (comment). A filler splitting the element. |
Caret creating a filler element and splitting words/elements is a known bug. |
The easiest way to reproduce it is to load such a content into the markers test: <div id="editor">
<p><a href="1"><i><strong>Lorem ipsum dolor sit amet.</strong></i></a></p>
<p>Foobar.</p>
</div> (you also need to load the link feature) And place selection in the marker. The DOM gets messy. The order of attribute elements on the left side of the selection is different than on the right-hand side so they don't get merged nicely and hence, the filler is inserted between them. The problem here is that we have 3 attributes with the same priority - strong, i and marker and after some operations the order gets messy because we only compare priorties (so the sort isn't stable at all). I made a quick fix like this and it seems to fix the issue: --- a/src/view/writer.js
+++ b/src/view/writer.js
@@ -914,6 +914,16 @@ function unwrapChildren( parent, startOffset, endOffset, attribute ) {
return Range.createFromParentsAndOffsets( parent, startOffset, parent, endOffset );
}
+function shouldABeOutsideB( a, b ) {
+ if ( a.priority < b.priority ) {
+ return true;
+ } else if ( a.priority > b.priority ) {
+ return false;
+ } else {
+ return a.name < b.name;
+ }
+}
+
// Wraps children with provided `attribute`. Only children contained in `parent` element between
// `startOffset` and `endOffset` will be wrapped.
//
@@ -933,7 +943,7 @@ function wrapChildren( parent, startOffset, endOffset, attribute ) {
const isUI = child.is( 'uiElement' );
// Wrap text, empty elements, ui elements or attributes with higher or equal priority.
- if ( isText || isEmpty || isUI || ( isAttribute && attribute.priority <= child.priority ) ) {
+ if ( isText || isEmpty || isUI || ( isAttribute && shouldABeOutsideB( attribute, child ) ) ) {
// Clone attribute.
const newAttribute = attribute.clone(); However, this won't be stable still because you may have two different attributes which have the same element name. So, we need some way to reliably compare entire attributes. I don't know the rules where elements are considered identical (and are merged) but assuming that classes names and attribute names (but not values) count to being identical, we could compare not element names alone but |
Steps to reproduce
Link
plugin into themarkers
manual test.Clipboard
plugin).bold
,italic
andlink
.Current result
The marker divides on every click.
GIF
Other information
OS: Windows 10, MacOS X
Browser: Chrome, Safari, Firefox, Opera, Edge
Release: 0.10.0
The text was updated successfully, but these errors were encountered: