Skip to content

Commit

Permalink
improvement: improve jumpToMessage scrolling
Browse files Browse the repository at this point in the history
Don't scroll the message list if the message is already visible.
  • Loading branch information
WofWca committed Oct 10, 2024
1 parent bdca272 commit 2b72fea
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 2 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
- Update local help (2024-10-02) #4165
- trim whitepaces when reading from clipboard in qr code reader #4169
- load chat lists faster (the chat list on the main screen, "Forward to..." dialog, etc)
- when jumping to message, don't scroll the message list if the message is already in view #4204

### Fixed
- fix that you can not click header button in dialog when they are on top of the navbar #4093
Expand Down
15 changes: 14 additions & 1 deletion packages/frontend/scss/message/_message-list.scss
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,20 @@
margin: 10px 0px;

li {
margin-bottom: 10px;
$margin-bottom: 10px;
margin-bottom: $margin-bottom;
// This is so that when we `scrollIntoView()` the last message
// in the chat, its margin is also scrolled into view.
// Otherwise only the visible part of the message would get scrolled
// into view, resulting in the message list not getting
// scrolled all the way to the bottom,
// resulting in the message list not not getting scrolled to the
// bottom when another message arrives.
scroll-margin-bottom: $margin-bottom;
// And this is purely cosmetic. For scrolling to a message
// that is above the visible area.
scroll-margin-top: $margin-bottom / 2;

min-width: 200px;

&::after {
Expand Down
11 changes: 10 additions & 1 deletion packages/frontend/src/components/message/MessageList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -333,7 +333,16 @@ export default function MessageList({ accountId, chat, refComposer }: Props) {
)
}

domElement.scrollIntoView()
domElement.scrollIntoView({
// behavior:
// "nearest" so as to not scroll if the message is already in view.
// Otherwise we'd try to scroll in such a way that the message
// is at the very top of the messages list.
// This would not be nice for the Ctrl + Up shortcut,
// or when highlighting the reply that is already in view.
block: 'nearest',
inline: 'nearest',
})

if (scrollTo.highlight === true) {
// Trigger highlight animation
Expand Down

0 comments on commit 2b72fea

Please sign in to comment.