本文整理匯總了TypeScript中draft-js.CharacterMetadata.applyEntity方法的典型用法代碼示例。如果您正苦於以下問題:TypeScript CharacterMetadata.applyEntity方法的具體用法?TypeScript CharacterMetadata.applyEntity怎麽用?TypeScript CharacterMetadata.applyEntity使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類draft-js.CharacterMetadata
的用法示例。
在下文中一共展示了CharacterMetadata.applyEntity方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。
示例1: flipIfBackwards
.when(createComment, (state: DocumentState, {text}) => {
const selection = flipIfBackwards(state.editor.getSelection())
const id = state.comments.length
const entityKey = Entity.create('Comment', 'MUTABLE', {id})
let content = state.editor.getCurrentContent()
if (selection.getAnchorKey() === selection.getFocusKey()) {
const start = selection.getAnchorOffset()
const end = selection.getFocusOffset()
let block = content.getBlockForKey(selection.getAnchorKey())
let chars = block.getCharacterList()
for (let i = start; i < end; i++) {
let metadata = chars.get(i)
metadata = CharacterMetadata.applyEntity(metadata, entityKey)
metadata = CharacterMetadata.applyStyle(metadata, 'comment')
chars = chars.set(i, metadata)
}
block = block.set('characterList', chars)
content = content.set('blockMap', content.getBlockMap().set(block.getKey(), block))
}
const comment = {id, entityKey, selection, text}
return Object.assign({}, state, {
editor: EditorState.push(state.editor, content, 'apply-entity'),
creatingComment: null,
comments: [...state.comments, comment],
})
})