-
-
Notifications
You must be signed in to change notification settings - Fork 831
Message editing: render avatars for pills in the editor #2997
Conversation
this way it won't interfere with editor selection/caret
so width of editor stay the same as content (unrelated to pills, really)
@@ -20,7 +20,7 @@ limitations under the License. | |||
// this is to try not make the text move but still have some | |||
// padding around and in the editor. | |||
// Actual values from fiddling around in inspector | |||
margin: -7px -10px -5px -10px; | |||
margin: -7px 24px -5px -10px; // right margin: -10px + 34px |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wonder if this could be done in a less fragile way...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(Not a blocking comment as part of the review, I am just wondering...)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I applied mx_EventTile_content to the editor, which has the 34px of margin. I had to override the overflow so the autocompletion doesn't get clipped, but I agree this is still better, because less magic in the numbers.
@@ -37,8 +37,8 @@ function parseHtmlMessage(html) { | |||
const resourceId = pillMatch[1]; // The room/user ID | |||
const prefix = pillMatch[2]; // The first character of prefix | |||
switch (prefix) { | |||
case "@": return new UserPillPart(resourceId, n.textContent); | |||
case "#": return new RoomPillPart(resourceId, n.textContent); | |||
case "@": return new UserPillPart(resourceId, n.textContent, room.getMember(resourceId)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can room
ever be null here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No, it's the current room. If you can write events (to be able to edit them later), the current room should always be an instance of Room
AFAIK.
this way we don't have to include it in the magic number
the avatar style code is still different though, as it's implemented differently This also prevents updating the css variables when not needed, which caused the avatar to flicker when updating the editor.
this way, the background isn't clipped at the top
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good to me! 😁
Note that this doesn't use
Pill
likeMessageComposerInput
because the editor contents isn't rendered by React. It moves most of the logic toAvatar
though, if it isn't there already, to avoid duplication to some extent.It's implemented as a pseudo-element on the span, with css variables set in JS passing the avatar url and letter down from the span. This way, it's sure to not interfere with the caret in the editor like an
<img>
would.Part of element-hq/element-web#9487