WebView: block cursor glyph becomes vertically misaligned after decreasing font size (C--)

Open
#2,336 0 comments 0 reactions 0 assignees View on GitHub

Maintainers usually reply within 1 day

Nobody has claimed this yet.

Assessment

Difficulty
3/5
Estimated time
1-2 days
Newbie friendliness
55/100
Issue type
Bug
Clarity
Mostly clear
Activity status
Active
Tech stack
css, html, javascript
Domain
frontend

Research direction

Start with frontends/server/frontend/editor.js and compare the Canvas text path (drawText, textBaseline, and textOffsetY) with the .lem-cursor HTML text styling. Reproduce in the native WebView frontend by reducing the font size with C-- and checking block cursor alignment against adjacent text. Done when the cursor character stays aligned after font-size changes; the proposed canvas workaround is unverified, and no regression test is named.

Written by the indexing model from the issue text.

Description

Description

Thank you for Lem and the WebView frontend! I installed the package today
(October 4, 2026), and overall it is working very well. During this first
session, I noticed the following rendering issue.

In the native WebView frontend, reducing the font size with C-- makes
the character drawn inside the block cursor appear vertically displaced
relative to the buffer text. The editor otherwise works well.

I tested several buffers and consistently observed the same bug.
This appears to be a general WebView font-size alignment problem.
The screenshot I inspected happens to show an Org buffer; organ-mode is
not a reproduction requirement. Testing with a minimal configuration
remains pending.

Steps to reproduce

  1. Launch the native WebView frontend.
  2. Open a buffer containing text.
  3. Reduce the font size with C-- (Control + minus).
  4. Move the block cursor onto a visible character.
  5. Compare the character inside the cursor with the adjacent text.

The exact number of font-size reductions and final font size were not recorded.
This uses Lem's font-size command, rather than browser page zoom.

Expected behavior

The character inside the block cursor remains aligned with the buffer's
text after font-size changes.

Actual behavior

The cursor's character appears lower than the surrounding text. In the
observed screenshot, the * inside the cursor appears between text lines.

Environment

  • GNU Guix, Linux, X11, StumpWM.
  • Lem revision: ef6c48eb56575bb3ffe648c30846321b2a5d7e2f.
  • Native WebView frontend using GTK4 / WebKitGTK 6.0.
  • Native webview library: 0.12.0.
  • Font initially configured as 18px Monospace; reduced via C--.
  • The screenshot buffer has organ-mode and transient-mode enabled; I
    also observed the bug consistently in several other buffers.
  • Custom Guix package with local HTTP authentication and asset-path patches.
    The initial screenshot predates the cursor-specific workaround described below.
    Whether the latest running image includes that workaround has not been verified.

This report concerns the pinned revision above; reproduction on current
upstream HEAD has not been checked.

Screenshot observation

In an Org buffer, the character inside the block cursor at the beginning
of a heading appears below the heading text, toward the following line.
The Org heading is only an example of the general alignment symptom.
A screenshot is available locally, but is not attached to this report yet.

Investigation / possible cause

In frontends/server/frontend/editor.js, buffer text is rendered through
Canvas drawText, with textBaseline = 'top' and textOffsetY = 5.
The block cursor instead renders its character as HTML text in .lem-cursor,
using CSS font metrics and padding. These two rendering paths may produce
different vertical alignment as the font size changes.

This is a hypothesis, not a confirmed root cause.

A local workaround renders the cursor character in a small canvas using
the buffer's existing drawText function and devicePixelRatio. JavaScript
checks and the Guix build pass, but a visual font-size regression test of
that workaround is still pending. It should not yet be treated as a verified fix.

Possibly related report

Flashing Cursor placement is Incorrect with Lem Webview (on macos), #2251.

This Linux report may be additional evidence for that issue; whether the
underlying cause is the same has not been established.

Dominant language
Common Lisp
Stars
3.1k
Forks
261
Avg merge
1d 6h
Merged PRs (30d)
133

Getting set up

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from lem-project/lem

All issues in lem-project/lem

Similar issues

More Web Dev issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.