Commit 5148848a authored by Olivier Yiptong's avatar Olivier Yiptong Committed by Chromium LUCI CQ

TableView: Select-all works for 1+ items

This adds the ability in TableView to add a range of items comprised of
only 1 item. This requirement manifests itself when using a "select-all"
capability. Prior to this CL, only ranges of 2+ items would be allowed.

Furthermore, this fixes a bug when all items are selected while there is
no 'active' row in a table. This can occur when the selection UI is
outside of the TableView.

Change-Id: I950fca34e8c83b650d14e0d6da3e7ad9d0b84f33
Fixed: 1169260
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2641320
Commit-Queue: Olivier Yiptong <oyiptong@chromium.org>
Auto-Submit: Olivier Yiptong <oyiptong@chromium.org>
Reviewed-by: default avatarAvi Drissman <avi@chromium.org>
Cr-Commit-Position: refs/heads/master@{#845741}
parent 0a3ac15f
......@@ -112,7 +112,10 @@ void ListSelectionModel::AddIndexToSelection(int index) {
void ListSelectionModel::AddIndexRangeToSelection(int index_start,
int index_end) {
DCHECK_LT(index_start, index_end);
DCHECK_LE(index_start, index_end);
if (index_start == index_end)
return AddIndexToSelection(index_start);
for (int i = index_start; i <= index_end; ++i) {
selected_indices_.insert(i);
......
......@@ -102,13 +102,16 @@ TEST_F(ListSelectionModelTest, AddIndexToSelected) {
EXPECT_EQ("active=-1 anchor=-1 selection=2 4", StateAsString(model));
}
TEST_F(ListSelectionModelTest, AddIndexRangeToSelected) {
TEST_F(ListSelectionModelTest, AddIndexRangeToSelection) {
ListSelectionModel model;
model.AddIndexRangeToSelection(2, 3);
EXPECT_EQ("active=-1 anchor=-1 selection=2 3", StateAsString(model));
model.AddIndexRangeToSelection(4, 5);
EXPECT_EQ("active=-1 anchor=-1 selection=2 3 4 5", StateAsString(model));
model.AddIndexRangeToSelection(1, 1);
EXPECT_EQ("active=-1 anchor=-1 selection=1 2 3 4 5", StateAsString(model));
}
TEST_F(ListSelectionModelTest, RemoveIndexFromSelection) {
......
......@@ -1105,8 +1105,10 @@ void TableView::SchedulePaintForSelection() {
if (selection_model_.size() == 1) {
const int first_model_row = GetFirstSelectedRow();
SchedulePaintInRect(GetRowBounds(ModelToView(first_model_row)));
if (first_model_row != selection_model_.active())
SchedulePaintInRect(GetRowBounds(ModelToView(selection_model_.active())));
const int active_row = selection_model_.active();
if (active_row >= 0 && first_model_row != active_row)
SchedulePaintInRect(GetRowBounds(ModelToView(active_row)));
} else if (selection_model_.size() > 1) {
SchedulePaint();
}
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment