Skip to content

Enable cursor support - #225

Merged
dubstar-04 merged 4 commits into
mainfrom
feature/cursor-state
Apr 5, 2026
Merged

Enable cursor support#225
dubstar-04 merged 4 commits into
mainfrom
feature/cursor-state

Conversation

@dubstar-04

Copy link
Copy Markdown
Owner

Complementary PR dubstar-04/Design-Core#260

fixes #10

@dubstar-04
dubstar-04 marked this pull request as ready for review April 5, 2026 08:09
@dubstar-04
dubstar-04 requested a review from Copilot April 5, 2026 08:09

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds UI-level cursor support to the canvas component so the core can drive cursor changes (aimed at improving CAD-style interaction per Issue #10).

Changes:

  • Register a cursor-change callback with core.canvas on mount and when core changes.
  • Add onCursorChange to map cursor “states” to CSS cursor values.
  • Unregister the cursor callback on unmount.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@@ -29,13 +32,25 @@ export default class Canvas extends Component{
componentDidUpdate(prevProps) {
if (prevProps.core !== this.props.core) {

Copilot AI Apr 5, 2026

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When core changes, the previous prevProps.core.canvas still retains the old cursor callback. That can keep this component alive and can also trigger onCursorChange after the canvas is no longer the active core (or after unmount), leading to errors. Clear the cursor callback on prevProps.core.canvas before registering the new one (mirroring cleanup done in componentWillUnmount).

Suggested change
if (prevProps.core !== this.props.core) {
if (prevProps.core !== this.props.core) {
prevProps.core.canvas.setCursorCallbackFunction(undefined);

Copilot uses AI. Check for mistakes.
Comment on lines +18 to +20
// set the cursor callback
this.props.core.canvas.setCursorCallbackFunction(this.onCursorChange.bind(this))

Copilot AI Apr 5, 2026

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this.onCursorChange.bind(this) creates a new function each time componentDidMount/componentDidUpdate runs. Consider binding once (e.g., this.boundOnCursorChange = this.onCursorChange.bind(this) in the constructor) and reusing that reference when registering/unregistering the callback; this avoids repeated allocations and makes cleanup reliable if the core API expects the same function reference.

Copilot uses AI. Check for mistakes.
GRABBING: 'grabbing',
SELECTION: 'cell',
};
this.canvasRef.current.style.cursor = cursors[state] ?? 'crosshair';

Copilot AI Apr 5, 2026

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

onCursorChange assumes this.canvasRef.current is always available. If a cursor update arrives after unmount (or while swapping cores), this will throw. Add a quick guard (e.g., return early when the ref is missing) to make the callback resilient.

Suggested change
this.canvasRef.current.style.cursor = cursors[state] ?? 'crosshair';
const canvas = this.canvasRef.current;
if (!canvas) {
return;
}
canvas.style.cursor = cursors[state] ?? 'crosshair';

Copilot uses AI. Check for mistakes.
@dubstar-04
dubstar-04 merged commit a7b7fac into main Apr 5, 2026
1 check passed
@dubstar-04
dubstar-04 deleted the feature/cursor-state branch April 5, 2026 09:08
@dubstar-04
dubstar-04 restored the feature/cursor-state branch April 7, 2026 05:40
@dubstar-04
dubstar-04 deleted the feature/cursor-state branch April 7, 2026 06:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Improve cursor design for CAD use

2 participants