@atlaskit/editor-plugin-selection-toolbar
Version:
@atlaskit/editor-plugin-selection-toolbar for @atlaskit/editor-core
21 lines • 667 B
JavaScript
import { isExperimentEnabled } from '@atlaskit/platform-feature-experiments/is-experiment-enabled';
export function getSelectionNodeTypes(state) {
const {
from,
to
} = state.selection;
if (isExperimentEnabled('platform_editor_reduce_memory_leaks')) {
const selectionNodeTypes = new Set();
state.doc.nodesBetween(from, to, node => {
selectionNodeTypes.add(node.type);
});
return Array.from(selectionNodeTypes);
}
const selectionNodeTypes = [];
state.doc.nodesBetween(from, to, node => {
if (selectionNodeTypes.indexOf(node.type) !== 0) {
selectionNodeTypes.push(node.type);
}
});
return selectionNodeTypes;
}