Skip to content

Commit

Permalink
Fix scrolling to message by removing id2dom mapping
Browse files Browse the repository at this point in the history
  • Loading branch information
edemaine committed Nov 17, 2023
1 parent 7348e6c commit c5b370a
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 10 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,12 @@ To see every change with descriptions aimed at developers, see
As a continuously updated web app, Coauthor uses dates
instead of version numbers.

## 2023-11-17

* Fix scrolling to a message when clicking on it in table of contents
(a long-standing but rare bug).
[[#608](https://github.com/edemaine/coauthor/issues/608)]

## 2023-11-15

* Support `\begin{hint}` / `\begin{hint+}` environments (for problem hints).
Expand Down
16 changes: 6 additions & 10 deletions client/message.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -450,13 +450,12 @@ threadMentions = {}

imageRefCount = new ReactiveDict
imageInternalRefCount = new ReactiveDict
id2dom = {}
scrollToLater = null
fileQuery = null
fileQueries = {}

checkImage = (id) ->
if id2dom[id]? or imageRefCount.get id
checkImage = (id, isLoaded) ->
if isLoaded or imageRefCount.get id
return if id of fileQueries
fileQueries[id] = true
else
Expand Down Expand Up @@ -504,7 +503,7 @@ export naturallyFolded = (message) -> message.minimized or message.deleted

export scrollToMessage = (id) ->
id = id[1..] if id[0] == '#'
if (dom = id2dom[id])?
if (dom = document.getElementById id)?
scrollToLater = null
$('html, body').animate
scrollTop: Math.max 0, $(dom).offset().top - 15
Expand Down Expand Up @@ -2287,17 +2286,14 @@ export WrappedSubmessage = React.memo ({message, read}) ->

## One-time effects
useEffect ->
## Maintain id2dom mapping
id2dom[message._id] = ref.current
checkImage message._id
## Scroll to this message if it's been requested.
if scrollToLater == message._id
scrollToLater = null
scrollToMessage message._id
## Restore id2dom mapping
## Watch for changes to file
checkImage message._id, true
->
delete id2dom[message._id]
checkImage message._id
checkImage message._id, false
, [message._id]

## Give focus to Title input if we just started editing this message,
Expand Down

0 comments on commit c5b370a

Please sign in to comment.