mirror of https://github.com/zulip/zulip.git
list_cursor: Promote error handling code.
If a caller passes undefined to go_to, it is almost certainly a programming error, so we shouldn't silently ignore it just because the current key is undefined. We also avoid setting curr_key until we validate the incoming key.
This commit is contained in:
parent
87e2231902
commit
eb7f7fae55
|
@ -83,20 +83,20 @@ var list_cursor = function (opts) {
|
|||
};
|
||||
|
||||
self.go_to = function (key) {
|
||||
if (key === self.curr_key) {
|
||||
return;
|
||||
}
|
||||
if (key === undefined) {
|
||||
blueslip.error('Caller is not checking keys for list_cursor.go_to');
|
||||
return;
|
||||
}
|
||||
if (key === self.curr_key) {
|
||||
return;
|
||||
}
|
||||
self.clear();
|
||||
self.curr_key = key;
|
||||
var row = self.get_row(key);
|
||||
if (row === undefined) {
|
||||
blueslip.error('Cannot highlight key for list_cursor: ' + key);
|
||||
return;
|
||||
}
|
||||
self.curr_key = key;
|
||||
row.highlight();
|
||||
};
|
||||
|
||||
|
|
Loading…
Reference in New Issue