diff --git a/src/editor/core/cursor/Cursor.ts b/src/editor/core/cursor/Cursor.ts index 11950399..db08651a 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 f00193be..7ca65896 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 + )