fix: make the error dialog caret point at the character it's blaming (#14886)

* fix: make the error dialog caret point at the character it's blaming

Custom G-code parse errors print the offending line with a '^' under the
character that broke, positioned with spaces so it only lines up in a
fixed-width font. Since v2.3.2 these dialogs rendered entirely in the
proportional UI font, so the caret drifted left of its column and landed
on unrelated text.

Render only the code excerpts (the offending source line and its caret) in
the fixed-width face, leaving the surrounding prose in the UI font, and
reserve the horizontal scrollbar's height so a long line does not clip.
Rename the flag to has_code_excerpts to match what it now means.

Fixes #14869

* refactor(GUI): use <code> instead of <tt> for error excerpts

wxHTML maps <tt>, <code>, <kbd> and <samp> to the same fixed-width
handler, so this renders identically. <code> is the non-deprecated
tag and matches what the original code used.

* fix(GUI): align the error caret with real spaces, not &nbsp;

The caret line was padded with &nbsp; so its spaces would survive inline
HTML. wxHTML measures every glyph by its font extent, so where the fixed
font lacks a U+00A0 glyph the fallback renders it about twice as wide, and
the all-&nbsp; caret line outran the source, drifting the ^ to the right.

Wrap the excerpts in a small <excerpt> tag, registered on the dialog's own
parser, that switches on wxHTML literal-whitespace mode so the caret uses
real spaces that match the source column in any font. It sits inside <code>
for the fixed face; <pre> would do both but forces a blank line above it.

---------

Co-authored-by: Noisyfox <timemanager.rick@gmail.com>
This commit is contained in:
Kris Austin
2026-08-04 09:01:45 -05:00
committed by GitHub
parent 59155f26ac
commit 82759d3899
5 changed files with 120 additions and 30 deletions

View File

@@ -1791,6 +1791,8 @@ namespace client
// from UTF8 to UTF16 don't bail out.
msg += boost::nowide::narrow(boost::nowide::widen(error_line));
msg += '\n';
// The error dialog (MsgDialog.cpp) renders this excerpt monospaced. It recognizes a source
// line directly above a caret line of spaces and a single '^'.
for (size_t i = 0; i < error_pos; ++ i)
msg += ' ';
msg += "^\n";