Skip to content

Add UseThemeBackground property to Editor#81

Merged
tig merged 6 commits into
developfrom
copilot/fix-editor-background-attribute
May 12, 2026
Merged

Add UseThemeBackground property to Editor#81
tig merged 6 commits into
developfrom
copilot/fix-editor-background-attribute

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented May 12, 2026

Syntax-highlighted tokens carry their own background color (e.g. Dark Plus's #1E1E1E), which conflicts with the active TG theme's Normal background — visible as mismatched backgrounds in themes like Anders.

Adds UseThemeBackground (default true) matching the semantics of TG's Markdown View: when enabled, highlighted tokens keep both their foreground and background from the syntax highlighting theme, and the viewport is filled with ISyntaxHighlighter.DefaultBackground so empty cells are consistent. When disabled, the highlighter's background is overridden with the TG scheme's Normal background.

  • Editor.cs — New UseThemeBackground property; invalidates visual-line caches and redraws on change. Passes value through to VisualLineBuildContext.
  • Editor.Drawing.cs — New FillViewportBackground method fills the viewport with ISyntaxHighlighter.DefaultBackground when UseThemeBackground is true, ensuring empty cells match per-token backgrounds.
  • VisualLineBuildContext.cs — New UseThemeBackground parameter/property.
  • VisualLineBuilder.csGetAttribute replaces styled-segment background with NormalAttribute.Background when UseThemeBackground is false (i.e., user opts out of the syntax theme's background).
  • EditorRenderingTests.cs — Three new tests covering default value, background override (false), and preservation (true).
  • TedApp.cs — Added "Use Theme Background" checkbox to the Options menu (checked by default), toggling Editor.UseThemeBackground via the Action pattern.
// Default: highlighted text uses the syntax theme's background (e.g. Dark Plus #1E1E1E)
editor.UseThemeBackground = true;

// Opt out: override highlighter bg with the TG scheme's Normal background
editor.UseThemeBackground = false;

Copilot AI assigned Copilot and tig May 12, 2026
Copilot AI linked an issue May 12, 2026 that may be closed by this pull request
When true (the default), syntax-highlighted tokens use the base
Normal background instead of the background supplied by the syntax
highlighter, so the editor blends into the surrounding theme.

Fixes the issue where the editor background was inconsistent with
the theme's Normal background when syntax highlighting was active.

Agent-Logs-Url: https://github.com/gui-cs/Text/sessions/30aff306-af60-4170-890c-2cde2267ebef

Co-authored-by: tig <585482+tig@users.noreply.github.com>
@tig
Copy link
Copy Markdown
Member

tig commented May 12, 2026

Add an options menu to Ted for this setting. Default should be checked.

@tig
Copy link
Copy Markdown
Member

tig commented May 12, 2026

@copilot Add an options menu to Ted for this setting. Default should be checked.

Copilot AI changed the title [WIP] Fix editor background attribute to use theme configuration Add UseThemeBackground property to Editor May 12, 2026
Copilot AI requested a review from tig May 12, 2026 13:54
Copilot finished work on behalf of tig May 12, 2026 13:54
@tig tig marked this pull request as ready for review May 12, 2026 13:55
Adds a checked checkbox in Options > Use Theme Background that
toggles Editor.UseThemeBackground. Default is checked (true).

Agent-Logs-Url: https://github.com/gui-cs/Text/sessions/04a93e8d-10c9-429a-888b-170fdd5fa584

Co-authored-by: tig <585482+tig@users.noreply.github.com>
Copy link
Copy Markdown
Contributor Author

Copilot AI commented May 12, 2026

@copilot Add an options menu to Ted for this setting. Default should be checked.

Added in b037315. The Options menu now has a "Use Theme Background" checkbox (checked by default) that toggles Editor.UseThemeBackground.

Copilot finished work on behalf of tig May 12, 2026 13:57
@tig
Copy link
Copy Markdown
Member

tig commented May 12, 2026

@copilot I think you have the logic backwards. And when (using current logic) it's unchecked, it is not using the correct background. See image.

image

Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 3d4ee72566

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread src/Terminal.Gui.Editor/Rendering/VisualLineBuilder.cs
UseThemeBackground=true now means "use the syntax highlighting theme's
background" (e.g. Dark Plus #1E1E1E), matching Terminal.Gui's Markdown
view convention. When true, the viewport is also filled with the
highlighter's DefaultBackground so empty cells match.

UseThemeBackground=false overrides the highlighter's background with
the TG scheme's Normal background.

Also switches ted's menu item to the Action pattern (matching
lineNumbersCheckBox) for reliable toggle behavior.

Agent-Logs-Url: https://github.com/gui-cs/Text/sessions/cef8e227-1d3b-4069-8f43-f532a295fc69

Co-authored-by: tig <585482+tig@users.noreply.github.com>
@chatgpt-codex-connector
Copy link
Copy Markdown

Codex usage limits have been reached for code reviews. Please check with the admins of this repo to increase the limits by adding credits.
Credits must be used to enable repository wide code reviews.

@tig
Copy link
Copy Markdown
Member

tig commented May 12, 2026

@copilot make sure you do code cleanup on the code you touched.

@chatgpt-codex-connector
Copy link
Copy Markdown

Codex usage limits have been reached for code reviews. Please check with the admins of this repo to increase the limits by adding credits.
Credits must be used to enable repository wide code reviews.

Copy link
Copy Markdown
Contributor Author

Copilot AI commented May 12, 2026

@copilot I think you have the logic backwards. And when (using current logic) it's unchecked, it is not using the correct background. See image.

<img width="527" height="329" alt="image" src="https...

Fixed in 6715c7a. The logic was indeed backwards — I had the semantics inverted from TG's Markdown convention. Now:

  • UseThemeBackground = true (checked, default) → preserves the syntax highlighting theme's background (e.g. Dark Plus #1E1E1E) and fills the viewport with ISyntaxHighlighter.DefaultBackground
  • UseThemeBackground = false (unchecked) → overrides the highlighter's background with the TG scheme's Normal background

Also switched the menu item to the Action pattern (matching lineNumbersCheckBox) for reliable toggle behavior.

Copy link
Copy Markdown
Contributor Author

Copilot AI commented May 12, 2026

@copilot make sure you do code cleanup on the code you touched.

Ran both dotnet format and dotnet jb cleanupcode --profile="Built-in: Full Cleanup" — both report no changes needed on the files I touched. The code is already clean.

Warning

Firewall rules blocked me from connecting to one or more addresses (expand for details)

I tried to connect to the following addresses, but was blocked by firewall rules:

  • www.jetbrains.com
    • Triggering command: /usr/share/dotnet/dotnet /usr/share/dotnet/dotnet exec --runtimeconfig /home/REDACTED/.nuget/packages/jetbrains.resharper.globaltools/2025.2.4/tools/netcoreapp3.1/any/cleanupcode.unix.runtimeconfig.json /home/REDACTED/.nuget/packages/jetbrains.resharper.globaltools/2025.2.4/tools/netcoreapp3.1/any/cleanupcode.exe Terminal.Gui.Text.slnx --profile=TG.Text Full Cleanup --no-build --include=examples/ted/TedApp.cs;src/Terminal.Gui.Editor/Editor.Drawing.cs;src/Terminal.Gui.Editor/Editor.cs;src/Terminal.Gui.Editor/Rendering/VisualLineBuildContext.cs;src/Terminal.Gui.Editor/Rendering/VisualLineBuilder.cs;tests/Terminal.Gui.Editor.Integ (dns block)
    • Triggering command: /usr/share/dotnet/dotnet /usr/share/dotnet/dotnet exec --runtimeconfig /home/REDACTED/.nuget/packages/jetbrains.resharper.globaltools/2025.2.4/tools/netcoreapp3.1/any/cleanupcode.unix.runtimeconfig.json /home/REDACTED/.nuget/packages/jetbrains.resharper.globaltools/2025.2.4/tools/netcoreapp3.1/any/cleanupcode.exe Terminal.Gui.Text.slnx --profile=Built-in: Full Cleanup --no-build --include=examples/ted/TedApp.cs;src/Terminal.Gui.Editor/Editor.Drawing.cs;src/Terminal.Gui.Editor/Editor.cs;src/Terminal.Gui.Editor/Rendering/VisualLineBuildContext.cs;src/Terminal.Gui.Editor/Rendering/VisualLineBuilder.cs;tests/Terminal.Gui.Editor.Integ (dns block)
    • Triggering command: /usr/share/dotnet/dotnet /usr/share/dotnet/dotnet exec --runtimeconfig /home/REDACTED/.nuget/packages/jetbrains.resharper.globaltools/2025.2.4/tools/netcoreapp3.1/any/cleanupcode.unix.runtimeconfig.json /home/REDACTED/.nuget/packages/jetbrains.resharper.globaltools/2025.2.4/tools/netcoreapp3.1/any/cleanupcode.exe Terminal.Gui.Text.slnx --profile=Built-in: Full Cleanup --no-build --exclude=third_party/**/* (dns block)

If you need me to access, download, or install something from one of these locations, you can either:

Copilot finished work on behalf of tig May 12, 2026 14:23
@tig tig merged commit 1b3d3fb into develop May 12, 2026
7 checks passed
@tig tig deleted the copilot/fix-editor-background-attribute branch May 12, 2026 14:44
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.

Background of some text is not using correct attribute

2 participants