mirror of
https://github.com/zulip/zulip.git
synced 2025-11-15 19:31:58 +00:00
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:
@@ -57,13 +57,15 @@ how modern browsers deal with copy/paste. Just test
|
|||||||
your changes carefully.
|
your changes carefully.
|
||||||
*/
|
*/
|
||||||
function construct_copy_div(div, start_id, end_id) {
|
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 = rows.get_message_recipient_row(start_row);
|
||||||
const start_recipient_row_id = rows.id_for_recipient_row(start_recipient_row);
|
const start_recipient_row_id = rows.id_for_recipient_row(start_recipient_row);
|
||||||
let should_include_start_recipient_header = false;
|
let should_include_start_recipient_header = false;
|
||||||
|
|
||||||
let last_recipient_row_id = start_recipient_row_id;
|
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));
|
const recipient_row_id = rows.id_for_recipient_row(rows.get_message_recipient_row(row));
|
||||||
// if we found a message from another recipient,
|
// if we found a message from another recipient,
|
||||||
// it means that we have messages from several recipients,
|
// it means that we have messages from several recipients,
|
||||||
|
|||||||
@@ -41,6 +41,30 @@ exports.last_visible = function () {
|
|||||||
return $('.focused_table .selectable_row').last();
|
return $('.focused_table .selectable_row').last();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
exports.visible_range = function (start_id, end_id) {
|
||||||
|
/*
|
||||||
|
Get all visible rows between start_id
|
||||||
|
and end_in, being inclusive on both ends.
|
||||||
|
*/
|
||||||
|
|
||||||
|
const rows = [];
|
||||||
|
|
||||||
|
let row = current_msg_list.get_row(start_id);
|
||||||
|
let msg_id = exports.id(row);
|
||||||
|
|
||||||
|
while (msg_id <= end_id) {
|
||||||
|
rows.push(row);
|
||||||
|
|
||||||
|
if (msg_id >= end_id) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
row = exports.next_visible(row);
|
||||||
|
msg_id = exports.id(row);
|
||||||
|
}
|
||||||
|
|
||||||
|
return rows;
|
||||||
|
};
|
||||||
|
|
||||||
exports.is_draft_row = function (row) {
|
exports.is_draft_row = function (row) {
|
||||||
return row.find('.restore-draft').length >= 1;
|
return row.find('.restore-draft').length >= 1;
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user