You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
fix: collaboration cursor chrome should not wrap mid-line (#1423)
Here be dragons!
The collaboration cursor caret needs to:
- exist in the dom as a non-zero width element, so that when hovering over it, the label can display
- yet, effectively not take up space in the dom, so that it doesn't cause wrapping or otherwise effect layout of the page
To achieve this, it took quite a bit of fiddling to figure out how to do this.
The caret is a span which has a before and after pseudo element.
The before element is what actually takes up space in the dom, and is colored via a border.
The color is actually set by reading the current color from the `.collaboration-cursor__caret` element. Allowing for dynamic coloring from JS.
There are a number of browser specific quirks with these hacks:
- Firefox differs from Chrome & Safari in that it will split a word that is wrapping if not displayed as inline-block (whereas the others need display: inline)
- Safari differs from Chrome & Firefox in that it needs the pseudo element to be position: relative to display a pseudo-element element with a negative margin
The word-joiner char (\u2060) is used to make sure the caret doesn't wrap around the text.
Therefore if modifying this code, please test in all major browsers to ensure that the caret is rendered correctly in all browsers.
Copy file name to clipboardExpand all lines: packages/core/src/editor/editor.css
+47-13
Original file line number
Diff line number
Diff line change
@@ -77,23 +77,56 @@ Tippy popups that are appended to document.body directly
77
77
opacity:0.001;
78
78
}
79
79
80
+
/**
81
+
Here be dragons!
82
+
83
+
The collaboration cursor caret needs to:
84
+
- exist in the dom as a non-zero width element, so that when hovering over it, the label can display
85
+
- yet, effectively not take up space in the dom, so that it doesn't cause wrapping or otherwise effect layout of the page
86
+
87
+
To achieve this, it took quite a bit of fiddling to figure out how to do this.
88
+
89
+
The caret is a span which has a before and after pseudo element.
90
+
The before element is what actually takes up space in the dom, and is colored via a border.
91
+
The color is actually set by reading the current color from the `.collaboration-cursor__caret` element. Allowing for dynamic coloring from JS.
92
+
93
+
There are a number of browser specific quirks with these hacks:
94
+
- Firefox differs from Chrome & Safari in that it will split a word that is wrapping if not displayed as inline-block (whereas the others need display: inline)
95
+
- Safari differs from Chrome & Firefox in that it needs the pseudo element to be position: relative to display a pseudo-element element with a negative margin
96
+
97
+
The word-joiner char (\u2060) is used to make sure the caret doesn't wrap around the text.
98
+
99
+
Therefore if modifying this code, please test in all major browsers to ensure that the caret is rendered correctly in all browsers.
100
+
**/
101
+
80
102
/* Give a remote user a caret */
81
103
.collaboration-cursor__caret {
82
-
outline:1px solid #0d0d0d;
83
104
position: relative;
84
105
word-break: normal;
85
106
white-space: nowrap !important;
86
107
}
87
108
88
-
/* Allow the caret to be hovered over */
89
-
.collaboration-cursor__caret::after {
90
-
content:"";
91
-
position: absolute;
92
-
top:0;
93
-
right:0;
94
-
left:0;
95
-
bottom:0;
96
-
width:2px;
109
+
/* Allow the caret to be colored & hovered over */
110
+
.collaboration-cursor__caret::before {
111
+
/* Use currentColor to grab the color from the caret in set by JS */
112
+
border-left:2px solid currentColor;
113
+
/* Make the cursor not actually take up the 2px of space within the element */
114
+
margin-left:-2px;
115
+
/* Fixes Safari's rendering of negative margin elements */
116
+
position: relative;
117
+
}
118
+
119
+
/* Firefox will split a word that is wrapping if not displayed as inline-block */
120
+
@-moz-document url-prefix() {
121
+
.collaboration-cursor__caret::before {
122
+
display: inline-block;
123
+
}
124
+
}
125
+
126
+
/* Add a word-joiner (\u2060) char to each side of the caret */
127
+
.collaboration-cursor__caret::after,
128
+
.collaboration-cursor__caret::before {
129
+
content:"";
97
130
}
98
131
99
132
/* Render the username above the caret */
@@ -103,10 +136,11 @@ Tippy popups that are appended to document.body directly
103
136
font-style: normal;
104
137
font-weight:600;
105
138
line-height: normal;
106
-
left:0;
139
+
left:-2px;
107
140
overflow: hidden;
108
141
position: absolute;
109
142
white-space: nowrap;
143
+
user-select: none;
110
144
111
145
color: transparent;
112
146
max-height:5px;
@@ -121,8 +155,8 @@ Tippy popups that are appended to document.body directly
0 commit comments