@atlaskit/editor-plugin-metrics
Version:
Metrics plugin for @atlaskit/editor-core
20 lines • 544 B
JavaScript
import { ActionType } from '../types';
export const checkTextInput = step => {
const {
slice: {
content
},
from,
to
} = step;
const node = content.firstChild;
const isAddingCharacter = from === to && content.childCount === 1 && !!node && !!node.text && node.text.length === 1;
const isDeletingCharacter = to - from === 1 && content.childCount === 0;
const isTextInput = isAddingCharacter || isDeletingCharacter;
if (!isTextInput) {
return undefined;
}
return {
type: ActionType.TEXT_INPUT
};
};