Skip to content

Commit

Permalink
Set iframe background color on neovim's default_colors_set (#1637)
Browse files Browse the repository at this point in the history
Issue #1637 reports that resizing the underlying textarea of a Firenvim
iframe can result in flashes of color. This can be particularly visible
when using Firenvim with a dark colorscheme on Github in dark mode.

The reason for these flashes of color is that when resizing, the iframe
gets resized first and the Neovim canvas gets resized second, between
these two moments, the iframe's background color can become visible if
the CSS colorscheme of the iframe and of the website do not match.

We fix this by ensuring that the iframe's background color is set to the
background color of the Neovim colorscheme. This breaks the ability of
the iframe to turn transparent when unfocused (the iframe gets dimmed
instead), but given that multiple users complained about this feature,
it may not be such a bad change.

Closes #1637.
  • Loading branch information
glacambre committed Sep 25, 2024
1 parent 25d6278 commit ee47cad
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 2 deletions.
5 changes: 5 additions & 0 deletions src/Neovim.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,11 @@ export async function neovim(
CanvasRenderer.events.on("frameResize", ({width, height}: any) => {
page.resizeEditor(width, height);
});
CanvasRenderer.events.on("colorChange", (({background, foreground}: any) => {
const e = canvas.ownerDocument.documentElement;
e.style.backgroundColor = background;
e.style.color = foreground;
}));

let prevNotificationPromise = Promise.resolve();
const socket = new WebSocket(`ws://127.0.0.1:${port}/${password}`);
Expand Down
2 changes: 1 addition & 1 deletion src/frame.ts
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ export const isReady = browser
nvim.nvim_command("doautocmd FocusGained");
});
window.addEventListener("blur", () => {
document.documentElement.style.opacity = "0.5";
document.documentElement.style.opacity = "0.7";
nvim.nvim_command("doautocmd FocusLost");
});
keyHandler.focus();
Expand Down
3 changes: 2 additions & 1 deletion src/renderer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ type ResizeEvent = {grid: number, width: number, height: number};
type FrameResizeEvent = {width: number, height: number}
type ModeChangeEvent = NvimMode;
type ResizeEventHandler = (e: ResizeEvent | FrameResizeEvent | ModeChangeEvent) => void;
type EventKind = "resize" | "frameResize" | "modeChange" | "mouseOn" | "mouseOff";
type EventKind = "colorChange" | "resize" | "frameResize" | "modeChange" | "mouseOn" | "mouseOff";
export const events = new EventEmitter<EventKind, ResizeEventHandler>();

let glyphCache : any = {};
Expand Down Expand Up @@ -420,6 +420,7 @@ const handlers : { [key:string] : (...args: any[])=>void } = {
if (sp !== undefined && sp !== -1) {
globalState.highlights[0].special = toHexCss(sp);
}
events.emit("colorChange", globalState.highlights[0]);
const curGridSize = globalState.gridSizes[getGridId()];
if (curGridSize !== undefined) {
pushDamage(getGridId(), DamageKind.Cell, curGridSize.height, curGridSize.width, 0, 0);
Expand Down

0 comments on commit ee47cad

Please sign in to comment.