mirror of
https://github.com/PR0M3TH3AN/unredact.git
synced 2026-10-27 08:40:29 +00:00
fix: remove inline-edit feature and backspace delete keybinding
- Delete inline-edit.js and all references - Remove backspace/delete key handler for redaction deletion - Clean up popover.js syncInlineEdit references Co-Authored-By: Claude Opus 4.6 <[email protected]>
This commit is contained in:
1 parent
f1e25f9712
commit
9f5ceb38ae
5 files changed
+5
-127
No files matched your search
@@ -132,7 +132,6 @@
|
||||
<div id="doc-container">
|
||||
<img id="doc-image" alt="Document page">
|
||||
<canvas id="overlay-canvas"></canvas>
|
||||
<div id="inline-edit-layer"></div>
|
||||
</div>
|
||||
<div id="text-edit-bar" hidden>
|
||||
<input type="text" id="left-text-input" class="seg-input" spellcheck="false" autocomplete="off" placeholder="left text">
|
||||
|
||||
@@ -1,102 +0,0 @@
|
||||
// @ts-check
|
||||
/**
|
||||
* Inline text editing — HTML inputs positioned on the canvas at
|
||||
* the left/right text locations so users edit directly on the document.
|
||||
*/
|
||||
import { state } from './state.js';
|
||||
import { renderCanvas } from './canvas.js';
|
||||
|
||||
const layer = document.getElementById("inline-edit-layer");
|
||||
|
||||
let leftInput = null;
|
||||
let rightInput = null;
|
||||
|
||||
/**
|
||||
* Show inline text inputs for the active redaction.
|
||||
* @param {string} id - Redaction ID
|
||||
*/
|
||||
export function showInlineEdit(id) {
|
||||
hideInlineEdit();
|
||||
|
||||
const r = state.redactions[id];
|
||||
if (!r?.analysis || !r?.overrides) return;
|
||||
|
||||
const a = r.analysis;
|
||||
const o = r.overrides;
|
||||
const fontSize = o.fontSize || a.font.size;
|
||||
const offsetX = o.offsetX || 0;
|
||||
const offsetY = o.offsetY || 0;
|
||||
const lineX = a.line.x + offsetX;
|
||||
const lineY = a.line.y + offsetY;
|
||||
const gapWidth = o.gapWidth || a.gap.w;
|
||||
|
||||
const leftText = o.leftText || "";
|
||||
const rightText = o.rightText || "";
|
||||
|
||||
// Left input: positioned at the start of the line, width up to the gap
|
||||
const leftWidth = Math.max(30, r.x - lineX);
|
||||
leftInput = _createInput(leftText, lineX, lineY, leftWidth, a.line.h, fontSize);
|
||||
leftInput.style.textAlign = "right";
|
||||
leftInput.addEventListener("input", () => {
|
||||
r.overrides.leftText = leftInput.value;
|
||||
renderCanvas();
|
||||
_syncTextEditBar(r);
|
||||
});
|
||||
|
||||
// Right input: positioned after the gap
|
||||
const rightX = r.x + gapWidth;
|
||||
const rightW = Math.max(50, (a.line.x + a.line.w) - rightX + 20);
|
||||
rightInput = _createInput(rightText, rightX, lineY, rightW, a.line.h, fontSize);
|
||||
rightInput.addEventListener("input", () => {
|
||||
r.overrides.rightText = rightInput.value;
|
||||
renderCanvas();
|
||||
_syncTextEditBar(r);
|
||||
});
|
||||
|
||||
layer.appendChild(leftInput);
|
||||
layer.appendChild(rightInput);
|
||||
}
|
||||
|
||||
/** Remove all inline edit inputs. */
|
||||
export function hideInlineEdit() {
|
||||
if (leftInput) { leftInput.remove(); leftInput = null; }
|
||||
if (rightInput) { rightInput.remove(); rightInput = null; }
|
||||
}
|
||||
|
||||
/** Update input values from state (e.g., after text reset or popover bar edit). */
|
||||
export function syncInlineEdit(id) {
|
||||
const r = state.redactions[id];
|
||||
if (!r?.overrides) return;
|
||||
if (leftInput) leftInput.value = r.overrides.leftText;
|
||||
if (rightInput) rightInput.value = r.overrides.rightText;
|
||||
}
|
||||
|
||||
function _syncTextEditBar(r) {
|
||||
// Keep the bottom text edit bar in sync
|
||||
const leftEl = document.getElementById("left-text-input");
|
||||
const rightEl = document.getElementById("right-text-input");
|
||||
if (leftEl) leftEl.value = r.overrides.leftText;
|
||||
if (rightEl) rightEl.value = r.overrides.rightText;
|
||||
}
|
||||
|
||||
function _createInput(value, x, y, w, h, fontSize) {
|
||||
const input = document.createElement("input");
|
||||
input.type = "text";
|
||||
input.value = value;
|
||||
Object.assign(input.style, {
|
||||
position: "absolute",
|
||||
left: x + "px",
|
||||
top: y + "px",
|
||||
width: Math.max(30, w) + "px",
|
||||
height: h + "px",
|
||||
fontSize: fontSize + "px",
|
||||
background: "rgba(255,255,255,0.7)",
|
||||
border: "1px solid rgba(0,180,0,0.5)",
|
||||
padding: "0 2px",
|
||||
pointerEvents: "auto",
|
||||
boxSizing: "border-box",
|
||||
outline: "none",
|
||||
fontFamily: "sans-serif",
|
||||
});
|
||||
return input;
|
||||
}
|
||||
+2
-13
@@ -12,7 +12,7 @@ import { renderCanvas } from './canvas.js';
|
||||
import { applyTransform, screenToDoc, hitTestRedaction, initViewport } from './viewport.js';
|
||||
import { openPopover, closePopover, setOnPopoverClose, updatePosDisplay, initPopover } from './popover.js';
|
||||
import { stopSolve, acceptSolution, initSolver } from './solver.js';
|
||||
import { showInlineEdit, hideInlineEdit, syncInlineEdit } from './inline-edit.js';
|
||||
|
||||
|
||||
// ── Font loading ──
|
||||
|
||||
@@ -329,7 +329,6 @@ function activateRedaction(id) {
|
||||
|
||||
if (r.status === "analyzed" || r.status === "solved") {
|
||||
openPopover(id);
|
||||
showInlineEdit(id);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -581,21 +580,11 @@ document.addEventListener("keydown", (e) => {
|
||||
e.preventDefault();
|
||||
exportAnnotations();
|
||||
}
|
||||
if ((e.key === "Delete" || e.key === "Backspace") && state.activeRedaction) {
|
||||
// Don't delete if user is typing in an input
|
||||
if (e.target.tagName === "INPUT" || e.target.tagName === "TEXTAREA") return;
|
||||
delete state.redactions[state.activeRedaction];
|
||||
state.activeRedaction = null;
|
||||
closePopover();
|
||||
renderRedactionList();
|
||||
renderCanvas();
|
||||
showToast("Redaction deleted");
|
||||
}
|
||||
});
|
||||
|
||||
// ── Initialize all modules ──
|
||||
|
||||
setOnPopoverClose(() => { stopSolve(); hideInlineEdit(); });
|
||||
setOnPopoverClose(stopSolve);
|
||||
initViewport();
|
||||
initPopover();
|
||||
initSolver();
|
||||
@@ -14,7 +14,6 @@ import {
|
||||
solveMode, filterLabel,
|
||||
} from './dom.js';
|
||||
import { renderCanvas } from './canvas.js';
|
||||
import { syncInlineEdit } from './inline-edit.js';
|
||||
|
||||
/** @type {(() => void)|null} */
|
||||
let _onClose = null;
|
||||
@@ -141,7 +140,7 @@ export function initPopover() {
|
||||
if (!r?.overrides) return;
|
||||
r.overrides.leftText = leftTextInput.value;
|
||||
renderCanvas();
|
||||
syncInlineEdit(state.activeRedaction);
|
||||
|
||||
});
|
||||
|
||||
rightTextInput.addEventListener("input", () => {
|
||||
@@ -149,7 +148,7 @@ export function initPopover() {
|
||||
if (!r?.overrides) return;
|
||||
r.overrides.rightText = rightTextInput.value;
|
||||
renderCanvas();
|
||||
syncInlineEdit(state.activeRedaction);
|
||||
|
||||
});
|
||||
|
||||
textReset.addEventListener("click", () => {
|
||||
@@ -161,7 +160,7 @@ export function initPopover() {
|
||||
leftTextInput.value = r.overrides.leftText;
|
||||
rightTextInput.value = r.overrides.rightText;
|
||||
renderCanvas();
|
||||
syncInlineEdit(state.activeRedaction);
|
||||
|
||||
});
|
||||
|
||||
solveTolerance.addEventListener("input", () => {
|
||||
|
||||
@@ -280,13 +280,6 @@ main {
|
||||
pointer-events: auto;
|
||||
}
|
||||
|
||||
#inline-edit-layer {
|
||||
position: absolute;
|
||||
top: 0;
|
||||
left: 0;
|
||||
pointer-events: none;
|
||||
transform-origin: 0 0;
|
||||
}
|
||||
|
||||
.loading {
|
||||
color: var(--accent);
|
||||
|
||||
Reference in new issue
Block a user