Skip to content
This repository has been archived by the owner on Sep 11, 2024. It is now read-only.

Message editing: render avatars for pills in the editor #2997

Merged
merged 18 commits into from
May 21, 2019

Conversation

bwindels
Copy link
Contributor

@bwindels bwindels commented May 20, 2019

edit-pill-avatars

Note that this doesn't use Pill like MessageComposerInput because the editor contents isn't rendered by React. It moves most of the logic to Avatar 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

@bwindels bwindels requested a review from a team May 20, 2019 14:03
@jryans jryans requested review from jryans and removed request for a team May 20, 2019 14:22
@@ -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
Copy link
Collaborator

@jryans jryans May 20, 2019

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...

Copy link
Collaborator

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...)

Copy link
Contributor Author

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.

res/css/views/elements/_MessageEditor.scss Outdated Show resolved Hide resolved
@@ -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));
Copy link
Collaborator

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?

Copy link
Contributor Author

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.

src/editor/parts.js Outdated Show resolved Hide resolved
bwindels added 4 commits May 21, 2019 12:18
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
@bwindels bwindels requested a review from jryans May 21, 2019 10:25
Copy link
Collaborator

@jryans jryans left a 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! 😁

res/css/views/rooms/_EventTile.scss Outdated Show resolved Hide resolved
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants