Compare commits
12
Commits
cc724f894b
..
main
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
2929d7d5e4 | ||
|
|
493f899a11 | ||
|
|
68e886c142 | ||
|
|
9e13ea9c40 | ||
|
|
058cdc20ab | ||
|
|
7f68a72e2b | ||
|
|
8e4f3ff951 | ||
|
|
67b5dc5965 | ||
|
|
9555db9bf5 | ||
|
|
a7d398ad6a | ||
|
|
a55a7a9170 | ||
|
|
8ddfe1b3e1 |
@@ -30,7 +30,7 @@ jobs:
|
|||||||
|
|
||||||
- uses: actions/setup-node@v4
|
- uses: actions/setup-node@v4
|
||||||
with:
|
with:
|
||||||
node-version: 20
|
node-version-file: .nvmrc
|
||||||
cache: npm
|
cache: npm
|
||||||
|
|
||||||
- name: Install dependencies
|
- name: Install dependencies
|
||||||
|
|||||||
@@ -1,3 +1,36 @@
|
|||||||
|
# After action report
|
||||||
|
|
||||||
|
## Done — 10 PRs implemented, merged, and CI-green on both forges
|
||||||
|
I worked through ai_prompts/prompt4.md and shipped PRs 1–10 of the plan's recommended sequence. Each was a focused branch, opened on both GitHub (Twest2/StepForge #5–#14) and Gitea (Tyler/autodoc #21–#30), verified green on GitHub CI (Ubuntu + Windows + dependency audit), merged with the same SHA to both forges, and the Gitea mirror closed with a merge note. Final state: main is byte-identical across local, GitHub, and Gitea (cc724f8), main CI is green, no open PRs, 289 unit tests pass (0 fail).
|
||||||
|
|
||||||
|
## PR What it fixed
|
||||||
|
1 Pinned Node ≥22.12 (.nvmrc/engines); removed all runtime npm self-repair; refuse silent --no-sandbox; CI on pull_request + prod/full audits; made the click E2E stop hiding startup crashes as "SKIPPED"; remediated the form-data/undici advisories
|
||||||
|
2 Closed the renderer privilege boundary: navigation/popup denial, sandboxed windows, per-channel IPC sender+argument validation, deny-by-default permissions (display capture only for the capture worker), intent-specific shell access replacing arbitrary shell:openPath
|
||||||
|
3 Truthful local-first AI/privacy contract: raw keystroke capture off by default, AbortController timeouts + cancellation + concurrency + image-size limits, loopback-only Ollama unless explicitly opted in, honest docs + new docs/PRIVACY.md
|
||||||
|
4 Optimistic revision fields + compare-and-swap (stale AI responses can't clobber edits), autosave keeps dirty state on failed saves, corrupt guides/steps quarantined instead of silently vanishing
|
||||||
|
5 Region-capture nested-result + listener-leak bugs, single-owner power blocker, explicit click-source reporting (evdev fix), strict-mode skips instead of storing post-click shots, pathToFileURL, shutdown drain
|
||||||
|
6 ZIP-bomb limits, transactional archive import, atomic snapshot restore, exclusive locks (O_EXCL + token), search index reconcile at startup, implemented the dead automatic-backup settings
|
||||||
|
7 Platform adapter layer — window-context detection extracted to app/platform/{windows,linux,darwin}/; shared code no longer branches on process.platform; Linux capability diagnostics
|
||||||
|
8 Production .deb (runtime-only staging, no dev tree, detected arch, desktop/MIME/icons, original generated icon set), apt setup scripts, real launcher; retired the old broken packager
|
||||||
|
9 Production .rpm + dnf setup, shared stage-runtime.sh so both formats never drift
|
||||||
|
10 Honest Wayland triggers (never promises per-click coordinates it can't deliver) + a least-privilege mouse-only udev rule replacing the broad input group keylogging surface; .gitattributes so Unix scripts don't break on CRLF
|
||||||
|
I verified real behavior where possible: built and inspected an actual 107 MB .deb, ran the click self-test (markers 3/3, burst 8/8), and confirmed the sandboxed app boots.
|
||||||
|
|
||||||
|
## One blocking item I did not act on — the license (needs your decision)
|
||||||
|
The plan calls this a legal release blocker that an implementation agent must not guess, and I agree. The repo currently contradicts itself:
|
||||||
|
|
||||||
|
package.json → MPL-2.0 and CONTRIBUTING requires MPL-2.0 + DCO sign-off (permits commercial use)
|
||||||
|
docs/LICENSE + README §License → Creative Commons Attribution-NonCommercial (forbids commercial use; also not a software license)
|
||||||
|
there is no root LICENSE file
|
||||||
|
MPL-2.0 and CC-BY-NC are mutually exclusive, and contributors have been signing off under a license the project doesn't actually ship. You need to pick one, then I can reconcile the SPDX field, root LICENSE, README, CONTRIBUTING, package payloads, and the About view in a single follow-up PR.
|
||||||
|
|
||||||
|
## What remains (plan PRs 11–14 — larger, several need your input)
|
||||||
|
Canonical blocks/callout-placement schema-v2 migration; lazy exports + Unicode font vendoring (needs a licensed-font choice); editor modularization + accessibility; and the signed reproducible release pipeline (needs signing keys). Also still open: the click self-test's arm/debounce scenarios fail on Linux — a pre-existing capture defect I surfaced honestly in PR 1 but didn't chase down (it needs on-device Linux capture debugging).
|
||||||
|
|
||||||
|
Tell me your license choice and I'll do the reconciliation PR; tell me which of 11–14 to prioritize and I'll take it next.
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
# StepForge comprehensive improvement plan
|
# StepForge comprehensive improvement plan
|
||||||
|
|
||||||
This document is an implementation handoff for another coding agent. It is based on a repository-wide audit of commit `534a28e` on 2026-07-03. It is a plan, not authorization to make all changes in one unreviewable patch.
|
This document is an implementation handoff for another coding agent. It is based on a repository-wide audit of commit `534a28e` on 2026-07-03. It is a plan, not authorization to make all changes in one unreviewable patch.
|
||||||
|
|||||||
+106
@@ -22,6 +22,7 @@ const { readLock } = require('../core/locks');
|
|||||||
const CaptureService = require('./capture');
|
const CaptureService = require('./capture');
|
||||||
const { TextIntelService } = require('./text-intel');
|
const { TextIntelService } = require('./text-intel');
|
||||||
const { keepProcessesResponsive } = require('./win-power');
|
const { keepProcessesResponsive } = require('./win-power');
|
||||||
|
const { zoomShortcutFromInputEvent } = require('./shortcut-utils');
|
||||||
const security = require('./security');
|
const security = require('./security');
|
||||||
const PACKAGE_JSON = require(path.join(__dirname, '..', 'package.json'));
|
const PACKAGE_JSON = require(path.join(__dirname, '..', 'package.json'));
|
||||||
|
|
||||||
@@ -65,6 +66,10 @@ let templates;
|
|||||||
let capture;
|
let capture;
|
||||||
let textIntel;
|
let textIntel;
|
||||||
let mainWindow;
|
let mainWindow;
|
||||||
|
let lastZoomShortcut = null;
|
||||||
|
let canvasZoomActive = false;
|
||||||
|
const UI_ZOOM_LEVEL_MIN = -8;
|
||||||
|
const UI_ZOOM_LEVEL_MAX = 8;
|
||||||
|
|
||||||
function reindex(guideId) {
|
function reindex(guideId) {
|
||||||
try {
|
try {
|
||||||
@@ -87,6 +92,43 @@ function applyTheme() {
|
|||||||
nativeTheme.themeSource = settings.get('appearance') || 'system';
|
nativeTheme.themeSource = settings.get('appearance') || 'system';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function dispatchZoomShortcut(kind) {
|
||||||
|
sendToRenderer('editor:zoom-shortcut', kind);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Ctrl+=/Ctrl+-/Ctrl+0 zoom the step editor's canvas while a guide is open
|
||||||
|
// there (dispatchZoomShortcut above); everywhere else — library, welcome,
|
||||||
|
// dialogs — the same keys scale the whole window's UI like a browser.
|
||||||
|
function applyUiZoom(kind) {
|
||||||
|
if (!mainWindow || mainWindow.isDestroyed()) return;
|
||||||
|
const wc = mainWindow.webContents;
|
||||||
|
if (kind === 'fit') {
|
||||||
|
wc.zoomLevel = 0;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
const delta = kind === 'in' ? 1 : kind === 'out' ? -1 : 0;
|
||||||
|
if (!delta) return;
|
||||||
|
wc.zoomLevel = Math.max(UI_ZOOM_LEVEL_MIN, Math.min(UI_ZOOM_LEVEL_MAX, wc.zoomLevel + delta));
|
||||||
|
}
|
||||||
|
|
||||||
|
// A single physical keypress reaches here twice — once via the global
|
||||||
|
// accelerator registration, once via before-input-event — plus multiple
|
||||||
|
// accelerator spellings can match the same key on some layouts. Collapse
|
||||||
|
// same-kind repeats within 50ms so one keypress is one zoom step.
|
||||||
|
function handleZoomShortcut(kind) {
|
||||||
|
if (!kind) return;
|
||||||
|
const now = Date.now();
|
||||||
|
if (lastZoomShortcut && lastZoomShortcut.kind === kind && (now - lastZoomShortcut.at) < 50) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
lastZoomShortcut = { kind, at: now };
|
||||||
|
if (canvasZoomActive) {
|
||||||
|
dispatchZoomShortcut(kind);
|
||||||
|
} else {
|
||||||
|
applyUiZoom(kind);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
function createWindow() {
|
function createWindow() {
|
||||||
mainWindow = new BrowserWindow({
|
mainWindow = new BrowserWindow({
|
||||||
width: 1280,
|
width: 1280,
|
||||||
@@ -113,6 +155,16 @@ function createWindow() {
|
|||||||
// away from it and every popup is denied, so no other document can run
|
// away from it and every popup is denied, so no other document can run
|
||||||
// with this window's preload bridge.
|
// with this window's preload bridge.
|
||||||
security.installWindowSecurity(mainWindow, 'main');
|
security.installWindowSecurity(mainWindow, 'main');
|
||||||
|
mainWindow.webContents.on('before-input-event', (event, input) => {
|
||||||
|
// Electron reports both the key-down and key-up as separate
|
||||||
|
// before-input-event calls; only act on the down edge or every tap
|
||||||
|
// fires the shortcut twice regardless of the dedupe window below.
|
||||||
|
if (input.type !== 'keyDown') return;
|
||||||
|
const kind = zoomShortcutFromInputEvent(input);
|
||||||
|
if (!kind) return;
|
||||||
|
event.preventDefault();
|
||||||
|
handleZoomShortcut(kind);
|
||||||
|
});
|
||||||
mainWindow.loadFile(path.join(__dirname, 'renderer', 'index.html'));
|
mainWindow.loadFile(path.join(__dirname, 'renderer', 'index.html'));
|
||||||
mainWindow.once('ready-to-show', () => {
|
mainWindow.once('ready-to-show', () => {
|
||||||
mainWindow.show();
|
mainWindow.show();
|
||||||
@@ -248,6 +300,19 @@ function createWindow() {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const waitClickBackendReady = async () => {
|
||||||
|
for (let i = 0; i < 240; i++) {
|
||||||
|
const streamReady = Boolean(
|
||||||
|
capture.streamBackend
|
||||||
|
&& typeof capture.streamBackend.isActive === 'function'
|
||||||
|
&& capture.streamBackend.isActive(),
|
||||||
|
);
|
||||||
|
if (streamReady || capture.frameLoopRunning) return true;
|
||||||
|
await new Promise((res) => setTimeout(res, 50));
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
};
|
||||||
|
|
||||||
// Third scenario: the real "Start recording" path. armRecording
|
// Third scenario: the real "Start recording" path. armRecording
|
||||||
// warms the recorder while the window is visible and only arms the
|
// warms the recorder while the window is visible and only arms the
|
||||||
// session once it hides; the first click *after* arming must get a
|
// session once it hides; the first click *after* arming must get a
|
||||||
@@ -268,6 +333,12 @@ function createWindow() {
|
|||||||
const warmupClicks = store.getGuide(armGuide.guideId).stepsOrder.length;
|
const warmupClicks = store.getGuide(armGuide.guideId).stepsOrder.length;
|
||||||
capture.onOsClick(Date.now(), toPhysical({ x: bounds.x + 100, y: bounds.y + 100 }), 'button-1');
|
capture.onOsClick(Date.now(), toPhysical({ x: bounds.x + 100, y: bounds.y + 100 }), 'button-1');
|
||||||
await waitArmed();
|
await waitArmed();
|
||||||
|
if (!await waitClickBackendReady()) {
|
||||||
|
throw new Error('arm selftest backend never became ready');
|
||||||
|
}
|
||||||
|
await new Promise((res) => setTimeout(res, 1500));
|
||||||
|
if (mainWindow.isVisible()) mainWindow.hide();
|
||||||
|
await new Promise((res) => setTimeout(res, 200));
|
||||||
const armPoint = {
|
const armPoint = {
|
||||||
x: Math.round(bounds.x + bounds.width * 0.4),
|
x: Math.round(bounds.x + bounds.width * 0.4),
|
||||||
y: Math.round(bounds.y + bounds.height * 0.4),
|
y: Math.round(bounds.y + bounds.height * 0.4),
|
||||||
@@ -295,6 +366,12 @@ function createWindow() {
|
|||||||
capture.togglePause(false);
|
capture.togglePause(false);
|
||||||
await capture.startClickFrameBackend();
|
await capture.startClickFrameBackend();
|
||||||
await waitArmed();
|
await waitArmed();
|
||||||
|
if (!await waitClickBackendReady()) {
|
||||||
|
throw new Error('debounce selftest backend never became ready');
|
||||||
|
}
|
||||||
|
await new Promise((res) => setTimeout(res, 1500));
|
||||||
|
if (mainWindow.isVisible()) mainWindow.hide();
|
||||||
|
await new Promise((res) => setTimeout(res, 200));
|
||||||
await new Promise((res) => setTimeout(res, 300));
|
await new Promise((res) => setTimeout(res, 300));
|
||||||
const dbPoint = {
|
const dbPoint = {
|
||||||
x: Math.round(bounds.x + bounds.width * 0.55),
|
x: Math.round(bounds.x + bounds.width * 0.55),
|
||||||
@@ -365,6 +442,27 @@ function createWindow() {
|
|||||||
|
|
||||||
function registerHotkeys() {
|
function registerHotkeys() {
|
||||||
globalShortcut.unregisterAll();
|
globalShortcut.unregisterAll();
|
||||||
|
const zoomBindings = [
|
||||||
|
['CommandOrControl+Plus', 'in'],
|
||||||
|
['CommandOrControl+Shift+=', 'in'],
|
||||||
|
['CommandOrControl+=', 'in'],
|
||||||
|
['CommandOrControl+numadd', 'in'],
|
||||||
|
['CommandOrControl+-', 'out'],
|
||||||
|
['CommandOrControl+Minus', 'out'],
|
||||||
|
['CommandOrControl+numsub', 'out'],
|
||||||
|
['CommandOrControl+0', 'fit'],
|
||||||
|
['CommandOrControl+num0', 'fit'],
|
||||||
|
];
|
||||||
|
for (const [accel, kind] of zoomBindings) {
|
||||||
|
try {
|
||||||
|
if (globalShortcut.register(accel, () => handleZoomShortcut(kind))) {
|
||||||
|
// Keep registering the other spellings so keyboards with different
|
||||||
|
// plus/minus translations still land on the same action.
|
||||||
|
}
|
||||||
|
} catch {
|
||||||
|
// Invalid accelerators must not break startup.
|
||||||
|
}
|
||||||
|
}
|
||||||
const accel = settings.get('capture.hotkeyCapture');
|
const accel = settings.get('capture.hotkeyCapture');
|
||||||
const pauseAccel = settings.get('capture.hotkeyPauseResume');
|
const pauseAccel = settings.get('capture.hotkeyPauseResume');
|
||||||
try {
|
try {
|
||||||
@@ -399,6 +497,14 @@ function setupIpc() {
|
|||||||
getMainWebContents: () => (mainWindow && !mainWindow.isDestroyed() ? mainWindow.webContents : null),
|
getMainWebContents: () => (mainWindow && !mainWindow.isDestroyed() ? mainWindow.webContents : null),
|
||||||
});
|
});
|
||||||
const c = security.check;
|
const c = security.check;
|
||||||
|
|
||||||
|
// The renderer reports whether the step editor (with a guide open) is the
|
||||||
|
// visible screen, so Ctrl+=/Ctrl+-/Ctrl+0 can pick canvas zoom vs UI zoom.
|
||||||
|
ipcMain.on('editor:canvas-zoom-active', (event, active) => {
|
||||||
|
if (!trustedSender(event)) return;
|
||||||
|
canvasZoomActive = Boolean(active);
|
||||||
|
});
|
||||||
|
|
||||||
const IMAGE_BUDGET = 256 * 1024 * 1024; // channels that carry base64 PNGs
|
const IMAGE_BUDGET = 256 * 1024 * 1024; // channels that carry base64 PNGs
|
||||||
const h = (channel, fn, opts = {}) => {
|
const h = (channel, fn, opts = {}) => {
|
||||||
const { maxChars = 2 * 1024 * 1024, validate = null } = opts;
|
const { maxChars = 2 * 1024 * 1024, validate = null } = opts;
|
||||||
|
|||||||
@@ -67,6 +67,10 @@ const api = {
|
|||||||
onState: (fn) => ipcRenderer.on('capture:state', (e, payload) => fn(payload)),
|
onState: (fn) => ipcRenderer.on('capture:state', (e, payload) => fn(payload)),
|
||||||
onStepUpdated: (fn) => ipcRenderer.on('step:updated', (e, payload) => fn(payload)),
|
onStepUpdated: (fn) => ipcRenderer.on('step:updated', (e, payload) => fn(payload)),
|
||||||
},
|
},
|
||||||
|
editor: {
|
||||||
|
onZoomShortcut: (fn) => ipcRenderer.on('editor:zoom-shortcut', (e, payload) => fn(payload)),
|
||||||
|
setCanvasZoomActive: (active) => ipcRenderer.send('editor:canvas-zoom-active', Boolean(active)),
|
||||||
|
},
|
||||||
archive: {
|
archive: {
|
||||||
export: invoke('archive:export'),
|
export: invoke('archive:export'),
|
||||||
open: invoke('archive:open'),
|
open: invoke('archive:open'),
|
||||||
|
|||||||
+16
-1
@@ -169,7 +169,14 @@ function makeHotkeyInput(value = '') {
|
|||||||
return wrap;
|
return wrap;
|
||||||
}
|
}
|
||||||
|
|
||||||
async function promptText({ title, label = 'Value', value = '', placeholder = '', multiline = false } = {}) {
|
async function promptText({
|
||||||
|
title,
|
||||||
|
label = 'Value',
|
||||||
|
value = '',
|
||||||
|
placeholder = '',
|
||||||
|
multiline = false,
|
||||||
|
onInput = null,
|
||||||
|
} = {}) {
|
||||||
return new Promise((resolve) => {
|
return new Promise((resolve) => {
|
||||||
const field = multiline
|
const field = multiline
|
||||||
? el('textarea', { rows: 6, placeholder }, value)
|
? el('textarea', { rows: 6, placeholder }, value)
|
||||||
@@ -186,12 +193,20 @@ async function promptText({ title, label = 'Value', value = '', placeholder = ''
|
|||||||
});
|
});
|
||||||
|
|
||||||
field.addEventListener('keydown', (e) => {
|
field.addEventListener('keydown', (e) => {
|
||||||
|
if (multiline && e.key === 'Enter') {
|
||||||
|
// Let the textarea keep the Enter key for a new line.
|
||||||
|
e.stopPropagation();
|
||||||
|
return;
|
||||||
|
}
|
||||||
if (!multiline && e.key === 'Enter') {
|
if (!multiline && e.key === 'Enter') {
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
close();
|
close();
|
||||||
resolve(field.value);
|
resolve(field.value);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
field.addEventListener('input', () => {
|
||||||
|
if (typeof onInput === 'function') onInput(field.value);
|
||||||
|
});
|
||||||
|
|
||||||
setTimeout(() => field.focus(), 0);
|
setTimeout(() => field.focus(), 0);
|
||||||
});
|
});
|
||||||
|
|||||||
+87
-24
@@ -4,6 +4,7 @@
|
|||||||
|
|
||||||
const api = window.stepforge;
|
const api = window.stepforge;
|
||||||
const dialogs = window.StepForgeDialogs || {};
|
const dialogs = window.StepForgeDialogs || {};
|
||||||
|
const shortcuts = window.StepForgeShortcuts || {};
|
||||||
|
|
||||||
const clone = (value) => JSON.parse(JSON.stringify(value));
|
const clone = (value) => JSON.parse(JSON.stringify(value));
|
||||||
const BLOCK_KIND_ORDER = { text: 0, code: 1, table: 2 };
|
const BLOCK_KIND_ORDER = { text: 0, code: 1, table: 2 };
|
||||||
@@ -105,6 +106,24 @@ function isEditableTarget(target) {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function zoomShortcutFromEvent(e) {
|
||||||
|
if (shortcuts.zoomShortcutFromKeyboardEvent) {
|
||||||
|
return shortcuts.zoomShortcutFromKeyboardEvent(e);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!(e.ctrlKey || e.metaKey)) return null;
|
||||||
|
|
||||||
|
const { key, code, shiftKey } = e;
|
||||||
|
if (key === '0' || code === 'Digit0' || code === 'Numpad0') return 'fit';
|
||||||
|
if (
|
||||||
|
key === '+' || key === '=' || key === 'Add' || key === 'Plus' ||
|
||||||
|
code === 'Equal' || code === 'NumpadAdd' ||
|
||||||
|
(key === '=' && shiftKey) || (code === 'Equal' && shiftKey)
|
||||||
|
) return 'in';
|
||||||
|
if (key === '-' || key === '_' || key === 'Subtract' || key === 'Minus' || code === 'Minus' || code === 'NumpadSubtract') return 'out';
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
class GuideEditor {
|
class GuideEditor {
|
||||||
constructor({ root, onMetaChange = () => {}, onToast = toast, onBack = () => {} } = {}) {
|
constructor({ root, onMetaChange = () => {}, onToast = toast, onBack = () => {} } = {}) {
|
||||||
this.root = root;
|
this.root = root;
|
||||||
@@ -141,6 +160,13 @@ class GuideEditor {
|
|||||||
this.saveStepDebounced = debounce(() => this.flushStep(), 180);
|
this.saveStepDebounced = debounce(() => this.flushStep(), 180);
|
||||||
this.saveGuideDebounced = debounce(() => this.flushGuide(), 180);
|
this.saveGuideDebounced = debounce(() => this.flushGuide(), 180);
|
||||||
|
|
||||||
|
if (api.editor && typeof api.editor.onZoomShortcut === 'function') {
|
||||||
|
api.editor.onZoomShortcut((kind) => {
|
||||||
|
if (!this.active || !this.guide) return;
|
||||||
|
this.applyZoomShortcut(kind);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
this.onDocumentKeyDown = this.onDocumentKeyDown.bind(this);
|
this.onDocumentKeyDown = this.onDocumentKeyDown.bind(this);
|
||||||
document.addEventListener('keydown', this.onDocumentKeyDown, true);
|
document.addEventListener('keydown', this.onDocumentKeyDown, true);
|
||||||
}
|
}
|
||||||
@@ -152,6 +178,9 @@ class GuideEditor {
|
|||||||
|
|
||||||
setActive(active) {
|
setActive(active) {
|
||||||
this.active = Boolean(active);
|
this.active = Boolean(active);
|
||||||
|
if (api.editor && typeof api.editor.setCanvasZoomActive === 'function') {
|
||||||
|
api.editor.setCanvasZoomActive(this.active);
|
||||||
|
}
|
||||||
if (!this.active && this.guideId) {
|
if (!this.active && this.guideId) {
|
||||||
// Leaving the editor: flush pending debounced saves so navigation can
|
// Leaving the editor: flush pending debounced saves so navigation can
|
||||||
// never drop the last edit (failures keep the dirty state and retry),
|
// never drop the last edit (failures keep the dirty state and retry),
|
||||||
@@ -1182,7 +1211,6 @@ class GuideEditor {
|
|||||||
const typeSelect = makeSelect(selected.type, [
|
const typeSelect = makeSelect(selected.type, [
|
||||||
'rect', 'oval', 'line', 'arrow', 'text', 'tooltip', 'number', 'blur', 'highlight', 'magnify', 'cursor',
|
'rect', 'oval', 'line', 'arrow', 'text', 'tooltip', 'number', 'blur', 'highlight', 'magnify', 'cursor',
|
||||||
].map((type) => ({ value: type, label: ANNOTATION_TYPE_LABELS[type] || type })));
|
].map((type) => ({ value: type, label: ANNOTATION_TYPE_LABELS[type] || type })));
|
||||||
const textInput = el('input', { type: 'text', value: selected.text || '', placeholder: 'Annotation text' });
|
|
||||||
const valueInput = el('input', { type: 'number', value: Number.isFinite(selected.value) ? selected.value : '', placeholder: 'Value' });
|
const valueInput = el('input', { type: 'number', value: Number.isFinite(selected.value) ? selected.value : '', placeholder: 'Value' });
|
||||||
const strokeInput = el('input', { type: 'color', value: style.stroke || '#E5484D' });
|
const strokeInput = el('input', { type: 'color', value: style.stroke || '#E5484D' });
|
||||||
const fillInput = el('input', { type: 'color', value: style.fill && style.fill !== 'transparent' ? style.fill : '#ffffff' });
|
const fillInput = el('input', { type: 'color', value: style.fill && style.fill !== 'transparent' ? style.fill : '#ffffff' });
|
||||||
@@ -1218,9 +1246,17 @@ class GuideEditor {
|
|||||||
const fields = new Set(ANNOTATION_FIELDS[selected.type] || []);
|
const fields = new Set(ANNOTATION_FIELDS[selected.type] || []);
|
||||||
const strokeLabel = (selected.type === 'text' || selected.type === 'number') ? 'Color' : 'Stroke';
|
const strokeLabel = (selected.type === 'text' || selected.type === 'number') ? 'Color' : 'Stroke';
|
||||||
const typeLabel = ANNOTATION_TYPE_LABELS[selected.type] || selected.type;
|
const typeLabel = ANNOTATION_TYPE_LABELS[selected.type] || selected.type;
|
||||||
|
const textInput = fields.has('text')
|
||||||
|
? el('textarea', {
|
||||||
|
rows: Math.max(3, Math.min(8, String(selected.text || '').split('\n').length)),
|
||||||
|
placeholder: 'Annotation text',
|
||||||
|
spellcheck: true,
|
||||||
|
})
|
||||||
|
: el('input', { type: 'text', value: selected.text || '', placeholder: 'Annotation text' });
|
||||||
|
if (fields.has('text')) textInput.value = selected.text || '';
|
||||||
|
|
||||||
const rows = [labeledRow('Type', typeSelect)];
|
const rows = [labeledRow('Type', typeSelect)];
|
||||||
if (fields.has('text')) rows.push(labeledRow('Text', textInput));
|
if (fields.has('text')) rows.push(labeledRow('Text', textInput, { stacked: true }));
|
||||||
if (fields.has('value')) rows.push(labeledRow('Value', valueInput));
|
if (fields.has('value')) rows.push(labeledRow('Value', valueInput));
|
||||||
if (fields.has('stroke')) rows.push(labeledRow(strokeLabel, strokeInput));
|
if (fields.has('stroke')) rows.push(labeledRow(strokeLabel, strokeInput));
|
||||||
if (fields.has('fill')) rows.push(labeledRow('Fill', fillInput));
|
if (fields.has('fill')) rows.push(labeledRow('Fill', fillInput));
|
||||||
@@ -1348,6 +1384,22 @@ class GuideEditor {
|
|||||||
if (mode === 1.5) this.dom.zoom150Btn.classList.add('active');
|
if (mode === 1.5) this.dom.zoom150Btn.classList.add('active');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
applyZoomShortcut(kind) {
|
||||||
|
if (kind === 'in') {
|
||||||
|
this.setZoom(Math.min(3, (Number(this.currentZoom) || 1) + 0.25));
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
if (kind === 'out') {
|
||||||
|
this.setZoom(Math.max(0.25, (Number(this.currentZoom) || 1) - 0.25));
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
if (kind === 'fit') {
|
||||||
|
this.setZoom('fit');
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
pushCanvasHistory(recordOrLabel = 'change') {
|
pushCanvasHistory(recordOrLabel = 'change') {
|
||||||
if (!this.currentStep) return;
|
if (!this.currentStep) return;
|
||||||
const record = recordOrLabel && typeof recordOrLabel === 'object'
|
const record = recordOrLabel && typeof recordOrLabel === 'object'
|
||||||
@@ -2168,19 +2220,39 @@ class GuideEditor {
|
|||||||
async editAnnotationText(ann) {
|
async editAnnotationText(ann) {
|
||||||
const step = this.currentStep;
|
const step = this.currentStep;
|
||||||
if (!step || !ann) return;
|
if (!step || !ann) return;
|
||||||
|
const originalText = ann.text ?? '';
|
||||||
|
const applyText = (nextText, { persist = true } = {}) => {
|
||||||
|
const selected = this.canvas.selected();
|
||||||
|
if (!selected) return;
|
||||||
|
selected.text = nextText;
|
||||||
|
step.annotations = clone(this.canvas.annotations || []);
|
||||||
|
this.pendingSave = true;
|
||||||
|
this.canvas.setAnnotations(step.annotations || []);
|
||||||
|
this.renderAnnotationPanel();
|
||||||
|
this.emitMeta();
|
||||||
|
if (persist) this.saveStepDebounced();
|
||||||
|
};
|
||||||
const value = await dialogs.promptText({
|
const value = await dialogs.promptText({
|
||||||
title: ann.type === 'tooltip' ? 'Edit tooltip' : 'Edit text',
|
title: ann.type === 'tooltip' ? 'Edit tooltip' : 'Edit text',
|
||||||
label: 'Text',
|
label: 'Text',
|
||||||
value: ann.text || '',
|
value: originalText,
|
||||||
multiline: true,
|
multiline: true,
|
||||||
|
onInput: applyText,
|
||||||
});
|
});
|
||||||
if (value == null) return;
|
this.saveStepDebounced.cancel();
|
||||||
ann.text = value;
|
if (value == null) {
|
||||||
step.annotations = clone(step.annotations || []);
|
const current = this.canvas.selected();
|
||||||
this.pendingSave = true;
|
if ((current?.text ?? '') !== originalText) {
|
||||||
|
applyText(originalText, { persist: false });
|
||||||
|
}
|
||||||
|
await this.flushStep(step);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
const current = this.canvas.selected();
|
||||||
|
if ((current?.text ?? '') !== value) {
|
||||||
|
applyText(value, { persist: false });
|
||||||
|
}
|
||||||
await this.flushStep(step);
|
await this.flushStep(step);
|
||||||
this.renderAnnotationPanel();
|
|
||||||
this.emitMeta();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
formatDescription(command, block = null) {
|
formatDescription(command, block = null) {
|
||||||
@@ -2227,6 +2299,12 @@ class GuideEditor {
|
|||||||
|
|
||||||
onDocumentKeyDown(e) {
|
onDocumentKeyDown(e) {
|
||||||
if (!this.active || !this.guide) return;
|
if (!this.active || !this.guide) return;
|
||||||
|
const zoomShortcut = zoomShortcutFromEvent(e);
|
||||||
|
if (zoomShortcut) {
|
||||||
|
e.preventDefault();
|
||||||
|
this.applyZoomShortcut(zoomShortcut);
|
||||||
|
return;
|
||||||
|
}
|
||||||
if ((e.ctrlKey || e.metaKey) && e.key === '/' && !e.shiftKey) {
|
if ((e.ctrlKey || e.metaKey) && e.key === '/' && !e.shiftKey) {
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
this.openQuickActions();
|
this.openQuickActions();
|
||||||
@@ -2270,21 +2348,6 @@ class GuideEditor {
|
|||||||
if (next) this.selectStep(next.stepId);
|
if (next) this.selectStep(next.stepId);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if ((e.ctrlKey || e.metaKey) && (e.key === '=' || e.key === '+')) {
|
|
||||||
e.preventDefault();
|
|
||||||
this.setZoom(Math.min(3, (Number(this.currentZoom) || 1) + 0.25));
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if ((e.ctrlKey || e.metaKey) && e.key === '-') {
|
|
||||||
e.preventDefault();
|
|
||||||
this.setZoom(Math.max(0.25, (Number(this.currentZoom) || 1) - 0.25));
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if ((e.ctrlKey || e.metaKey) && e.key === '0') {
|
|
||||||
e.preventDefault();
|
|
||||||
this.setZoom('fit');
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
// Copy / paste the selected annotation.
|
// Copy / paste the selected annotation.
|
||||||
if ((e.ctrlKey || e.metaKey) && e.key.toLowerCase() === 'c' && this.selectedAnnotationId) {
|
if ((e.ctrlKey || e.metaKey) && e.key.toLowerCase() === 'c' && this.selectedAnnotationId) {
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
|
|||||||
@@ -21,6 +21,7 @@
|
|||||||
<div id="modal-root"></div>
|
<div id="modal-root"></div>
|
||||||
<div id="toast-root"></div>
|
<div id="toast-root"></div>
|
||||||
<script src="util.js"></script>
|
<script src="util.js"></script>
|
||||||
|
<script src="../shortcut-utils.js"></script>
|
||||||
<script src="canvas.js"></script>
|
<script src="canvas.js"></script>
|
||||||
<script src="dialogs.js"></script>
|
<script src="dialogs.js"></script>
|
||||||
<script src="editor.js"></script>
|
<script src="editor.js"></script>
|
||||||
|
|||||||
@@ -0,0 +1,55 @@
|
|||||||
|
'use strict';
|
||||||
|
|
||||||
|
(function attachShortcutUtils(root, factory) {
|
||||||
|
const api = factory();
|
||||||
|
if (typeof module !== 'undefined' && module.exports) {
|
||||||
|
module.exports = api;
|
||||||
|
}
|
||||||
|
if (root) {
|
||||||
|
root.StepForgeShortcuts = api;
|
||||||
|
}
|
||||||
|
})(typeof globalThis !== 'undefined' ? globalThis : this, () => {
|
||||||
|
function hasZoomModifier(source) {
|
||||||
|
return Boolean(source && (source.ctrlKey || source.metaKey || source.control || source.meta));
|
||||||
|
}
|
||||||
|
|
||||||
|
function zoomShortcutFromSource(source) {
|
||||||
|
if (!hasZoomModifier(source)) return null;
|
||||||
|
|
||||||
|
const key = String(source.key || '');
|
||||||
|
const code = String(source.code || '');
|
||||||
|
const shiftKey = Boolean(source.shiftKey || source.shift);
|
||||||
|
|
||||||
|
if (key === '0' || code === 'Digit0' || code === 'Numpad0') return 'fit';
|
||||||
|
|
||||||
|
if (
|
||||||
|
key === '+' || key === '=' || key === 'Add' || key === 'Plus' ||
|
||||||
|
code === 'Equal' || code === 'NumpadAdd' ||
|
||||||
|
(key === '=' && shiftKey) || (code === 'Equal' && shiftKey)
|
||||||
|
) {
|
||||||
|
return 'in';
|
||||||
|
}
|
||||||
|
|
||||||
|
if (
|
||||||
|
key === '-' || key === '_' || key === 'Subtract' || key === 'Minus' ||
|
||||||
|
code === 'Minus' || code === 'NumpadSubtract'
|
||||||
|
) {
|
||||||
|
return 'out';
|
||||||
|
}
|
||||||
|
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
function zoomShortcutFromKeyboardEvent(event) {
|
||||||
|
return zoomShortcutFromSource(event);
|
||||||
|
}
|
||||||
|
|
||||||
|
function zoomShortcutFromInputEvent(input) {
|
||||||
|
return zoomShortcutFromSource(input);
|
||||||
|
}
|
||||||
|
|
||||||
|
return {
|
||||||
|
zoomShortcutFromInputEvent,
|
||||||
|
zoomShortcutFromKeyboardEvent,
|
||||||
|
};
|
||||||
|
});
|
||||||
@@ -0,0 +1,26 @@
|
|||||||
|
'use strict';
|
||||||
|
|
||||||
|
const test = require('node:test');
|
||||||
|
const assert = require('node:assert/strict');
|
||||||
|
|
||||||
|
const {
|
||||||
|
zoomShortcutFromInputEvent,
|
||||||
|
zoomShortcutFromKeyboardEvent,
|
||||||
|
} = require('../../app/shortcut-utils');
|
||||||
|
|
||||||
|
test('zoom shortcut helper recognizes zoom in, out, and fit across event shapes', () => {
|
||||||
|
assert.equal(zoomShortcutFromKeyboardEvent({ ctrlKey: true, key: '=', code: 'Equal' }), 'in');
|
||||||
|
assert.equal(zoomShortcutFromKeyboardEvent({ ctrlKey: true, key: '+', code: 'NumpadAdd' }), 'in');
|
||||||
|
assert.equal(zoomShortcutFromKeyboardEvent({ ctrlKey: true, key: 'Plus', code: 'Equal' }), 'in');
|
||||||
|
assert.equal(zoomShortcutFromKeyboardEvent({ ctrlKey: true, key: '-', code: 'Minus' }), 'out');
|
||||||
|
assert.equal(zoomShortcutFromKeyboardEvent({ metaKey: true, key: '0', code: 'Digit0' }), 'fit');
|
||||||
|
assert.equal(zoomShortcutFromKeyboardEvent({ ctrlKey: true, key: '=', code: 'Equal', shiftKey: true }), 'in');
|
||||||
|
});
|
||||||
|
|
||||||
|
test('zoom shortcut helper recognizes Electron before-input-event payloads', () => {
|
||||||
|
assert.equal(zoomShortcutFromInputEvent({ control: true, key: '=', code: 'Equal' }), 'in');
|
||||||
|
assert.equal(zoomShortcutFromInputEvent({ control: true, key: '=', code: 'Equal', shift: true }), 'in');
|
||||||
|
assert.equal(zoomShortcutFromInputEvent({ control: true, key: 'Plus', code: 'Equal', shift: true }), 'in');
|
||||||
|
assert.equal(zoomShortcutFromInputEvent({ control: true, key: '-', code: 'Minus' }), 'out');
|
||||||
|
assert.equal(zoomShortcutFromInputEvent({ meta: true, key: '0', code: 'Digit0' }), 'fit');
|
||||||
|
});
|
||||||
Reference in New Issue
Block a user