feat: support absolute pixel height in lineHeight option#5848
Open
yiliang114 wants to merge 1 commit intoxtermjs:masterfrom
Open
feat: support absolute pixel height in lineHeight option#5848yiliang114 wants to merge 1 commit intoxtermjs:masterfrom
yiliang114 wants to merge 1 commit intoxtermjs:masterfrom
Conversation
Follow the Monaco editor convention: when lineHeight is less than 8, treat it as a multiplier of the character height (existing behavior); when it is 8 or greater, treat it as an absolute pixel height. This allows users to set an exact pixel line height (e.g. `lineHeight: 23`) without needing to calculate the equivalent multiplier, which varies with font size, font family, and device pixel ratio. Fixes xtermjs#2612
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Closes #2612
Follow the Monaco editor convention for
lineHeightinterpretation:1.2) — existing behavior, fully backwards compatible20means 20px)This was suggested by @Tyriar to align with Monaco editor's approach. Compared to the string-based
'23px'approach in #5730, this keeps the type signature asnumber(no breaking change) and provides a simpler API.Changes
typings/xterm.d.ts: Updated JSDoc to document both modessrc/common/services/OptionsService.ts: SeparatedlineHeightvalidation fromtabStopWidthwith documenting commentssrc/browser/renderer/dom/DomRenderer.ts: Cell height calculation branches on>= 8for pixel mode, withMath.maxclamp to ensure cell height never falls below character heightaddons/addon-webgl/src/WebglRenderer.ts: Same logic; also fixedchar.topcentering to compare actual dimensions instead of checkinglineHeight === 1src/common/services/OptionsService.test.ts: Added 6 test cases covering multiplier mode, pixel mode, boundary values, and error handlingTest Results
Unit Tests
npm run test-unit— ✅ 2263 passing, 0 failingnpm run build— ✅ passnpm run lint— ✅ 0 warningsManual Verification (DOM Renderer)
Manual Verification (WebGL Renderer)
Screenshots
Default (lineHeight=1.0):

placeholder for 01-default-lineheight-1.0.png
Multiplier mode (lineHeight=1.5):

placeholder for 02-lineheight-1.5-multiplier.png
Pixel mode (lineHeight=20):

placeholder for 03-lineheight-20-pixel.png
Pixel mode (lineHeight=30):

placeholder for 04-lineheight-30-pixel.png
WebGL pixel mode (lineHeight=25):

placeholder for 08-webgl-lineheight-25-pixel.png

Example usage