Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
function selectEditorPoint(core: EditorCore, container: Node, offset: number): boolean {
if (!container || !contains(core.contentDiv, container)) {
return false;
}
let range = core.document.createRange();
if (container.nodeType == NodeType.Text && offset <= container.nodeValue.length) {
range.setStart(container, offset);
} else if (offset == NodeBoundary.Begin) {
range.setStartBefore(container);
} else {
range.setStartAfter(container);
}
range.collapse(true /* toStart */);
return updateSelection(core, range);
}
export const selectRange: SelectRange = (
core: EditorCore,
range: Range,
skipSameRange?: boolean
) => {
let selection: Selection;
let needAddRange = true;
if (
!contains(core.contentDiv, range) ||
!(selection = core.document.defaultView.getSelection())
) {
return false;
}
if (selection.rangeCount > 0) {
// Workaround IE exception 800a025e
try {
let currentRange: Range;
// Do not remove/add range if current selection is the same with target range
// Without this check, execCommand() may fail in Edge since we changed the selection
if (
(skipSameRange || Browser.isEdge) &&
(currentRange = selection.rangeCount == 1 ? selection.getRangeAt(0) : null) &&
currentRange.startContainer == range.startContainer &&
currentRange.startOffset == range.startOffset &&
export function hasFocus(core: EditorCore): boolean {
let activeElement = core.document.activeElement;
return (
activeElement &&
(core.contentDiv == activeElement || contains(core.contentDiv, activeElement))
);
}
editor.runAsync(() => {
let newContainer = editor.getElementAtCursor();
if (
contains(vtable.table, newContainer) &&
!contains(td, newContainer, true /*treatSameNodeAsContain*/)
) {
let newPos = targetTd
? new Position(targetTd, PositionType.Begin)
: new Position(vtable.table, isUp ? PositionType.Before : PositionType.After);
if (hasShiftKey) {
newPos =
newPos.node.nodeType == NodeType.Element && isVoidHtmlElement(newPos.node)
? new Position(
newPos.node,
newPos.isAtEnd ? PositionType.After : PositionType.Before
)
: newPos;
editor
.getSelection()
.setBaseAndExtent(anchorNode, anchorOffset, newPos.node, newPos.offset);
} else {
public contains(node: Node): boolean {
return contains(this.core.contentDiv, node);
}
editor.runAsync(() => {
let newContainer = editor.getElementAtCursor();
if (
contains(vtable.table, newContainer) &&
!contains(td, newContainer, true /*treatSameNodeAsContain*/)
) {
let newPos = targetTd
? new Position(targetTd, PositionType.Begin)
: new Position(vtable.table, isUp ? PositionType.Before : PositionType.After);
if (hasShiftKey) {
newPos =
newPos.node.nodeType == NodeType.Element && isVoidHtmlElement(newPos.node)
? new Position(
newPos.node,
newPos.isAtEnd ? PositionType.After : PositionType.Before
)
: newPos;
editor
.getSelection()
.setBaseAndExtent(anchorNode, anchorOffset, newPos.node, newPos.offset);