Skip to content

Make the decoration option fontSize a number#315533

Open
remcohaszing wants to merge 1 commit into
microsoft:mainfrom
remcohaszing:numeric-font-size
Open

Make the decoration option fontSize a number#315533
remcohaszing wants to merge 1 commit into
microsoft:mainfrom
remcohaszing:numeric-font-size

Conversation

@remcohaszing
Copy link
Copy Markdown
Contributor

This options took a numeric string. This number is a ratio by which the font size will be multiplied. This was once an absolute value, but this is no longer the case.

This value is currently used in ViewModel.getFontSizeAtPosition(), where it is incorrectly used as an absolute value. This number is currently only used in TextAreaEditContext, but I don’t believe it’s really needed there.

Besides that, the number is currently unused inside Monaco. But its numerical value is needed to fix some bugs. E.g. this is a prerequisite for fixing #305658.

This options took a numeric string. This number is a ratio by which the
font size will be multiplied. This was once an absolute value, but this
is no longer the case.

This value is currently used in `ViewModel.getFontSizeAtPosition()`,
where it is incorrectly used as an absolute value. This number is
currently only used in `TextAreaEditContext`, but I don’t believe it’s
really needed there.

Besides that, the number is currently unused inside Monaco. But its
numerical value is needed to fix some bugs. E.g. this is a prerequisite
for fixing microsoft#305658.
Copilot AI review requested due to automatic review settings May 10, 2026 12:07
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR updates Monaco/VS Code editor decoration typings to treat fontSize as a numeric value and aligns getFontSizeAtPosition() to return a number | null, with the intent of enabling correct font-size computations for variable-font rendering scenarios (notably as a prerequisite for #305658).

Changes:

  • Switched decoration fontSize types from string to number across public (src/vs/monaco.d.ts) and internal editor/model interfaces.
  • Updated getFontSizeAtPosition() signatures to return number | null and adjusted the view model implementation to return numeric values.
  • Propagated the type change into textarea edit context render data to use numeric font sizes.

Reviewed changes

Copilot reviewed 9 out of 10 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
src/vs/monaco.d.ts Public API type changes for decoration fontSize and getFontSizeAtPosition() return type.
src/vs/editor/common/viewModel/viewModelImpl.ts ViewModel now returns numeric font size from decorations/config.
src/vs/editor/common/viewModel.ts Updated IViewModel.getFontSizeAtPosition return type.
src/vs/editor/common/model/textModel.ts ModelDecorationOptions.fontSize now stored as `number
src/vs/editor/common/model.ts IModelDecorationOptions.fontSize now typed as `number
src/vs/editor/common/editorCommon.ts Decoration render option fontSize now typed as number.
src/vs/editor/browser/widget/codeEditor/codeEditorWidget.ts Updated editor widget API surface for numeric getFontSizeAtPosition().
src/vs/editor/browser/services/abstractCodeEditorService.ts Decoration type options provider now uses numeric fontSize.
src/vs/editor/browser/editorBrowser.ts Updated ICodeEditor.getFontSizeAtPosition() return type.
src/vs/editor/browser/controller/editContext/textArea/textAreaEditContext.ts Render data carries numeric fontSize into textarea rendering.
Comments suppressed due to low confidence (1)

src/vs/editor/common/viewModel/viewModelImpl.ts:581

  • This implementation returns fontDecoration.options.fontSize directly. The PR description indicates this value is a multiplier (ratio) of the editor font size, but this code treats it as an absolute font size in px. This will cause callers like TextAreaEditContext (which passes the returned value to setFontSize) to render at e.g. 0.3px instead of editorFontSize * 0.3. Consider multiplying by the base font size (similar to how lineHeight multipliers are applied in src/vs/editor/common/viewLayout/lineHeights.ts:461).
		const fontDecorations = this.model.getFontDecorationsInRange(Range.fromPositions(position), this._editorId);
		let fontSize = this._configuration.options.get(EditorOption.fontInfo).fontSize;
		for (const fontDecoration of fontDecorations) {
			if (fontDecoration.options.fontSize) {
				fontSize = fontDecoration.options.fontSize;
				break;

Comment on lines 461 to 465
public glyphMarginClassName: string | undefined;
public isWholeLine: boolean;
public lineHeight: number | undefined;
public fontSize: string | undefined;
public fontSize: number | undefined;
public fontFamily: string | undefined;
@mjbvz mjbvz assigned aiday-mar and unassigned mjbvz May 11, 2026
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.

4 participants