@atlaskit/editor-plugin-block-controls
Version:
Block controls plugin for @atlaskit/editor-core
26 lines (24 loc) • 970 B
JavaScript
import { startEditing } from './commands';
import { getInteractionTrackingState } from './pm-plugin';
export var handleKeyDown = function handleKeyDown(view, event) {
// Check if this is a keyboard shortcut (Ctrl/Cmd + key)
var isShortcut = event.ctrlKey || event.metaKey || event.altKey;
if (isShortcut) {
return false;
}
// Only consider actual typing keys (not shortcuts)
// We need to check if it's a single character key or a deletion key
// and ensure it's not part of a shortcut
var isTypingKey =
// Single character keys (letters, numbers, symbols)
event.key.length === 1 || event.key === 'Backspace' || event.key === 'Delete' || event.key === ' ' || event.key === 'Enter';
if (!isTypingKey) {
return false;
}
var state = getInteractionTrackingState(view.state);
// if user hasnt started typing yet, start timer
if (!(state !== null && state !== void 0 && state.isEditing)) {
startEditing(view);
}
return false;
};