📅  最后修改于: 2023-12-03 14:40:05.941000             🧑  作者: Mango
CKEditor is a powerful web-based WYSIWYG editor that allows users to easily create and edit content. One of the great features of CKEditor is the ability to push text in front of the cursor using CSS. This allows users to easily add content to an existing document without disrupting the flow of the rest of the content.
To push text in front of the cursor, you first need to create a CSS class that will set the position of the new text. For example, you might create a class called "pushed" that sets the position to "absolute" and the left and top values to "0."
.pushed {
position: absolute;
left: 0;
top: 0;
}
Once you have your CSS class, you can use the following code to push text in front of the cursor:
var editor = CKEDITOR.instances.editor1;
var range = editor.getSelection().getRanges()[0];
var newNode = editor.document.createElement('div');
newNode.setAttribute('class', 'pushed');
newNode.setText('New text');
range.insertNode(newNode);
In this code, "editor1" is the ID of the CKEditor instance you are working with. "getSelection().getRanges()[0]" gets the current selection and "insertNode(newNode)" inserts the new node (with the "pushed" class) in front of the cursor.
With a little bit of CSS and JavaScript, you can easily push text in front of the cursor in CKEditor. This is a great feature for users who want to add content to an existing document without disturbing the rest of the content.