Skip to content

Commit

Permalink
fix: 拼音隐藏 placeholder
Browse files Browse the repository at this point in the history
  • Loading branch information
wangfupeng1988 committed Sep 22, 2021
1 parent 68b03e4 commit aec1a9f
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 4 deletions.
2 changes: 1 addition & 1 deletion packages/core/src/text-area/TextArea.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import { TEXTAREA_TO_EDITOR } from '../utils/weak-maps'
import { IDomEditor } from '../editor/interface'
import { DomEditor } from '../editor/dom-editor'
import updateView from './update-view'
import handlePlaceholder from './place-holder'
import { handlePlaceholder } from './place-holder'
import { editorSelectionToDOM, DOMSelectionToEditor } from './syncSelection'
import { promiseResolveThen } from '../utils/util'
import eventHandlerConf from './event-handlers/index'
Expand Down
4 changes: 4 additions & 0 deletions packages/core/src/text-area/event-handlers/composition.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import TextArea from '../TextArea'
import { hasEditableTarget } from '../helpers'
import { IS_SAFARI, IS_CHROME, IS_FIREFOX } from '../../utils/ua'
import { DOMNode } from '../../utils/dom'
import { hidePlaceholder } from '../place-holder'

const EDITOR_TO_TEXT: WeakMap<IDomEditor, string> = new WeakMap()
const EDITOR_TO_START_CONTAINER: WeakMap<IDomEditor, DOMNode> = new WeakMap()
Expand Down Expand Up @@ -38,6 +39,9 @@ export function handleCompositionStart(e: Event, textarea: TextArea, editor: IDo
EDITOR_TO_START_CONTAINER.set(editor, startContainer)
}
textarea.isComposing = true

// 隐藏 placeholder
hidePlaceholder(textarea, editor)
}

/**
Expand Down
21 changes: 18 additions & 3 deletions packages/core/src/text-area/place-holder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
*/

import { IDomEditor } from '../editor/interface'
import { DomEditor } from '../editor/dom-editor'
import TextArea from './TextArea'
import $ from '../utils/dom'

Expand All @@ -13,7 +12,7 @@ import $ from '../utils/dom'
* @param textarea textarea
* @param editor editor
*/
function handlePlaceholder(textarea: TextArea, editor: IDomEditor) {
export function handlePlaceholder(textarea: TextArea, editor: IDomEditor) {
const { placeholder } = editor.getConfig()
if (!placeholder) return

Expand All @@ -39,4 +38,20 @@ function handlePlaceholder(textarea: TextArea, editor: IDomEditor) {
}
}

export default handlePlaceholder
/**
* 隐藏 placeholder (如拼音输入 compositionStart 时,要先隐藏,等 compositionEnd 时再判断是否显示)
* @param textarea textarea
* @param editor editor
*/
export function hidePlaceholder(textarea: TextArea, editor: IDomEditor) {
const { placeholder } = editor.getConfig()
if (!placeholder) return

const isEmpty = editor.isEmpty()
if (!isEmpty) return

if (textarea.showPlaceholder) {
textarea.$placeholder?.hide()
textarea.showPlaceholder = false // 记录
}
}
2 changes: 2 additions & 0 deletions packages/editor/examples/default-mode.html
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,8 @@
console.log('on created', editor)
}
editorConfig.onChange = (editor) => {
// console.log(editor.children)

const html = editor.getHtml()
document.getElementById('editor-content-view').innerHTML = html

Expand Down

0 comments on commit aec1a9f

Please sign in to comment.