Press n or j to go to the next uncovered block, b, p or k for the previous block.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 | 1x 693x 1x 692x 692x 413x 413x 413x | import type { DOMSelection, GetDOMSelection, EditorCore } from 'roosterjs-content-model-types';
/**
* @internal
*/
export const getDOMSelection: GetDOMSelection = core => {
if (core.lifecycle.shadowEditFragment) {
return null;
} else {
const selection = core.selection.selection;
return selection && (selection.type != 'range' || !core.domHelper.hasFocus())
? selection
: getNewSelection(core);
}
};
function getNewSelection(core: EditorCore): DOMSelection | null {
const selection = core.logicalRoot.ownerDocument.defaultView?.getSelection();
const range = selection && selection.rangeCount > 0 ? selection.getRangeAt(0) : null;
return selection && range && core.logicalRoot.contains(range.commonAncestorContainer)
? {
type: 'range',
range,
isReverted:
selection.focusNode != range.endContainer ||
selection.focusOffset != range.endOffset,
}
: null;
}
|