The*_*eed 2 ckeditor ckeditor5
我已经成功地为ckeditor 5创建了一个插件,该插件允许用户从页面中选择一个或多个以前的帖子,并在单击“应用引号”按钮后将其插入到编辑器视图中,一个又一个地作为块引用。
效果很好,但是,我希望光标位于最后一个blockquote之后的新行上,以便用户可以添加自己的注释。
我尝试在段落列表中附加一个段落标签,但是在最后一个引号之内而不是之后,它以新段落的形式出现。
有人对此有解决方案吗?
我编写了一个简单的函数,在编辑器中添加了引号和用于用户回复的段落。
/**
* @param {String} author An author of the message.
* @param {String} message A message that will be quoted.
*/
function replyTo( author, message ) {
// window.editor must be an instance of the editor.
editor.model.change( writer => {
const root = editor.model.document.getRoot();
const blockQuote = writer.createElement( 'blockQuote' );
const authorParagraph = writer.createElement( 'paragraph' );
const messageParagraph = writer.createElement( 'paragraph' );
// Inserts: "Author wrote:" as bold and italic text.
writer.insertText( `${ author } wrote:`, { bold: true, italic: true }, authorParagraph );
// Inserts the message.
writer.insertText( message, messageParagraph );
// Appends "Author wrote" and the message to block quote.
writer.append( authorParagraph, blockQuote );
writer.append( messageParagraph, blockQuote );
// A paragraph that allows typing below the block quote.
const replyParagraph = writer.createElement( 'paragraph' );
// Appends the block quote to editor.
writer.append( blockQuote, root );
// Appends the reply paragraph below the block quote.
writer.append( replyParagraph, root );
// Removes the initial paragraph from the editor.
writer.remove( root.getChild( 0 ) );
// And place selection inside the paragraph.
writer.setSelection( replyParagraph, 'in' );
} );
editor.editing.view.focus();
}
Run Code Online (Sandbox Code Playgroud)
如果您对如何将其调整为自己的代码有疑问,我想看看您编写的代码。它可以帮助您了解自己的所作所为。
当然,您可以将建议的代码视为在线演示– https://jsfiddle.net/pomek/s2yjug64/
| 归档时间: |
|
| 查看次数: |
270 次 |
| 最近记录: |