Skip to content

fix(scene): fix vertex snap not cancelling on V key release#756

Open
bofeng-song wants to merge 1 commit into
cocos:mainfrom
bofeng-song:fix/vertex-snap-keyup
Open

fix(scene): fix vertex snap not cancelling on V key release#756
bofeng-song wants to merge 1 commit into
cocos:mainfrom
bofeng-song:fix/vertex-snap-keyup

Conversation

@bofeng-song

@bofeng-song bofeng-song commented Jul 15, 2026

Copy link
Copy Markdown
Contributor

Related issue: https://zentao.sud.center/index.php?m=bug&f=view&bugID=414

Summary

Vertex snapping (hold V) could not be cancelled by releasing the V key — the snap gizmo stayed active after key release.

Root cause

The engine's KeyboardInputSource._handleKeyboardUp calls event.stopPropagation() on every canvas keyup event. Since input-bridge.js registered its keyup listener on document (bubble phase), the stopped propagation meant the listener never fired.

In Creator this is not an issue because the engine runs inside a separate iframe/webview, so its stopPropagation() on the inner canvas does not affect the outer document's listeners. In the CLI, the engine and input-bridge.js share the same document context.

Fix

Switch the keyup listener from a normal document listener to capture phase (addEventListener('keyup', handler, true)). Capture runs top-down (window → document → ... → canvas) before the event reaches the canvas target, so it fires before the engine can stop propagation.

Test plan

  • Open scene editor, select a node with a mesh
  • Hold V → vertex snap activates (floating gizmo appears at nearest vertex)
  • Release V → vertex snap cancels (gizmo returns to node center, snap drag plane hides)
  • Repeat while moving mouse outside the canvas area during V hold — keyup should still be captured

The engine's KeyboardInputSource calls stopPropagation() on canvas
keyup events, which prevents them from bubbling to document. Switch
the keyup listener to capture phase so it fires top-down before the
event reaches the canvas.
@bofeng-song bofeng-song requested review from knoxHuang and star-e July 15, 2026 08:56
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.

2 participants