Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
64 changes: 64 additions & 0 deletions packages/lexical/src/LexicalEditor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import {
$isElementNode,
type BaseSelection,
mergeRegister,
type RangeSelection,
TextNode,
} from '.';
import {FULL_RECONCILE, NO_DIRTY_NODES} from './LexicalConstants';
Expand Down Expand Up @@ -249,6 +250,62 @@ export interface EditorConfig {
theme: EditorThemeClasses;
}

/** @internal */
export interface CollapsedSelectionFormat {
format: number;
style: string;
offset: number;
key: NodeKey;
timeStamp: number;
}

/** @internal */
export interface InputState {
compositionPhase: 'idle' | 'composing' | 'ending-firefox' | 'ending-safari';
compositionEndData: string;
hadOrphanedCompositionEvents: boolean;

lastKeyDownTimeStamp: number;
lastKeyCode: string | null;
lastBeforeInputInsertTextTimeStamp: number;
unprocessedBeforeInputData: string | null;
collapsedSelectionFormat: CollapsedSelectionFormat;
postDeleteSelectionToRestore: RangeSelection | null;

isSelectionChangeFromDOMUpdate: boolean;
isSelectionChangeFromMouseDown: boolean;
isInsertLineBreak: boolean;

isInsertTextAfterHandledSelectionCommand: boolean;
handledSelectionCommandTimeoutId: ReturnType<typeof setTimeout> | null;
}

/** @internal */
export function createInputState(): InputState {
return {
collapsedSelectionFormat: {
format: 0,
key: 'root',
offset: 0,
style: '',
timeStamp: 0,
},
compositionEndData: '',
compositionPhase: 'idle',
hadOrphanedCompositionEvents: false,
handledSelectionCommandTimeoutId: null,
isInsertLineBreak: false,
isInsertTextAfterHandledSelectionCommand: false,
isSelectionChangeFromDOMUpdate: false,
isSelectionChangeFromMouseDown: false,
lastBeforeInputInsertTextTimeStamp: 0,
lastKeyCode: null,
lastKeyDownTimeStamp: 0,
postDeleteSelectionToRestore: null,
unprocessedBeforeInputData: null,
};
}

/**
* Configuration entry passed in {@link CreateEditorArgs.nodes} to substitute
* a core node class with a custom subclass. The replacement class itself
Expand Down Expand Up @@ -725,6 +782,10 @@ export function resetEditor(
editor._cascadeCount = 0;
}
editor._blockCursorElement = null;
if (editor._inputState.handledSelectionCommandTimeoutId !== null) {
clearTimeout(editor._inputState.handledSelectionCommandTimeoutId);
}
editor._inputState = createInputState();

const observer = editor._observer;

Expand Down Expand Up @@ -1108,6 +1169,8 @@ export class LexicalEditor {
*/
_slotsUsed: boolean;
/** @internal */
_inputState: InputState;
/** @internal */
_createEditorArgs?: undefined | CreateEditorArgs;

/** @internal */
Expand Down Expand Up @@ -1176,6 +1239,7 @@ export class LexicalEditor {
this._window = null;
this._blockCursorElement = null;
this._slotsUsed = false;
this._inputState = createInputState();
}

/**
Expand Down
Loading