提交 991f26a8 编写于 作者: D DCloud_LXH

fix: editor 设置格式后,ios中文输入法输入状态 placeholder 不隐藏 question/106127

上级 7c3b8659
......@@ -8,7 +8,7 @@ import QuillClass, {
} from 'quill'
import { LINEFEED } from '@dcloudio/uni-shared'
import { useContextInfo, useSubscribe } from '@dcloudio/uni-components'
import { getRealPath } from '@dcloudio/uni-platform'
import { getRealPath, getBaseSystemInfo } from '@dcloudio/uni-platform'
import { CustomEventTrigger } from '../../../helpers/useEvent'
import HTMLParser from '../../../helpers/html-parser'
import loadScript from './loadScript'
......@@ -85,7 +85,7 @@ export function useQuill(
() => props.placeholder,
(value) => {
if (quillReady) {
quill.root.setAttribute('data-placeholder', value)
setPlaceHolder(value)
}
}
)
......@@ -159,6 +159,12 @@ export function useQuill(
delta,
}
}
function setPlaceHolder(placeholder: string) {
const placeHolderAttrName = 'data-placeholder'
const QuillRoot = quill.root
QuillRoot.getAttribute(placeHolderAttrName) !== placeholder &&
QuillRoot.setAttribute(placeHolderAttrName, placeholder)
}
let oldStatus: StringMap = {}
function updateStatus(range?: RangeStatic) {
const status = range ? quill.getFormat(range) : {}
......@@ -196,10 +202,21 @@ export function useQuill(
const events = ['focus', 'blur', 'input']
events.forEach((name) => {
$el.addEventListener(name, ($event) => {
const contents = getContents()
if (name === 'input') {
if (getBaseSystemInfo().platform === 'ios') {
const regExpContent = (contents.html.match(
/<span [\s\S]*>([\s\S]*)<\/span>/
) || [])[1]
const placeholder =
regExpContent && regExpContent.replace(/\s/g, '')
? ''
: props.placeholder
setPlaceHolder(placeholder)
}
$event.stopPropagation()
} else {
trigger(name, $event, getContents())
trigger(name, $event, contents)
}
})
})
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册