fix(core): copilot tool restore (#13470)
Close [AI-410](https://linear.app/affine-design/issue/AI-410) <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit - New Features - None - Bug Fixes - Middle-click panning now reliably returns to the previously active tool, including after using Copilot or frame navigation. - Smoother, more responsive transition into panning to reduce accidental selections. - Refactor - Simplified AI panel click-outside handling with no change to user-visible behavior. <!-- end of auto-generated comment: release notes by coderabbit.ai -->
This commit is contained in:
@@ -1,4 +1,7 @@
|
|||||||
import { EdgelessLegacySlotIdentifier } from '@blocksuite/affine-block-surface';
|
import {
|
||||||
|
DefaultTool,
|
||||||
|
EdgelessLegacySlotIdentifier,
|
||||||
|
} from '@blocksuite/affine-block-surface';
|
||||||
import { on } from '@blocksuite/affine-shared/utils';
|
import { on } from '@blocksuite/affine-shared/utils';
|
||||||
import type { PointerEventState } from '@blocksuite/std';
|
import type { PointerEventState } from '@blocksuite/std';
|
||||||
import { BaseTool, MouseButton, type ToolOptions } from '@blocksuite/std/gfx';
|
import { BaseTool, MouseButton, type ToolOptions } from '@blocksuite/std/gfx';
|
||||||
@@ -64,12 +67,15 @@ export class PanTool extends BaseTool<PanToolOption> {
|
|||||||
const { toolType, options: originalToolOptions } = currentTool;
|
const { toolType, options: originalToolOptions } = currentTool;
|
||||||
const selectionToRestore = this.gfx.selection.surfaceSelections;
|
const selectionToRestore = this.gfx.selection.surfaceSelections;
|
||||||
if (!toolType) return;
|
if (!toolType) return;
|
||||||
|
// restore to DefaultTool if previous tool is CopilotTool
|
||||||
|
if (toolType.toolName === 'copilot') {
|
||||||
|
this.controller.setTool(DefaultTool);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
let finalOptions: ToolOptions<BaseTool<any>> | undefined =
|
let finalOptions: ToolOptions<BaseTool<any>> | undefined =
|
||||||
originalToolOptions;
|
originalToolOptions;
|
||||||
const PRESENT_TOOL_NAME = 'frameNavigator';
|
if (toolType.toolName === 'frameNavigator') {
|
||||||
|
|
||||||
if (toolType.toolName === PRESENT_TOOL_NAME) {
|
|
||||||
// When restoring PresentTool (frameNavigator) after a temporary pan (e.g., via middle mouse button),
|
// When restoring PresentTool (frameNavigator) after a temporary pan (e.g., via middle mouse button),
|
||||||
// set 'restoredAfterPan' to true. This allows PresentTool to avoid an unwanted viewport reset
|
// set 'restoredAfterPan' to true. This allows PresentTool to avoid an unwanted viewport reset
|
||||||
// and maintain the panned position.
|
// and maintain the panned position.
|
||||||
@@ -93,9 +99,11 @@ export class PanTool extends BaseTool<PanToolOption> {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
requestAnimationFrame(() => {
|
||||||
this.controller.setTool(PanTool, {
|
this.controller.setTool(PanTool, {
|
||||||
panning: true,
|
panning: true,
|
||||||
});
|
});
|
||||||
|
});
|
||||||
|
|
||||||
const dispose = on(document, 'pointerup', evt => {
|
const dispose = on(document, 'pointerup', evt => {
|
||||||
if (evt.button === MouseButton.MIDDLE) {
|
if (evt.button === MouseButton.MIDDLE) {
|
||||||
|
|||||||
@@ -141,10 +141,7 @@ export class AffineAIPanelWidget extends WidgetComponent {
|
|||||||
!this.contains(e.target as Node)
|
!this.contains(e.target as Node)
|
||||||
) {
|
) {
|
||||||
this._clickOutside();
|
this._clickOutside();
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return false;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
private readonly _onKeyDown = (event: KeyboardEvent) => {
|
private readonly _onKeyDown = (event: KeyboardEvent) => {
|
||||||
|
|||||||
Reference in New Issue
Block a user