Skip to content

Commit aa20e7b

Browse files
authored
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 -->
1 parent 01e8458 commit aa20e7b

File tree

2 files changed

+14
-9
lines changed
  • blocksuite/affine/gfx/pointer/src/tools
  • packages/frontend/core/src/blocksuite/ai/widgets/ai-panel

2 files changed

+14
-9
lines changed

blocksuite/affine/gfx/pointer/src/tools/pan-tool.ts

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
1-
import { EdgelessLegacySlotIdentifier } from '@blocksuite/affine-block-surface';
1+
import {
2+
DefaultTool,
3+
EdgelessLegacySlotIdentifier,
4+
} from '@blocksuite/affine-block-surface';
25
import { on } from '@blocksuite/affine-shared/utils';
36
import type { PointerEventState } from '@blocksuite/std';
47
import { BaseTool, MouseButton, type ToolOptions } from '@blocksuite/std/gfx';
@@ -64,12 +67,15 @@ export class PanTool extends BaseTool<PanToolOption> {
6467
const { toolType, options: originalToolOptions } = currentTool;
6568
const selectionToRestore = this.gfx.selection.surfaceSelections;
6669
if (!toolType) return;
70+
// restore to DefaultTool if previous tool is CopilotTool
71+
if (toolType.toolName === 'copilot') {
72+
this.controller.setTool(DefaultTool);
73+
return;
74+
}
6775

6876
let finalOptions: ToolOptions<BaseTool<any>> | undefined =
6977
originalToolOptions;
70-
const PRESENT_TOOL_NAME = 'frameNavigator';
71-
72-
if (toolType.toolName === PRESENT_TOOL_NAME) {
78+
if (toolType.toolName === 'frameNavigator') {
7379
// When restoring PresentTool (frameNavigator) after a temporary pan (e.g., via middle mouse button),
7480
// set 'restoredAfterPan' to true. This allows PresentTool to avoid an unwanted viewport reset
7581
// and maintain the panned position.
@@ -93,8 +99,10 @@ export class PanTool extends BaseTool<PanToolOption> {
9399
});
94100
}
95101

96-
this.controller.setTool(PanTool, {
97-
panning: true,
102+
requestAnimationFrame(() => {
103+
this.controller.setTool(PanTool, {
104+
panning: true,
105+
});
98106
});
99107

100108
const dispose = on(document, 'pointerup', evt => {

packages/frontend/core/src/blocksuite/ai/widgets/ai-panel/ai-panel.ts

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -141,10 +141,7 @@ export class AffineAIPanelWidget extends WidgetComponent {
141141
!this.contains(e.target as Node)
142142
) {
143143
this._clickOutside();
144-
return true;
145144
}
146-
147-
return false;
148145
};
149146

150147
private readonly _onKeyDown = (event: KeyboardEvent) => {

0 commit comments

Comments
 (0)