Skip to content

armgit / mimik

Public Imported from GitHub
0

🎬 A browser extension and desktop app that turns your clicks into step-by-step guides with annotated screenshots πŸ“–

fix(desktop): fall back to keystrokes sooner and count pasted text as typing

Luis Ortiza5b4691438bc
diff --git a/apps/desktop/scripts/check-pipeline.ts b/apps/desktop/scripts/check-pipeline.ts
index b1dfee4..569e2d8 100644
--- a/apps/desktop/scripts/check-pipeline.ts
+++ b/apps/desktop/scripts/check-pipeline.ts
@@ -490,8 +490,11 @@ app.whenReady().then(async () => {
typedTextFor(editor('a short note'), 'a sho') === 'a short note' &&
typedTextFor(editor(null), 'typed') === 'typed' &&
typedTextFor({ ...editor('\uFEFFhi\u200B'), role: 'textbox' }, '') === 'hi' &&
- typedTextFor(control, 'typed') === null,
- detail: 'a document far longer than the buffer yields the buffer, a short one yields the field, markers are stripped, a button yields nothing',
+ typedTextFor(control, 'typed') === null &&
+ typedTextFor(editor('x'.repeat(81)), 'ab') === 'ab' &&
+ typedTextFor(editor('y'.repeat(100)), 'z'.repeat(60)) === 'y'.repeat(100),
+ detail:
+ 'a field longer than twice the buffer and 80 characters yields the buffer, a shorter one yields the field, markers are stripped, a button yields nothing',
});
const typedThenClicked = async (keysAfterSnapshot: number) => {
diff --git a/apps/desktop/src/main/capture/recorder.ts b/apps/desktop/src/main/capture/recorder.ts
index 0ce5bac..411a620 100644
--- a/apps/desktop/src/main/capture/recorder.ts
+++ b/apps/desktop/src/main/capture/recorder.ts
@@ -1,7 +1,7 @@
import { randomUUID } from 'node:crypto';
import type { CaptureImage } from '@mimik/core/capture/sink';
import type { ElementMeta } from '@mimik/core/guides/types';
-import { screen } from 'electron';
+import { clipboard, screen } from 'electron';
import { cursorPoint } from './displays';
import {
clearDeadKey,
@@ -25,8 +25,7 @@ const SETTLE_MS = 60;
const SNAPSHOT_MS = 400;
const REPEAT_CLICK_MS = 500;
const MARKER_CODE_POINTS = new Set([0x200b, 0xfeff, 0xfff9, 0xfffa, 0xfffb, 0xfffc, 0xfffd]);
-const FIELD_SLACK: Record<string, number> = { document: 24 };
-const DEFAULT_FIELD_SLACK = 120;
+const FIELD_FLOOR = 80;
const KEY = {
escape: 1,
@@ -43,6 +42,8 @@ const KEY = {
altRight: 3640,
meta: 3675,
metaRight: 3676,
+ a: 30,
+ v: 47,
} as const;
const MODIFIER_KEYS: ReadonlySet<number> = new Set([
@@ -162,8 +163,7 @@ export function typedTextFor(field: ScreenElement | null, buffer: string, readFi
const shown = [...(field.textContent ?? '')].filter((char) => !MARKER_CODE_POINTS.has(char.codePointAt(0) ?? 0));
if (!shown.join('').trim()) return buffer || null;
const typed = [...buffer].length;
- const slack = FIELD_SLACK[field.role ?? ''] ?? DEFAULT_FIELD_SLACK;
- return typed > 0 && shown.length > typed + slack ? buffer : shown.join('');
+ return typed > 0 && shown.length > Math.max(2 * typed, FIELD_FLOOR) ? buffer : shown.join('');
}
export function isBoundShortcut(accelerator: string | null, action: KeyAction, key: string): boolean {
@@ -398,20 +398,29 @@ export class DesktopRecorder {
const settings = this.settings();
if (isTextKey(action)) {
if (!settings.recordTyping) return;
- this.typing = true;
- this.keys += 1;
this.buffered(action);
- if (this.idle) clearTimeout(this.idle);
- this.idle = setTimeout(() => this.commitTyping(true), settings.typingDebounceMs);
- this.idle.unref?.();
- if (this.snapshotTimer) clearTimeout(this.snapshotTimer);
- this.snapshotTimer = setTimeout(() => {
- this.snapshot = { field: this.focused().catch(() => null), keys: this.keys };
- }, SNAPSHOT_MS);
- this.snapshotTimer.unref?.();
+ this.extendTyping(settings);
return;
}
+ const primary = process.platform === 'darwin' ? action.meta : action.ctrl;
+ if (primary && !action.alt && settings.recordTyping) {
+ const pasted = action.keycode === KEY.v ? clipboard.readText() : '';
+ if (pasted) {
+ this.appending = this.appending.then(() => {
+ this.buffer += pasted;
+ });
+ this.extendTyping(settings);
+ return;
+ }
+ if (action.keycode === KEY.a && this.typing) {
+ this.appending = this.appending.then(() => {
+ this.buffer = '';
+ });
+ return;
+ }
+ }
+
const submitted = this.typing;
this.commitTyping(true);
if (action.keycode === KEY.tab) this.watchPassword();
@@ -425,6 +434,19 @@ export class DesktopRecorder {
this.enqueue(() => this.captureKey(action));
}
+ private extendTyping(settings: CaptureSettings): void {
+ this.typing = true;
+ this.keys += 1;
+ if (this.idle) clearTimeout(this.idle);
+ this.idle = setTimeout(() => this.commitTyping(true), settings.typingDebounceMs);
+ this.idle.unref?.();
+ if (this.snapshotTimer) clearTimeout(this.snapshotTimer);
+ this.snapshotTimer = setTimeout(() => {
+ this.snapshot = { field: this.focused().catch(() => null), keys: this.keys };
+ }, SNAPSHOT_MS);
+ this.snapshotTimer.unref?.();
+ }
+
async captureKey(action: KeyAction): Promise<void> {
const key = await this.label(action.keycode);
if (!key) return;