fix(editor): tool panel not closed when user close keyboard with default gesture in android (#12613)

Close [BS-3159](https://linear.app/affine-design/issue/BS-3159/输入法自带的键盘收起操作后-占位符还留着)

<!-- This is an auto-generated comment: release notes by coderabbit.ai -->

## Summary by CodeRabbit

- **Bug Fixes**
  - The toolbar now automatically closes when the keyboard is dismissed and no panel is open, ensuring smoother user experience.
  - Improved cleanup to prevent delayed actions after the toolbar is closed, enhancing stability.

<!-- end of auto-generated comment: release notes by coderabbit.ai -->
This commit is contained in:
L-Sun
2025-05-28 10:55:32 +00:00
parent d4c5b40284
commit 9a651a5b53

View File

@@ -8,7 +8,7 @@ import {
requiredProperties, requiredProperties,
ShadowlessElement, ShadowlessElement,
} from '@blocksuite/std'; } from '@blocksuite/std';
import { effect, type Signal, signal } from '@preact/signals-core'; import { effect, type Signal, signal, untracked } from '@preact/signals-core';
import { html } from 'lit'; import { html } from 'lit';
import { property } from 'lit/decorators.js'; import { property } from 'lit/decorators.js';
import { repeat } from 'lit/directives/repeat.js'; import { repeat } from 'lit/directives/repeat.js';
@@ -260,6 +260,11 @@ export class AffineKeyboardToolbar extends SignalWatcher(
if (this.keyboard.visible$.value) { if (this.keyboard.visible$.value) {
this._closeToolPanel(); this._closeToolPanel();
} }
// when keyboard is closed and the panel is not opened, we need to close the toolbar,
// this usually happens when user close keyboard from system side
else if (this.hasUpdated && untracked(() => !this.panelOpened)) {
this.close(true);
}
}) })
); );
@@ -308,9 +313,12 @@ export class AffineKeyboardToolbar extends SignalWatcher(
override firstUpdated() { override firstUpdated() {
// workaround for the virtual keyboard showing transition animation // workaround for the virtual keyboard showing transition animation
setTimeout(() => { const timeoutId = setTimeout(() => {
this._scrollCurrentBlockIntoView(); this._scrollCurrentBlockIntoView();
}, 700); }, 700);
this.disposables.add(() => {
clearTimeout(timeoutId);
});
} }
override render() { override render() {