fix(editor): can not query in mobile at menu (#11649)
This PR addresses an issue where queries cannot be performed in the mobile menu, particularly on Android devices. The root cause was that the `event.key` of keypress returns 'Unidentified' on Android, which prevented proper query handling. Changes made: - Replaced the keydown event observer with a beforeinput event listener - Removed unnecessary keyboard event handling code that was causing issues
This commit is contained in:
@@ -3,10 +3,7 @@ import {
|
|||||||
getTextContentFromInlineRange,
|
getTextContentFromInlineRange,
|
||||||
} from '@blocksuite/affine-rich-text';
|
} from '@blocksuite/affine-rich-text';
|
||||||
import { VirtualKeyboardProvider } from '@blocksuite/affine-shared/services';
|
import { VirtualKeyboardProvider } from '@blocksuite/affine-shared/services';
|
||||||
import {
|
import { getViewportElement } from '@blocksuite/affine-shared/utils';
|
||||||
createKeydownObserver,
|
|
||||||
getViewportElement,
|
|
||||||
} from '@blocksuite/affine-shared/utils';
|
|
||||||
import { SignalWatcher, WithDisposable } from '@blocksuite/global/lit';
|
import { SignalWatcher, WithDisposable } from '@blocksuite/global/lit';
|
||||||
import { MoreHorizontalIcon } from '@blocksuite/icons/lit';
|
import { MoreHorizontalIcon } from '@blocksuite/icons/lit';
|
||||||
import { PropTypes, requiredProperties } from '@blocksuite/std';
|
import { PropTypes, requiredProperties } from '@blocksuite/std';
|
||||||
@@ -36,8 +33,6 @@ export class AffineMobileLinkedDocMenu extends SignalWatcher(
|
|||||||
|
|
||||||
private readonly _expand = new Set<string>();
|
private readonly _expand = new Set<string>();
|
||||||
|
|
||||||
private _firstActionItem: LinkedMenuItem | null = null;
|
|
||||||
|
|
||||||
private readonly _linkedDocGroup$ = signal<LinkedMenuGroup[]>([]);
|
private readonly _linkedDocGroup$ = signal<LinkedMenuGroup[]>([]);
|
||||||
|
|
||||||
private readonly _renderGroup = (group: LinkedMenuGroup) => {
|
private readonly _renderGroup = (group: LinkedMenuGroup) => {
|
||||||
@@ -187,42 +182,14 @@ export class AffineMobileLinkedDocMenu extends SignalWatcher(
|
|||||||
const keydownObserverAbortController = new AbortController();
|
const keydownObserverAbortController = new AbortController();
|
||||||
this._disposables.add(() => keydownObserverAbortController.abort());
|
this._disposables.add(() => keydownObserverAbortController.abort());
|
||||||
|
|
||||||
createKeydownObserver({
|
// we need use beforeinput because the event.key of keypress event usually is `Unidentified` in Android
|
||||||
target: eventSource,
|
this.disposables.addFromEvent(eventSource, 'beforeinput', () => {
|
||||||
signal: keydownObserverAbortController.signal,
|
|
||||||
onInput: isComposition => {
|
|
||||||
if (isComposition) {
|
|
||||||
this._updateLinkedDocGroup().catch(console.error);
|
|
||||||
} else {
|
|
||||||
const subscription = inlineEditor.slots.renderComplete.subscribe(
|
|
||||||
() => {
|
|
||||||
subscription.unsubscribe();
|
|
||||||
this._updateLinkedDocGroup().catch(console.error);
|
|
||||||
}
|
|
||||||
);
|
|
||||||
}
|
|
||||||
},
|
|
||||||
onDelete: () => {
|
|
||||||
const subscription = inlineEditor.slots.renderComplete.subscribe(
|
|
||||||
() => {
|
|
||||||
subscription.unsubscribe();
|
|
||||||
const curRange = inlineEditor.getInlineRange();
|
const curRange = inlineEditor.getInlineRange();
|
||||||
|
if (curRange && curRange.index < this.context.startRange.index) {
|
||||||
if (!this.context.startRange || !curRange) return;
|
|
||||||
|
|
||||||
if (curRange.index < this.context.startRange.index) {
|
|
||||||
this.context.close();
|
this.context.close();
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
this._updateLinkedDocGroup().catch(console.error);
|
this._updateLinkedDocGroup().catch(console.error);
|
||||||
}
|
|
||||||
);
|
|
||||||
},
|
|
||||||
onConfirm: () => {
|
|
||||||
this._firstActionItem?.action()?.catch(console.error);
|
|
||||||
},
|
|
||||||
onAbort: () => {
|
|
||||||
this.context.close();
|
|
||||||
},
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -237,8 +204,6 @@ export class AffineMobileLinkedDocMenu extends SignalWatcher(
|
|||||||
return nothing;
|
return nothing;
|
||||||
}
|
}
|
||||||
|
|
||||||
this._firstActionItem = resolveSignal(groups[0].items)[0];
|
|
||||||
|
|
||||||
this.style.bottom = `${this.keyboard.height$.value}px`;
|
this.style.bottom = `${this.keyboard.height$.value}px`;
|
||||||
|
|
||||||
return html`
|
return html`
|
||||||
|
|||||||
Reference in New Issue
Block a user