Skip to content

Commit

Permalink
provide which key activated cell overlay
Browse files Browse the repository at this point in the history
  • Loading branch information
BrianHung committed Jul 2, 2024
1 parent 5983dca commit b0d35d2
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 5 deletions.
1 change: 1 addition & 0 deletions packages/core/API.md
Original file line number Diff line number Diff line change
Expand Up @@ -556,6 +556,7 @@ export type ProvideEditorComponent<T extends InnerGridCell> = React.FunctionComp
readonly markdownDivCreateNode?: (content: string) => DocumentFragment;
readonly target: Rectangle;
readonly forceEditMode: boolean;
readonly key?: string;
readonly isValid?: boolean;
}>;

Expand Down
15 changes: 10 additions & 5 deletions packages/core/src/data-editor/data-editor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -742,10 +742,11 @@ const DataEditorImpl: React.ForwardRefRenderFunction<DataEditorRef, DataEditorPr
target: Rectangle;
content: GridCell;
theme: FullTheme;
initialValue: string | undefined;
initialValue?: string;
cell: Item;
highlight: boolean;
forceEditMode: boolean;
key?: string;
}>();
const searchInputRef = React.useRef<HTMLInputElement | null>(null);
const canvasRef = React.useRef<HTMLCanvasElement | null>(null);
Expand Down Expand Up @@ -1405,9 +1406,12 @@ const DataEditorImpl: React.ForwardRefRenderFunction<DataEditorRef, DataEditorPr
);

const reselect = React.useCallback(
(bounds: Rectangle, fromKeyboard: boolean, initialValue?: string) => {
(bounds: Rectangle, key?: string) => {
if (gridSelection.current === undefined) return;

const fromKeyboard = key !== undefined;
const initialValue = key?.length === 1 ? key : undefined; // Ignore activateCell keys.

const [col, row] = gridSelection.current.cell;
const c = getMangledCellContent([col, row]);
if (c.kind !== GridCellKind.Boolean && c.allowOverlay) {
Expand Down Expand Up @@ -1440,6 +1444,7 @@ const DataEditorImpl: React.ForwardRefRenderFunction<DataEditorRef, DataEditorPr
cell: [col, row],
highlight: initialValue === undefined,
forceEditMode: initialValue !== undefined,
key,
});
} else if (c.kind === GridCellKind.Boolean && fromKeyboard && c.readonly !== true) {
mangledOnCellsEdited([
Expand Down Expand Up @@ -2299,7 +2304,7 @@ const DataEditorImpl: React.ForwardRefRenderFunction<DataEditorRef, DataEditorPr
}
if (shouldActivate) {
onCellActivated?.([col - rowMarkerOffset, row]);
reselect(a.bounds, false);
reselect(a.bounds);
return true;
}
}
Expand Down Expand Up @@ -3144,7 +3149,7 @@ const DataEditorImpl: React.ForwardRefRenderFunction<DataEditorRef, DataEditorPr
}, 0);
} else {
onCellActivated?.([col - rowMarkerOffset, row]);
reselect(bounds, true);
reselect(bounds, event.key);
}
} else if (gridSelection.current.range.height > 1 && isHotkey(keys.downFill, event, details)) {
fillDown();
Expand Down Expand Up @@ -3352,7 +3357,7 @@ const DataEditorImpl: React.ForwardRefRenderFunction<DataEditorRef, DataEditorPr
) {
return;
}
reselect(event.bounds, true, event.key);
reselect(event.bounds, event.key);
event.stopPropagation();
event.preventDefault();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ interface DataGridOverlayEditorProps {
readonly theme: Theme;
readonly onFinishEditing: (newCell: GridCell | undefined, movement: readonly [-1 | 0 | 1, -1 | 0 | 1]) => void;
readonly forceEditMode: boolean;
readonly key?: string;
readonly highlight: boolean;
readonly imageEditorOverride?: ImageEditorType;
readonly getCellRenderer: GetCellRendererCallback;
Expand All @@ -52,6 +53,7 @@ const DataGridOverlayEditor: React.FunctionComponent<DataGridOverlayEditorProps>
content,
onFinishEditing: onFinishEditingIn,
forceEditMode,
key,
initialValue,
imageEditorOverride,
markdownDivCreateNode,
Expand Down Expand Up @@ -179,6 +181,7 @@ const DataGridOverlayEditor: React.FunctionComponent<DataGridOverlayEditorProps>
onFinishedEditing={onEditorFinished}
validatedSelection={isEditableGridCell(targetValue) ? targetValue.selectionRange : undefined}
forceEditMode={forceEditMode}
key={key}
target={target}
imageEditorOverride={imageEditorOverride}
markdownDivCreateNode={markdownDivCreateNode}
Expand Down
1 change: 1 addition & 0 deletions packages/core/src/internal/data-grid/data-grid-types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -391,6 +391,7 @@ export type ProvideEditorComponent<T extends InnerGridCell> = React.FunctionComp
readonly markdownDivCreateNode?: (content: string) => DocumentFragment;
readonly target: Rectangle;
readonly forceEditMode: boolean;
readonly key?: string;
readonly isValid?: boolean;
readonly theme: Theme;
}>;
Expand Down

0 comments on commit b0d35d2

Please sign in to comment.