superdesk/superdesk-client-core

View on GitHub
scripts/core/editor3/helpers/selectionPositionInBlock.ts

Summary

Maintainability
A
0 mins
Test Coverage
import {EditorState} from 'draft-js';

export function isSelectionAtEndOfBlock(editorState: EditorState): boolean {
    const selection = editorState.getSelection();
    const endBlockKey = selection.getEndKey();
    const block = editorState.getCurrentContent().getBlockForKey(endBlockKey);

    return block.getLength() === selection.getEndOffset();
}

export function isSelectionAtStartOfBlock(editorState: EditorState): boolean {
    return editorState.getSelection().getStartOffset() === 0;
}