CKEDITOR получить текст до и после текущей позиции курсора - PullRequest
0 голосов
/ 27 октября 2018

Привет Я хотел бы получить текст редактора до и после текущей позиции курсора.Я наполовину сделал это, но у меня проблемы с новыми строками .. Кто-нибудь может мне помочь?

M3JSEditor.getSplittedTextFromCursor = function(editor) {
var range = editor.getSelection().getRanges()[ 0 ], startNode = range.startContainer;

if ( startNode.type == CKEDITOR.NODE_TEXT && range.startOffset )
    // Range at the non-zero position of a text node.
    return [startNode.getText().substr(0, range.startOffset), startNode.getText().substr(range.startOffset, startNode.getText().length)]; //range.endOffset
else {
    // Expand the range to the beginning of editable.
    range.collapse( true );
    range.setStartAt( editor.editable(), CKEDITOR.POSITION_AFTER_START );

    // Let's use the walker to find the closes (previous) text node.
    var walker = new CKEDITOR.dom.walker( range ),
    node;

    while ( ( node = walker.previous() ) ) {
        // If found, return the last character of the text node.
        if ( node.type == CKEDITOR.NODE_TEXT )
            return [node.getText(), '']; //((node.getText().slice( -1 )
    }
}

// Selection starts at the 0 index of the text node and/or there's no previous text node in contents.
return ['', ''];

}

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...