Make sure a previously highlighted nick in the user list is highlighted when the list is refreshed
List is refreshed when there is a change in the channel (join/part/quit/nick).
This commit is contained in:
parent
3070ae098a
commit
615353c582
@ -163,6 +163,11 @@ function renderChannelUsers(data) {
|
||||
.sort((a, b) => b.lastMessage - a.lastMessage)
|
||||
.map((a) => a.nick);
|
||||
|
||||
// Before re-rendering the list of names, there might have been an entry
|
||||
// marked as active (i.e. that was highlighted by keyboard navigation).
|
||||
// It is `undefined` if there was none.
|
||||
const previouslyActive = users.find(".active").data("name");
|
||||
|
||||
const search = users
|
||||
.find(".search")
|
||||
.prop("placeholder", nicks.length + " " + (nicks.length === 1 ? "user" : "users"));
|
||||
@ -177,6 +182,15 @@ function renderChannelUsers(data) {
|
||||
search.trigger("input");
|
||||
}
|
||||
|
||||
// If a nick was highlighted before re-rendering the lists, re-highlight it in
|
||||
// the newly-rendered list.
|
||||
if (previouslyActive) {
|
||||
// We need to un-highlight everything first because triggering `input` with
|
||||
// a value highlights the first entry.
|
||||
users.find(".user").removeClass("active");
|
||||
users.find(`.user[data-name="${previouslyActive}"]`).addClass("active");
|
||||
}
|
||||
|
||||
return users;
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user