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:
Jérémie Astori 2017-12-17 23:06:58 -05:00
parent 3070ae098a
commit 615353c582
No known key found for this signature in database
GPG Key ID: B9A4F245CD67BDE8

View File

@ -163,6 +163,11 @@ function renderChannelUsers(data) {
.sort((a, b) => b.lastMessage - a.lastMessage) .sort((a, b) => b.lastMessage - a.lastMessage)
.map((a) => a.nick); .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 const search = users
.find(".search") .find(".search")
.prop("placeholder", nicks.length + " " + (nicks.length === 1 ? "user" : "users")); .prop("placeholder", nicks.length + " " + (nicks.length === 1 ? "user" : "users"));
@ -177,6 +182,15 @@ function renderChannelUsers(data) {
search.trigger("input"); 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; return users;
} }