Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: show copy cursor in grid on key down and not just mouse move #1735

Merged
merged 5 commits into from
Feb 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 0 additions & 15 deletions packages/code-studio/src/assets/svg/cursor-copy.svg

This file was deleted.

28 changes: 0 additions & 28 deletions packages/code-studio/src/main/AppMainContainer.scss
Original file line number Diff line number Diff line change
Expand Up @@ -9,34 +9,6 @@ $tab-link-disabled-color: $gray-600;

$nav-space: 4px; // give a gap around some buttons for focus area that are in nav bar

.grid-cursor-copy {
cursor:
url('../assets/svg/cursor-copy.svg') 8 8,
copy;
}

.grid-cursor-linker {
cursor:
url('../assets/svg/cursor-linker.svg') 8 8,
crosshair;
}

.grid-cursor-linker-not-allowed {
cursor:
url('../assets/svg/cursor-linker-not-allowed.svg') 8 8,
not-allowed;
}

.linker-overlay path.link-select {
cursor: pointer;
}

.linker-overlay.danger-delete path.link-select {
cursor:
url('../assets/svg/cursor-unlinker.svg') 8 8,
pointer;
}

.app-main-top-nav-menus {
display: flex;
width: 100%;
Expand Down
2 changes: 1 addition & 1 deletion packages/components/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@
"dist",
"scss",
"css",
"logos"
"assets"
],
"sideEffects": [
"*.css"
Expand Down
4 changes: 2 additions & 2 deletions packages/components/src/theme/Logo.css
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
:root {
--dh-logo-dark-img: url('../../logos/community-wordmark-dark.svg');
--dh-logo-light-img: url('../../logos/community-wordmark-light.svg');
--dh-logo-dark-img: url('../../assets/logos/community-wordmark-dark.svg');
--dh-logo-light-img: url('../../assets/logos/community-wordmark-light.svg');
}

.dh-logo {
Expand Down
3 changes: 2 additions & 1 deletion packages/dashboard-core-plugins/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,8 @@
"@deephaven/mocks": "file:../mocks"
},
"files": [
"dist"
"dist",
"assets"
],
"sideEffects": [
"*.css"
Expand Down
6 changes: 6 additions & 0 deletions packages/dashboard-core-plugins/src/linker/LinkerLink.scss
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,12 @@ $dash-size: 10;
}

&.danger-delete {
path.link-select {
cursor:
url('../assets/svg/cursor-unlinker.svg') 8 8,
pointer;
}

path.link-select:hover ~ path.link-background {
stroke: $dash-delete-color-2;
}
Expand Down
8 changes: 0 additions & 8 deletions packages/dashboard-core-plugins/src/panels/IrisGridPanel.scss
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,3 @@ $panel-message-overlay-top: 30px;
color: $danger;
}
}

.grid-cursor-linker {
cursor: crosshair;
}

.grid-cursor-copy {
cursor: copy;
}
5 changes: 5 additions & 0 deletions packages/grid/src/Grid.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -1729,18 +1729,23 @@ class Grid extends PureComponent<GridProps, GridState> {
event: GridKeyboardEvent
): void {
const keyHandlers = this.getKeyHandlers();
let cursor = null;
for (let i = 0; i < keyHandlers.length; i += 1) {
const keyHandler = keyHandlers[i];
const result =
keyHandler[functionName] != null &&
keyHandler[functionName](event, this);
if (result !== false) {
if (keyHandler.cursor != null) {
({ cursor } = keyHandler);
}
const options = result as EventHandlerResultOptions;
if (options?.stopPropagation ?? true) event.stopPropagation();
if (options?.preventDefault ?? true) event.preventDefault();
break;
}
}
this.setState({ cursor });
}

handleKeyDown(event: GridKeyboardEvent): void {
Expand Down
3 changes: 3 additions & 0 deletions packages/grid/src/KeyHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@ export class KeyHandler {
this.order = order;
}

// Cursor to use if this returns any truthy value including { stopPropagation: false, preventDefault: false }
cursor: string | null = null;

/**
* Handle a keydown event on the grid.
* @param event The keyboard event
Expand Down
14 changes: 14 additions & 0 deletions packages/iris-grid/assets/svg/cursor-copy.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 2 additions & 1 deletion packages/iris-grid/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,8 @@
"@deephaven/mocks": "file:../mocks"
},
"files": [
"dist"
"dist",
"assets"
],
"sideEffects": [
"*.css"
Expand Down
18 changes: 18 additions & 0 deletions packages/iris-grid/src/IrisGrid.scss
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,24 @@ $cell-invalid-box-shadow:
position: relative;
}

.grid-cursor-copy {
cursor:
url('../assets/svg/cursor-copy.svg') 8 8,
copy;
}

.grid-cursor-linker {
cursor:
url('../assets/svg/cursor-linker.svg') 8 8,
crosshair;
}

.grid-cursor-linker-not-allowed {
cursor:
url('../assets/svg/cursor-linker-not-allowed.svg') 8 8,
not-allowed;
}

.table-sidebar {
height: 100%;
flex: 0 0 $table-sidebar-max-width;
Expand Down
4 changes: 3 additions & 1 deletion packages/iris-grid/src/IrisGrid.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@ import PendingDataBottomBar from './PendingDataBottomBar';
import IrisGridCopyHandler, { CopyOperation } from './IrisGridCopyHandler';
import FilterInputField from './FilterInputField';
import {
CopyCellKeyHandler,
ClearFilterKeyHandler,
CopyKeyHandler,
ReverseKeyHandler,
Expand Down Expand Up @@ -489,7 +490,7 @@ export class IrisGrid extends Component<IrisGridProps, IrisGridState> {
columnSelectionValidator: null,
columnAllowedCursor: null,
columnNotAllowedCursor: null,
copyCursor: null,
copyCursor: 'copy',
name: 'table',
onlyFetchVisibleColumns: true,
showSearchBar: false,
Expand Down Expand Up @@ -703,6 +704,7 @@ export class IrisGrid extends Component<IrisGridProps, IrisGridState> {

const { dh } = model;
const keyHandlers: KeyHandler[] = [
new CopyCellKeyHandler(this),
new ReverseKeyHandler(this),
new ClearFilterKeyHandler(this),
];
Expand Down
45 changes: 45 additions & 0 deletions packages/iris-grid/src/key-handlers/CopyCellKeyHandler.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
import { KeyboardEvent } from 'react';
import { KeyHandler } from '@deephaven/grid';
import { ContextActionUtils } from '@deephaven/components';
import type { Grid } from '@deephaven/grid';
import { IrisGrid } from '../IrisGrid';

class CopyCellKeyHandler extends KeyHandler {
private irisGrid: IrisGrid;

constructor(irisGrid: IrisGrid) {
super();

this.irisGrid = irisGrid;
this.cursor = null;
}

onDown(event: KeyboardEvent, grid: Grid): boolean {
if (
event.altKey &&
!ContextActionUtils.isModifierKeyDown(event) &&
!event.shiftKey
) {
const { mouseX, mouseY } = grid.state;
if (mouseX == null || mouseY == null) {
return false;
}
const gridPoint = grid.getGridPointFromXY(mouseX, mouseY);
if (gridPoint.column != null && gridPoint.row != null) {
this.cursor = this.irisGrid.props.copyCursor;
return true;
}
}
return false;
}

onUp(event: KeyboardEvent, grid: Grid): boolean {
if (this.cursor === this.irisGrid.props.copyCursor) {
this.cursor = null;
return true;
}
return false;
}
}

export default CopyCellKeyHandler;
1 change: 1 addition & 0 deletions packages/iris-grid/src/key-handlers/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
export { default as CopyCellKeyHandler } from './CopyCellKeyHandler';
export { default as CopyKeyHandler } from './CopyKeyHandler';
export { default as ReverseKeyHandler } from './ReverseKeyHandler';
export { default as ClearFilterKeyHandler } from './ClearFilterKeyHandler';
Loading