Skip to content

emrg: draggable, resizable annotation panel, and annotations on the HTML preview - #3303

Merged
argszero merged 1 commit into
masterfrom
anno-panel-drag-resize
Dec 3, 2026
Merged

argszero merged 1 commit into
masterfrom
anno-panel-drag-resize

Conversation

@argszero

@argszero argszero commented Dec 3, 2026

Copy link
Copy Markdown
Owner

What the host asked for

The annotation panel could not be moved or resized, and the HTML preview could not be annotated at all. Two different causes:

  • The chat panel's position was written in annotation.css (position: fixed; top: 76px; right: 20px; width: 340px), so every person on every window got the same box.
  • The preview is a WebContentsView the main process composites above the app window. A DOM layer in the renderer sits under it, so the app's own floating panel can never hang over a previewed page.

What changed

The panel's box is state. lib/annotation.ts gains PanelBox, defaultPanelBox, clampBox, storedPanelBox and persistPanelBox. The header is the drag handle, the bottom-right corner is the only resize surface, a double-click puts it back, and the position is remembered across a close. The one rule the stylesheet carried — never larger than the window — moved into clampBox, because a style sheet cannot clamp a value a drag produces. While a drag is in flight the body gets anno-dragging, the same bargain col-resizing makes for a column handle: the pointer crosses the reply on its way, and a selection there would create an annotation mid-drag.

The preview gets its own panel, drawn inside the page. preview-preload.js runs in a sandboxed preload's own world and builds its interface behind a closed shadow root. It hands the page nothing: no contextBridge, no exposeInMainWorld, no window.emrg. Selecting text wraps it in a <mark>, the containing block becomes the quote, and the element path becomes the address — the rendered words are not the source words, so the file and the element are what make an annotation locatable again.

The batch is text, and one sender is allowed. The preload answers { items: [{ paragraph, body, selector }] }; main.js forwards it only when event.sender === previewView.webContents, and the file comes from its own previewPath, never from the page. The renderer receives it through onPreviewAnnotation (preload's second subscription) and sends it through the composer — queueing, the user record and the session all live on that one path, as with the transcript's batch.

composeMessage grew an optional source so a previewed page's annotation names its address; a message without one is byte-identical to what it produced before, and a test holds that half still.

Tests

  • lib/annotation.test.ts: the default box, the clamp into a shrunken window, the floor a drag cannot pass, a corrupt stored value, the round trip, and the source line staying inside the item it belongs to.
  • AnnotationMode.test.tsx: drag by header, clamped at the window's edge, resize from the corner, stopped at the floor, remembered across a close, reset by double-click. The old case that pinned max-height: calc(100vh - 168px) now measures the panel's real size against the window, because the bound moved from the stylesheet into clampBox.
  • preview-annotation-wiring.test.js (new): the preview view loads the preload, the browser view loads none, the preload hands the page nothing (comment-stripped, so a mention in prose is not a call), only the preview view's own webContents can send a batch up, and the renderer composes through the composer.
  • preload-api.test.js: the subscription surface became method → channel, so onPreviewAnnotation is frozen like onEvent is.

Readings taken here

  • Renderer: npm run typecheck clean, npm test 1282 passed / 67 files.
  • Main process: npm test 272 pass, 8 skipped, 0 fail (279 executed).
  • pytest tests/test_doc_counts.py 82 passed, tests/test_agent_md_prompt_cap.py 6 passed.

Not here

Marks are not reattached after a preview reloads: that layer keeps no store, and an annotation that silently moved is worse than one that is gone. Persisting them across a reload is its own change.

…he HTML preview

The panel was pinned by the stylesheet at one position for every window
(`top: 76px; right: 20px; width: 340px`), and the HTML preview could not be
annotated at all: it is a `WebContentsView` the main process composites above
the app, so no DOM layer in the renderer can cover it.

The chat panel's box is state now. The header is the drag handle, the corner is
the only resize surface, a double-click puts it back, and the position survives
a close because `persistPanelBox` writes it. The one rule the CSS carried -
never larger than the window - moved into `clampBox` with it, since a style
sheet cannot clamp a value a drag produces.

The preview gets its own panel, drawn inside the page it previews:
`preview-preload.js` runs in a sandboxed preload's own world behind a closed
shadow root and hands the page nothing - no `contextBridge`, no `window.emrg`.
A batch leaves as plain strings and the main process forwards it only when the
sender is the preview view itself, with the file path taken from its own
`previewPath` rather than from the page. It arrives in the renderer through
`onPreviewAnnotation` and leaves through the composer, the same door the
transcript's own batch uses.

`sandbox: true` on the browser view is unchanged and still loads no preload,
which `preview-annotation-wiring.test.js` pins: that view exists to show remote
pages, and the page reaching nothing is its boundary.
@argszero
argszero merged commit 803bc3b into master Dec 3, 2026
2 checks passed
@argszero
argszero deleted the anno-panel-drag-resize branch December 3, 2026 10:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant