diff --git a/zephyr/static/js/dom_access.js b/zephyr/static/js/dom_access.js index 49ddf073ae..91d41b97e7 100644 --- a/zephyr/static/js/dom_access.js +++ b/zephyr/static/js/dom_access.js @@ -1,13 +1,18 @@ +// We need to andSelf() because more often than not, the next item +// *is* a .message_row, so nextUntil returns an empty set (except for +// when it's in a bookend). +// (This could probably be further optimized by handling that case +// explicitly first, since it's also the common case.) function get_next_visible(message_row) { if (message_row === undefined) return []; - return message_row.nextAll('.message_row').filter(':first'); + return message_row.nextUntil('.message_row').andSelf().next('.message_row'); } function get_prev_visible(message_row) { if (message_row === undefined) return []; - return message_row.prevAll('.message_row').filter(':first'); + return message_row.prevUntil('.message_row').andSelf().prev('.message_row'); } function get_first_visible() {