0

这是一个有趣的问题。我希望用户能够选择多个元素并通过单击按钮为它们选择一个新标签。我当前的代码如下所示:

sel = editor.getSelection()
ranges = sel.getRanges()
# Iterate through the selection ranges
for range in ranges
    iterator = range.createIterator()
    paragraphs = []
    # Iterate through the blocks in the range
    while (block = iterator.getNextParagraph())
        # Undo the style if it's already applied 
        if (block.getName() == tagName) 
            tagName = 'p'
        paragraphs.push( block )
    if paragraphs.length
        # Create the new element
        bqBlock = editor.document.createElement(tagName)
        bqBlock.insertBefore( paragraphs[0] )
        # Move each child in the selection into the new element
        while ( paragraphs.length > 0 )
            block = paragraphs.shift()
            block.moveChildren(bqBlock)
            block.remove()

这很好用,除了选择被删除,这对用户非常不友好。我想保持原来的选择。

如果有内置的方法可以做到这一点,我正在使用 ckeditor。

编辑:

Reinmar 为我找到了答案: Set cursor to specific position in CKEditor

4

0 回答 0