Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix font settings #18536

Open
wants to merge 8 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -98,8 +98,8 @@ See [customize options] and [manage connection profiles] for more details.
"mssql.intelliSense.enableSuggestions": true,
"mssql.intelliSense.enableQuickInfo": true,
"mssql.intelliSense.lowerCaseSuggestions": false,
"mssql.resultsFontFamily": "-apple-system,BlinkMacSystemFont,Segoe WPC,Segoe UI,HelveticaNeue-Light,Ubuntu,Droid Sans,sans-serif",
"mssql.resultsFontSize": 13,
"mssql.resultsFontFamily": null,
"mssql.resultsFontSize": null,
"mssql.copyIncludeHeaders": false,
"mssql.copyRemoveNewLine" : true,
"mssql.splitPaneSelection": "next",
Expand Down
19 changes: 11 additions & 8 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -1222,16 +1222,19 @@
"scope": "resource"
},
"mssql.resultsFontFamily": {
"type": "string",
"description": "%mssql.resultsFontFamily%",
"default": "-apple-system,BlinkMacSystemFont,Segoe WPC,Segoe UI,HelveticaNeue-Light,Ubuntu,Droid Sans,sans-serif",
"scope": "resource"
"type": "string",
"description": "%mssql.resultsFontFamily%",
"default": null,
"scope": "resource"
},
"mssql.resultsFontSize": {
"type": "number",
"description": "%mssql.resultsFontSize%",
"default": 13,
"scope": "resource"
"type": [
"number",
"null"
],
"description": "%mssql.resultsFontSize%",
"default": null,
"scope": "resource"
},
"mssql.saveAsCsv.includeHeaders": {
"type": "boolean",
Expand Down
12 changes: 6 additions & 6 deletions src/constants/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -170,12 +170,12 @@ export const configMaxRecentConnections = "maxRecentConnections";
export const configCopyRemoveNewLine = "copyRemoveNewLine";
export const configSplitPaneSelection = "splitPaneSelection";
export const configShowBatchTime = "showBatchTime";
export const extConfigResultKeys = [
"shortcuts",
"messagesDefaultOpen",
"resultsFontSize",
"resultsFontFamily",
];
export enum extConfigResultKeys {
ShortCuts = "shortcuts",
MessagesDefaultOpen = "messagesDefaultOpen",
ResultsFontSize = "resultsFontSize",
ResultsFontFamily = "resultsFontFamily",
}
export const sqlToolsServiceInstallDirConfigKey = "installDir";
export const sqlToolsServiceExecutableFilesConfigKey = "executableFiles";
export const sqlToolsServiceVersionConfigKey = "version";
Expand Down
2 changes: 1 addition & 1 deletion src/models/sqlOutputContentProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ export class SqlOutputContentProvider {
queryUri,
);
let config = new ResultsConfig();
for (let key of Constants.extConfigResultKeys) {
for (let key in Constants.extConfigResultKeys) {
config[key] = extConfig[key];
}
return Promise.resolve(config);
Expand Down
63 changes: 63 additions & 0 deletions src/queryResult/queryResultWebViewController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ export class QueryResultWebviewController extends ReactWebviewViewController<
},
executionPlanState: {},
filterState: {},
fontSettings: {},
});

void this.initialize();
Expand All @@ -74,6 +75,25 @@ export class QueryResultWebviewController extends ReactWebviewViewController<
isExecutionPlan: false,
executionPlanState: {},
filterState: {},
fontSettings: {
fontSize:
(this._vscodeWrapper
.getConfiguration(Constants.extensionName)
.get(
Constants.extConfigResultKeys
.ResultsFontSize,
) as number) ??
(this._vscodeWrapper
.getConfiguration("editor")
.get("fontSize") as number),

fontFamily: this._vscodeWrapper
.getConfiguration(Constants.extensionName)
.get(
Constants.extConfigResultKeys
.ResultsFontFamily,
),
},
};
}
});
Expand All @@ -85,6 +105,33 @@ export class QueryResultWebviewController extends ReactWebviewViewController<
this._queryResultStateMap.delete(uri);
}
});
this._vscodeWrapper.onDidChangeConfiguration((e) => {
if (e.affectsConfiguration("mssql.resultsFontFamily")) {
for (const [uri, state] of this._queryResultStateMap) {
state.fontSettings.fontFamily = this._vscodeWrapper
.getConfiguration(Constants.extensionName)
.get(
Constants.extConfigResultKeys.ResultsFontFamily,
);
this._queryResultStateMap.set(uri, state);
}
}
if (e.affectsConfiguration("mssql.resultsFontSize")) {
for (const [uri, state] of this._queryResultStateMap) {
state.fontSettings.fontSize =
(this._vscodeWrapper
.getConfiguration(Constants.extensionName)
.get(
Constants.extConfigResultKeys
.ResultsFontSize,
) as number) ??
(this._vscodeWrapper
.getConfiguration("editor")
.get("fontSize") as number);
this._queryResultStateMap.set(uri, state);
}
}
});
}
}

Expand Down Expand Up @@ -225,6 +272,22 @@ export class QueryResultWebviewController extends ReactWebviewViewController<
},
}),
filterState: {},
fontSettings: {
fontSize:
(this._vscodeWrapper
.getConfiguration(Constants.extensionName)
.get(
Constants.extConfigResultKeys.ResultsFontSize,
) as number) ??
(this._vscodeWrapper
.getConfiguration("editor")
.get("fontSize") as number),
fontFamily: this._vscodeWrapper
.getConfiguration(Constants.extensionName)
.get(
Constants.extConfigResultKeys.ResultsFontFamily,
) as string,
},
};
this._queryResultStateMap.set(uri, currentState);
}
Expand Down
2 changes: 1 addition & 1 deletion src/queryResult/queryResultWebviewPanelController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@

import * as vscode from "vscode";
import * as qr from "../sharedInterfaces/queryResult";
// import * as Constants from "../constants/constants";
import { randomUUID } from "crypto";
import VscodeWrapper from "../controllers/vscodeWrapper";
import { ReactWebviewPanelController } from "../controllers/reactWebviewPanelController";
Expand Down Expand Up @@ -37,6 +36,7 @@ export class QueryResultWebviewPanelController extends ReactWebviewPanelControll
},
executionPlanState: {},
filterState: {},
fontSettings: {},
},
{
title: vscode.l10n.t({
Expand Down
7 changes: 5 additions & 2 deletions src/reactviews/pages/QueryResult/queryResultPane.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -66,9 +66,7 @@ const useStyles = makeStyles({
width: "100%",
position: "relative",
display: "flex",
fontFamily: "var(--vscode-editor-font-family)",
fontWeight: "normal",
fontSize: "var(--vscode-editor-font-size)",
},
queryResultPaneOpenButton: {
position: "absolute",
Expand Down Expand Up @@ -236,6 +234,7 @@ export const QueryResultPane = () => {
gridCount: number,
) => {
const divId = `grid-parent-${batchId}-${resultId}`;
console.log(metadata.fontSettings.fontSize ?? 12);
return (
<div
id={divId}
Expand All @@ -252,6 +251,10 @@ export const QueryResultPane = () => {
gridCount,
)}px`
: "",
fontFamily: metadata.fontSettings.fontFamily
? metadata.fontSettings.fontFamily
: "var(--vscode-editor-font-family)",
fontSize: `${metadata.fontSettings.fontSize ?? 12}px`,
}}
>
<ResultGrid
Expand Down
15 changes: 12 additions & 3 deletions src/reactviews/pages/QueryResult/resultGrid.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -135,8 +135,17 @@ const ResultGrid = forwardRef<ResultGridHandle, ResultGridProps>(
table.rerenderGrid();
}
};

const ROW_HEIGHT = 25;
const DEFAULT_FONT_SIZE = 12;
console.log(
"resultGrid: ",
props.state.state.fontSettings.fontSize,
);
const ROW_HEIGHT = props.state.state.fontSettings.fontSize! + 12; // 12 px is the padding
const COLUMN_WIDTH = Math.max(
(props.state.state.fontSettings.fontSize! / DEFAULT_FONT_SIZE) *
120,
120,
); // Scale width with font size, but keep a minimum of 120px
if (!props.resultSetSummary || !props.linkHandler) {
return;
}
Expand Down Expand Up @@ -222,7 +231,7 @@ const ResultGrid = forwardRef<ResultGridHandle, ResultGridProps>(
rowHeight: ROW_HEIGHT,
showRowNumber: true,
forceFitColumns: false,
defaultColumnWidth: 120,
defaultColumnWidth: COLUMN_WIDTH,
};
let rowNumberColumn = new RowNumberColumn<Slick.SlickData>({
autoCellSelection: false,
Expand Down
6 changes: 6 additions & 0 deletions src/sharedInterfaces/queryResult.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,11 @@ export interface QueryResultTabStates {
resultPaneTab: QueryResultPaneTabs;
}

export interface FontSettings {
fontSize?: number;
fontFamily?: string;
}

export interface QueryResultWebviewState extends ExecutionPlanWebviewState {
uri?: string;
title?: string;
Expand All @@ -72,6 +77,7 @@ export interface QueryResultWebviewState extends ExecutionPlanWebviewState {
selection?: ISlickRange[];
executionPlanState: ExecutionPlanState;
filterState: Record<string, ColumnFilterState>;
fontSettings: FontSettings;
}

export interface QueryResultReducers
Expand Down
Loading