Skip to content

Commit

Permalink
feat: optimize cursor focus in readonly mode #936
Browse files Browse the repository at this point in the history
  • Loading branch information
Hufe921 committed Dec 21, 2024
1 parent aa2d3c7 commit 2e0ac96
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/editor/core/cursor/Cursor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down Expand Up @@ -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) {
Expand Down
5 changes: 5 additions & 0 deletions src/editor/utils/ua.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
)

0 comments on commit 2e0ac96

Please sign in to comment.