Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
private _getAnchorForClickOpenHyperlink(ev: React.MouseEvent, element: HTMLElement): HTMLAnchorElement {
const { clickOpenHyperlinkViewMode, readonly } = this.props;
const isPrimaryButton = ev.button === 0;
if (!isPrimaryButton || !clickOpenHyperlinkViewMode || readonly || this.mode !== LeanRoosterModes.View) {
return null;
}
// Hyperlink plugin will handle CTRL+Click when editor is created and FireFox will handle for contenteditable
const ctrlOpen = Browser.isMac ? ev.metaKey : ev.ctrlKey;
if ((this._editor && ctrlOpen) || (Browser.isFirefox && ctrlOpen)) {
return null;
}
const anchor = findClosestElementAncestor(element, this._contentDiv, "a[href]");
if (anchor) {
return anchor as HTMLAnchorElement;
}
return null;
}
private onKeyPress(event: PluginKeyboardEvent) {
// If normalization was not possible before the keypress,
// check again after the keyboard event has been processed by browser native behaviour.
//
// This handles the case where the keyboard event that first inserts content happens when
// there is already content under the selection (e.g. Ctrl+a -> type new content).
//
// Only scheudle when the range is not collapsed to catch this edge case.
let range = this.editor.getSelectionRange();
if (!range || this.editor.contains(findClosestElementAncestor(range.startContainer))) {
return;
}
if (range.collapsed) {
this.tryNormalizeTyping(event, range);
} else if (!range.collapsed) {
this.editor.runAsync(() => {
this.tryNormalizeTyping(event);
});
}
}
editor.getDocument().execCommand(DocumentCommand.FormatBlock, false, '<div>');
wrapped = true;
}
let div = editor.getDocument().createElement('div');
while (header.firstChild) {
div.appendChild(header.firstChild);
}
editor.replaceNode(header, div);
});
if (level > 0) {
let traverser = editor.getSelectionTraverser();
let inlineElement = traverser ? traverser.currentInlineElement : null;
while (inlineElement) {
let element = findClosestElementAncestor(inlineElement.getContainerNode());
if (element) {
element.style.fontSize = '';
}
inlineElement = traverser.getNextInlineElement();
}
editor.getDocument().execCommand(DocumentCommand.FormatBlock, false, ``);
}
}, ChangeSource.Format);
}
</div>