Skip to content

Commit

Permalink
Register Enter event @ porting from @Juice10’s rrweb
Browse files Browse the repository at this point in the history
source: @Juice10/record-once-rrweb/commit/d734cf95dbaf7442547
  • Loading branch information
joris committed Oct 2, 2020
1 parent 3e18d20 commit 0333f38
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 5 deletions.
12 changes: 9 additions & 3 deletions src/record/observer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,7 @@ function initInputObserver(
maskInputOptions: MaskInputOptions,
sampling: SamplingStrategy,
): listenerHandler {
function eventHandler(event: Event) {
function eventHandler(event: KeyboardEvent) { // was Event
const { target } = event;
if (
!target ||
Expand All @@ -231,6 +231,11 @@ function initInputObserver(
) {
return;
}

if (event.type === 'keyup' && event.key === 'Enter') {
return cbWithDedup(target, { key: 'Enter' });
}

const type: string | undefined = (target as HTMLInputElement).type;
if (
type === 'password' ||
Expand Down Expand Up @@ -272,7 +277,8 @@ function initInputObserver(
if (
!lastInputValue ||
lastInputValue.text !== v.text ||
lastInputValue.isChecked !== v.isChecked
lastInputValue.isChecked !== v.isChecked ||
lastInputValue.key !== v.key
) {
lastInputValueMap.set(target, v);
const id = mirror.getId(target as INode);
Expand Down Expand Up @@ -304,7 +310,7 @@ function initInputObserver(
hookSetter<HTMLElement>(p[0], p[1], {
set() {
// mock to a normal event
eventHandler({ target: this } as Event);
eventHandler({ target: this } as KeyboardEvent); // was Event
},
}),
),
Expand Down
5 changes: 3 additions & 2 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -356,8 +356,9 @@ export type viewportResizeDimention = {
export type viewportResizeCallback = (d: viewportResizeDimention) => void;

export type inputValue = {
text: string;
isChecked: boolean;
text?: string;
isChecked?: boolean;
key?: string;
};

export type inputCallback = (v: inputValue & { id: number }) => void;
Expand Down

0 comments on commit 0333f38

Please sign in to comment.