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(editor): Switch back to selection mode on window blur #13341

Merged
merged 1 commit into from
Feb 21, 2025
Merged
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
34 changes: 23 additions & 11 deletions packages/editor-ui/src/components/canvas/Canvas.vue
Original file line number Diff line number Diff line change
Expand Up @@ -154,22 +154,22 @@ const panningKeyCode = ref<string[] | true>(isMobileDevice ? true : [' ', contro
const panningMouseButton = ref<number[] | true>(isMobileDevice ? true : [1]);
const selectionKeyCode = ref<string | true | null>(isMobileDevice ? 'Shift' : true);

onKeyDown(
panningKeyCode.value,
() => {
selectionKeyCode.value = null;
panningMouseButton.value = [0, 1];
},
{
dedupe: true,
},
);
function switchToPanningMode() {
selectionKeyCode.value = null;
panningMouseButton.value = [0, 1];
}

onKeyUp(panningKeyCode.value, () => {
function switchToSelectionMode() {
selectionKeyCode.value = true;
panningMouseButton.value = [1];
}

onKeyDown(panningKeyCode.value, switchToPanningMode, {
dedupe: true,
});

onKeyUp(panningKeyCode.value, switchToSelectionMode);

/**
* Rename node key bindings
* We differentiate between short and long press because the space key is also used for activating panning
Expand Down Expand Up @@ -670,6 +670,14 @@ function onMinimapMouseLeave() {
hideMinimap();
}

/**
* Window Events
*/

function onWindowBlur() {
switchToSelectionMode();
}

/**
* Lifecycle
*/
Expand All @@ -679,11 +687,15 @@ const initialized = ref(false);
onMounted(() => {
props.eventBus.on('fitView', onFitView);
props.eventBus.on('nodes:select', onSelectNodes);

window.addEventListener('blur', onWindowBlur);
});

onUnmounted(() => {
props.eventBus.off('fitView', onFitView);
props.eventBus.off('nodes:select', onSelectNodes);

window.removeEventListener('blur', onWindowBlur);
});

onPaneReady(async () => {
Expand Down
Loading