Skip to content

Commit a144891

Browse files
committed
move getLatestSelection to GridSelectionMouseHandler
1 parent c43f306 commit a144891

File tree

3 files changed

+34
-34
lines changed

3 files changed

+34
-34
lines changed

Diff for: packages/iris-grid/src/mousehandlers/IrisGridContextMenuHandler.test.tsx renamed to packages/grid/src/mouse-handlers/GridSelectionMouseHandler.test.ts

+6-6
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
import { GridRange } from '@deephaven/grid';
2-
import IrisGridContextMenuHandler from './IrisGridContextMenuHandler';
1+
import { GridRange } from '../GridRange';
2+
import GridSelectionMouseHandler from './GridSelectionMouseHandler';
33

44
describe('getLatestSelection', () => {
55
it('should return the original selection if the clicked cell is within the original selection', () => {
66
const originalSelection = [new GridRange(1, 1, 2, 2)];
7-
const result = IrisGridContextMenuHandler.getLatestSelection(
7+
const result = GridSelectionMouseHandler.getLatestSelection(
88
originalSelection,
99
1,
1010
1
@@ -18,7 +18,7 @@ describe('getLatestSelection', () => {
1818
const columnIndex = 3;
1919
const rowIndex = 3;
2020

21-
const result = IrisGridContextMenuHandler.getLatestSelection(
21+
const result = GridSelectionMouseHandler.getLatestSelection(
2222
originalSelection,
2323
columnIndex,
2424
rowIndex
@@ -30,7 +30,7 @@ describe('getLatestSelection', () => {
3030
it('should return the original selection if columnIndex is null', () => {
3131
const originalSelection = [new GridRange(1, 1, 2, 2)];
3232

33-
const result = IrisGridContextMenuHandler.getLatestSelection(
33+
const result = GridSelectionMouseHandler.getLatestSelection(
3434
originalSelection,
3535
null,
3636
1
@@ -42,7 +42,7 @@ describe('getLatestSelection', () => {
4242
it('should return the original selection if rowIndex is null', () => {
4343
const originalSelection = [new GridRange(1, 1, 2, 2)];
4444

45-
const result = IrisGridContextMenuHandler.getLatestSelection(
45+
const result = GridSelectionMouseHandler.getLatestSelection(
4646
originalSelection,
4747
null,
4848
1

Diff for: packages/grid/src/mouse-handlers/GridSelectionMouseHandler.ts

+26-1
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,37 @@
11
import { type EventHandlerResult } from '../EventHandlerResult';
22
import type Grid from '../Grid';
33
import GridMouseHandler, { type GridMouseEvent } from '../GridMouseHandler';
4-
import GridRange from '../GridRange';
4+
import GridRange, { type GridRangeIndex } from '../GridRange';
55
import GridUtils, { type GridPoint } from '../GridUtils';
66

77
const DEFAULT_INTERVAL_MS = 100;
88

99
class GridSelectionMouseHandler extends GridMouseHandler {
10+
/**
11+
* Returns the latest grid selection based on the current grid selection and where the user clicked
12+
* This code is dependent on the behavior of onContextMenu
13+
* @param originalSelection The selection from the current grid state which may be stale
14+
* @param columnIndex The column index where the user clicked
15+
* @param rowIndex The row index where the user clicked
16+
*/
17+
static getLatestSelection(
18+
originalSelection: readonly GridRange[],
19+
columnIndex: GridRangeIndex,
20+
rowIndex: GridRangeIndex
21+
): readonly GridRange[] {
22+
const clickedInOriginalSelection = GridRange.containsCell(
23+
originalSelection,
24+
columnIndex,
25+
rowIndex
26+
);
27+
28+
// If the user clicked in a valid cell outside of the original selection,
29+
// the selection will be changed to just that cell.
30+
return clickedInOriginalSelection || columnIndex == null || rowIndex == null
31+
? originalSelection
32+
: [GridRange.makeCell(columnIndex, rowIndex)];
33+
}
34+
1035
private startPoint?: GridPoint;
1136

1237
private hasExtendedFloating = false;

Diff for: packages/iris-grid/src/mousehandlers/IrisGridContextMenuHandler.tsx

+2-27
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,8 @@ import {
2222
GridMouseHandler,
2323
type GridPoint,
2424
GridRange,
25-
type GridRangeIndex,
2625
GridRenderer,
26+
GridSelectionMouseHandler,
2727
isDeletableGridModel,
2828
isEditableGridModel,
2929
isExpandableGridModel,
@@ -150,31 +150,6 @@ class IrisGridContextMenuHandler extends GridMouseHandler {
150150
)}"`;
151151
}
152152

153-
/**
154-
* Returns the latest grid selection based on the current grid selection and where the user clicked
155-
* This code is dependent on the behavior of GridSelectionMouseHandler.onContextMenu
156-
* @param originalSelection The selection from the current grid state which may be stale
157-
* @param columnIndex The column index where the user clicked
158-
* @param rowIndex The row index where the user clicked
159-
*/
160-
static getLatestSelection(
161-
originalSelection: readonly GridRange[],
162-
columnIndex: GridRangeIndex,
163-
rowIndex: GridRangeIndex
164-
): readonly GridRange[] {
165-
const clickedInOriginalSelection = GridRange.containsCell(
166-
originalSelection,
167-
columnIndex,
168-
rowIndex
169-
);
170-
171-
// If the user clicked in a valid cell outside of the original selection,
172-
// the selection will be changed to just that cell.
173-
return clickedInOriginalSelection || columnIndex == null || rowIndex == null
174-
? originalSelection
175-
: [GridRange.makeCell(columnIndex, rowIndex)];
176-
}
177-
178153
irisGrid: IrisGrid;
179154

180155
debouncedUpdateCustomFormat: DebouncedFunc<
@@ -915,7 +890,7 @@ class IrisGridContextMenuHandler extends GridMouseHandler {
915890
selectedRanges: stateSelectedRanges,
916891
} = irisGrid.state;
917892

918-
const selectedRanges = IrisGridContextMenuHandler.getLatestSelection(
893+
const selectedRanges = GridSelectionMouseHandler.getLatestSelection(
919894
stateSelectedRanges,
920895
columnIndex,
921896
rowIndex

0 commit comments

Comments
 (0)