From 2e0ac966e839a2dc9df911b04d24577c46d930e4 Mon Sep 17 00:00:00 2001 From: Hufe921 Date: Sat, 21 Dec 2024 16:37:45 +0800 Subject: [PATCH] feat: optimize cursor focus in readonly mode #936 --- src/editor/core/cursor/Cursor.ts | 3 +++ src/editor/utils/ua.ts | 5 +++++ 2 files changed, 8 insertions(+) diff --git a/src/editor/core/cursor/Cursor.ts b/src/editor/core/cursor/Cursor.ts index 119503990..db08651aa 100644 --- a/src/editor/core/cursor/Cursor.ts +++ b/src/editor/core/cursor/Cursor.ts @@ -6,6 +6,7 @@ import { ICursorOption } from '../../interface/Cursor' import { IEditorOption } from '../../interface/Editor' import { IElementPosition } from '../../interface/Element' import { findScrollContainer } from '../../utils' +import { isMobile } from '../../utils/ua' import { Draw } from '../draw/Draw' import { CanvasEvent } from '../event/CanvasEvent' import { Position } from '../position/Position' @@ -91,6 +92,8 @@ export class Cursor { } public focus() { + // 移动端只读模式禁用聚焦避免唤起输入法,web端允许聚焦避免事件无法捕获 + if (isMobile && this.draw.isReadonly()) return const agentCursorDom = this.cursorAgent.getAgentCursorDom() // 光标不聚焦时重新定位 if (document.activeElement !== agentCursorDom) { diff --git a/src/editor/utils/ua.ts b/src/editor/utils/ua.ts index f00193be0..7ca658963 100644 --- a/src/editor/utils/ua.ts +++ b/src/editor/utils/ua.ts @@ -3,3 +3,8 @@ export const isApple = export const isIOS = typeof navigator !== 'undefined' && /iPad|iPhone/.test(navigator.userAgent) + +export const isMobile = + /Mobile|Android|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test( + navigator.userAgent + )