Skip to content

Commit

Permalink
style: cancel old message highlight animations (#4203)
Browse files Browse the repository at this point in the history
I.e. when we highlight a new message as a result of `jumpToMessage`,
remove the animation on the previously highlighted message
(or messages).

This is particularly useful for the Ctrl + Up shortcut
which is to choose the message to reply to.

Just FYI the added code usually takes 0.1-0.5ms to execute.

Co-authored-by: Simon Laux <[email protected]>
  • Loading branch information
WofWca and Simon-Laux authored Oct 12, 2024
1 parent 0680efe commit 50c5b9b
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 5 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@
- losing scrolling "momentum" while scrolling the messages list fast #4122
- fix crash when you chose Settings from a context menu on account you haven't selected #4190
- fix All Media not opening from a context menu on account you haven't selected #4191
- cancel old message highlight animations when a new message is highlighted #4203
- fix: packaging: include architecture in filename for all appimages #4202
- fix: make open external link scheme case insensive #4201

Expand Down
7 changes: 2 additions & 5 deletions packages/frontend/src/components/composer/Composer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -603,11 +603,8 @@ export function useDraft(
} as Type.MessageQuote
saveDraft()

// TODO improvement: perhaps the animation could used
// a little less intensity.
// Not good when jumping through several messages.
// Can we just cancel the animation on the previously highlighted message?
// Also it looks like it takes a while to execute
// TODO perf: jumpToMessage is not instant, but it should be
// since the message is (almost?) always already rendered.
jumpToMessage(accountId, messageId, true)
}
// TODO perf: I imagine this is pretty slow, given IPC and some chats
Expand Down
5 changes: 5 additions & 0 deletions packages/frontend/src/components/message/MessageList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -346,6 +346,11 @@ export default function MessageList({ accountId, chat, refComposer }: Props) {
domElement.tagName === 'LI' ? domElement : domElement.parentElement
if (highlightableElement !== null) {
setTimeout(() => {
// Stop the animation on the previously highlighted message.
highlightableElement.parentElement
?.querySelectorAll(':scope > .highlight')
.forEach(el => el.classList.remove('highlight'))

// Retrigger animation
highlightableElement.classList.add('highlight')
highlightableElement.style.animation = 'none'
Expand Down

0 comments on commit 50c5b9b

Please sign in to comment.