copy/paste: Extract visible_range() to fix error.

When we tried to copy/paste multiple rows up to
and including the last row in our view, we'd have
a blueslip error when the `for` loop checked the
condition `rows.id(row) <= ...` after we had
called `row = rows.next_visible(row)` on the last
row.  Basically, `rows.id()` would complain
about a non-existent row.

Now we extract that code into `visible_range`, so
that our `while` loop can exit as soon as we found
the last row in the range.
This commit is contained in:
Steve Howell
2020-04-02 21:34:54 +00:00
committed by Tim Abbott
parent beaf488eeb
commit f2806a0a06
2 changed files with 29 additions and 3 deletions

View File

@@ -57,13 +57,15 @@ how modern browsers deal with copy/paste. Just test
your changes carefully.
*/
function construct_copy_div(div, start_id, end_id) {
const start_row = current_msg_list.get_row(start_id);
const copy_rows = rows.visible_range(start_id, end_id);
const start_row = copy_rows[0];
const start_recipient_row = rows.get_message_recipient_row(start_row);
const start_recipient_row_id = rows.id_for_recipient_row(start_recipient_row);
let should_include_start_recipient_header = false;
let last_recipient_row_id = start_recipient_row_id;
for (let row = start_row; rows.id(row) <= end_id; row = rows.next_visible(row)) {
for (const row of copy_rows) {
const recipient_row_id = rows.id_for_recipient_row(rows.get_message_recipient_row(row));
// if we found a message from another recipient,
// it means that we have messages from several recipients,