Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
shouldHandleEvent: (event, editor) => {
let li = cacheGetElementAtCursor(editor, event, 'LI');
return !event.rawEvent.shiftKey && li && isNodeEmpty(li);
},
handleEvent: (event, editor) => {
editor.performAutoComplete(() => toggleListAndPreventDefault(event, editor));
},
};
/**
* AutoBullet edit feature, provides the ablility to automatically convert current line into a list.
* When user input "1. ", convert into a numbering list
* When user input "- " or "* ", convert into a bullet list
*/
export const AutoBullet: ContentEditFeature = {
keys: [Keys.SPACE],
shouldHandleEvent: (event, editor) => {
if (!cacheGetListElement(event, editor)) {
let searcher = cacheGetContentSearcher(event, editor);
let textBeforeCursor = searcher.getSubStringBefore(3);
// Auto list is triggered if:
// 1. Text before cursor exactly mathces '*', '-' or '1.'
// 2. There's no non-text inline entities before cursor
return (
['*', '-', '1.'].indexOf(textBeforeCursor) >= 0 &&
!searcher.getNearestNonTextInlineElement()
);
}
return false;
},
handleEvent: (event, editor) => {
Keys,
} from 'roosterjs-editor-core';
/**
* When user type, they may end a link with a puncatuation, i.e. www.bing.com;
* we need to trim off the trailing puncatuation before turning it to link match
*/
const TRAILING_PUNCTUATION_REGEX = /[.+=\s:;"',>]+$/i;
const MINIMUM_LENGTH = 5;
/**
* AutoLink edit feature, provides the ability to automatically convert text user typed or pasted
* in hyperlink format into a real hyperlink
*/
export const AutoLink: GenericContentEditFeature = {
keys: [Keys.ENTER, Keys.SPACE, Keys.CONTENTCHANGED],
shouldHandleEvent: cacheGetLinkData,
handleEvent: autoLink,
};
/**
* UnlinkWhenBackspaceAfterLink edit feature, provides the ability to convert a hyperlink back into text
* if user presses BACKSPACE right after a hyperlink
*/
export const UnlinkWhenBackspaceAfterLink: GenericContentEditFeature = {
keys: [Keys.BACKSPACE],
shouldHandleEvent: hasLinkBeforeCursor,
handleEvent: (event, editor) => {
event.rawEvent.preventDefault();
removeLink(editor);
},
};