Skip to content

Make preview overlay's inset configurable via CSS variable#95

Merged
cyanzhong merged 2 commits intoMarkEdit-app:mainfrom
gpolitis:inset-left-css-variable
Apr 29, 2026
Merged

Make preview overlay's inset configurable via CSS variable#95
cyanzhong merged 2 commits intoMarkEdit-app:mainfrom
gpolitis:inset-left-css-variable

Conversation

@gpolitis
Copy link
Copy Markdown
Contributor

Why

Third-party plugins that occupy a slice on the left edge of the viewport (e.g. a TOC sidebar) can't currently coexist with preview-only mode: .markdown-body.overlay uses position: absolute; inset: 0 against the viewport, ignoring any padding-inline-start on body. The only workaround is !important overrides targeting preview's class names, which is fragile.

Concrete example — my outline plugin currently ships with this compatibility shim:

https://github.com/gpolitis/MarkEdit-outline/blob/2cbbea0bb99de604a5a1cf73862155bcb95e8ee3/markedit-outline.js#L164-L170

The shim works but couples the two plugins via class-name targeting, which silently breaks if either side renames a class.

What

Replace inset: 0 with explicit per-side values, reading left from a CSS custom property with a 0 fallback:

left: var(--markedit-content-inset-left, 0);

A plugin that claims a left slice declares the variable on body when active:

body.my-plugin-active {
  --markedit-content-inset-left: 268px;
}

CSS custom properties cascade through the DOM, so preview's overlay pane picks it up automatically.

Backward compatibility

When no plugin sets the variable, 0 is used and the layout is byte-identical to today. No other selectors changed.

Scope

Scoped to left only since that's the only side affected today. If future plugins need other edges, mirror variables for top/right/bottom are a natural addition — leaving that for when there's a concrete use case.

In preview-only mode, the preview pane uses position:absolute + inset:0,
which is sized against the viewport regardless of any padding on body.
That makes it impossible for a third-party plugin (e.g. a left-edge
sidebar) to coexist with preview mode without overriding this rule via
class-name targeting.

Replace inset:0 with explicit top/right/bottom values plus
left: var(--markedit-content-inset-left, 0). The fallback keeps
existing behaviour identical when no plugin sets the variable.

Plugins that occupy a horizontal slice on the left can now declare
their offset via the CSS variable and compose cleanly with preview
overlay mode without reaching into preview's class names.
@cyanzhong
Copy link
Copy Markdown
Contributor

cyanzhong commented Apr 29, 2026

Thank you for your contribution. The idea makes sense to me.

Comment thread styles/main.css Outdated
top: 0;
right: 0;
bottom: 0;
left: var(--markedit-content-inset-left, 0);
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@gpolitis Instead of only left, what about make inset a variable?

Do you think if it will be more useful or too much?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good call, agreed. Pushed 5beca15 switching to a single --markedit-content-inset variable. Plugins set the shorthand (e.g. --markedit-content-inset: 0 0 0 268px;), and calc() / nested var() work inside it.

Per review feedback: cover all four edges with one shorthand-valued
custom property instead of a per-side variable for left only.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@cyanzhong cyanzhong changed the title Make preview overlay's left edge configurable via CSS variable Make preview overlay's inset configurable via CSS variable Apr 29, 2026
@cyanzhong cyanzhong merged commit 78dc9da into MarkEdit-app:main Apr 29, 2026
1 check passed
@gpolitis
Copy link
Copy Markdown
Contributor Author

Thank you for accepting this!

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.

2 participants