Skip to content

Commit

Permalink
DROOLS-5521: Handle pressing TAB when editing last cell (#1006)
Browse files Browse the repository at this point in the history
* DROOLS-5521: Handle pressing TAB when editing last cell

For more details see https://issues.redhat.com/browse/DROOLS-5521

* Apply Sonar suggestion
  • Loading branch information
Jozef Marko committed Aug 5, 2020
1 parent 5c5cf6b commit 1cf7020
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import java.util.List;
import java.util.Objects;
import java.util.Optional;
import java.util.function.IntPredicate;

import com.ait.lienzo.client.core.shape.Group;
import com.ait.lienzo.client.core.types.Point2D;
Expand Down Expand Up @@ -321,13 +322,11 @@ private int computeHiddenColumnsCompensation(final int startingIndex,
final SelectionExtension direction) {
int index = startingIndex;
int hiddenColumnsCount = 0;
IntPredicate outOfBound = columnIndex -> columnIndex < 0 || columnIndex >= gridModel.getColumnCount();
if (gridModel.getColumnCount() > 0) {
while (!gridModel.getColumns().get(index).isVisible()) {
while (!outOfBound.test(index) && !gridModel.getColumns().get(index).isVisible()) {
hiddenColumnsCount++;
index += direction.getDeltaX();
if (index < 0 || index >= gridModel.getColumnCount()) {
break;
}
}
}
return hiddenColumnsCount * direction.getDeltaX();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -406,6 +406,25 @@ public void adjustSelectionLeftAndFindVisible() {
gridWidgetData.getSelectedCellsOrigin());
}

@Test
public void adjustSelectionLeftOutOfBound() {
cellSelectionManager.selectCell(0,
0,
false,
false);
cellSelectionManager.adjustSelection(SelectionExtension.LEFT,
false);

final List<GridData.SelectedCell> selectedCells = gridWidgetData.getSelectedCells();
assertEquals(1,
selectedCells.size());
assertTrue(selectedCells.contains(new GridData.SelectedCell(0,
0)));
assertEquals(new GridData.SelectedCell(0,
0),
gridWidgetData.getSelectedCellsOrigin());
}

@Test
public void adjustSelectionLeftWithShiftKey() {
cellSelectionManager.selectCell(0,
Expand Down Expand Up @@ -468,6 +487,25 @@ public void adjustSelectionRightAndFindVisible() {
gridWidgetData.getSelectedCellsOrigin());
}

@Test
public void adjustSelectionRightOutOfBound() {
cellSelectionManager.selectCell(0,
2,
false,
false);
cellSelectionManager.adjustSelection(SelectionExtension.RIGHT,
false);

final List<GridData.SelectedCell> selectedCells = gridWidgetData.getSelectedCells();
assertEquals(1,
selectedCells.size());
assertTrue(selectedCells.contains(new GridData.SelectedCell(0,
2)));
assertEquals(new GridData.SelectedCell(0,
2),
gridWidgetData.getSelectedCellsOrigin());
}

@Test
public void adjustSelectionRightWithShiftKey() {
cellSelectionManager.selectCell(0,
Expand Down

0 comments on commit 1cf7020

Please sign in to comment.