Make the decoration option fontSize a number#315533
Open
remcohaszing wants to merge 1 commit into
Open
Conversation
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.
Contributor
There was a problem hiding this comment.
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
fontSizetypes fromstringtonumberacross public (src/vs/monaco.d.ts) and internal editor/model interfaces. - Updated
getFontSizeAtPosition()signatures to returnnumber | nulland 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.fontSizedirectly. 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 likeTextAreaEditContext(which passes the returned value tosetFontSize) to render at e.g.0.3pxinstead ofeditorFontSize * 0.3. Consider multiplying by the base font size (similar to howlineHeightmultipliers are applied insrc/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; |
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.
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 inTextAreaEditContext, 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.