Skip to content

Commit 22c92d2

Browse files
committed
feat: add font smoothing configuration for webview UI
1 parent fd4f358 commit 22c92d2

File tree

6 files changed

+45
-5
lines changed

6 files changed

+45
-5
lines changed

package.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -340,6 +340,11 @@
340340
"type": "string",
341341
"default": "",
342342
"description": "Custom storage path. Leave empty to use the default location. Supports absolute paths (e.g. 'D:\\RooCodeStorage')"
343+
},
344+
"roo-cline.fontSmoothing": {
345+
"type": "boolean",
346+
"default": true,
347+
"description": "Enable CSS font smoothing (-webkit-font-smoothing: antialiased; -moz-osx-font-smoothing: grayscale;) for the Roo Code webview UI for potentially crisper text rendering."
343348
}
344349
}
345350
}

src/core/webview/ClineProvider.ts

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -424,9 +424,15 @@ export class ClineProvider extends EventEmitter<ClineProviderEvents> implements
424424
// Listen for when color changes
425425
vscode.workspace.onDidChangeConfiguration(
426426
async (e) => {
427-
if (e && e.affectsConfiguration("workbench.colorTheme")) {
428-
// Sends latest theme name to webview
429-
await this.postMessageToWebview({ type: "theme", text: JSON.stringify(await getTheme()) })
427+
if (e) {
428+
if (e.affectsConfiguration("workbench.colorTheme")) {
429+
// Sends latest theme name to webview
430+
await this.postMessageToWebview({ type: "theme", text: JSON.stringify(await getTheme()) })
431+
}
432+
if (e.affectsConfiguration("roo-cline.fontSmoothing")) {
433+
// Resend the entire state to update the font smoothing setting in the webview
434+
await this.postStateToWebview()
435+
}
430436
}
431437
},
432438
null,
@@ -1200,6 +1206,7 @@ export class ClineProvider extends EventEmitter<ClineProviderEvents> implements
12001206
showRooIgnoredFiles,
12011207
language,
12021208
maxReadFileLine,
1209+
fontSmoothing,
12031210
} = await this.getState()
12041211

12051212
const telemetryKey = process.env.POSTHOG_API_KEY
@@ -1275,6 +1282,7 @@ export class ClineProvider extends EventEmitter<ClineProviderEvents> implements
12751282
renderContext: this.renderContext,
12761283
maxReadFileLine: maxReadFileLine ?? 500,
12771284
settingsImportedAt: this.settingsImportedAt,
1285+
fontSmoothing: fontSmoothing ?? false,
12781286
}
12791287
}
12801288

@@ -1286,6 +1294,7 @@ export class ClineProvider extends EventEmitter<ClineProviderEvents> implements
12861294

12871295
async getState() {
12881296
const stateValues = this.contextProxy.getValues()
1297+
const config = vscode.workspace.getConfiguration("roo-cline")
12891298

12901299
const customModes = await this.customModesManager.getCustomModes()
12911300

@@ -1357,6 +1366,7 @@ export class ClineProvider extends EventEmitter<ClineProviderEvents> implements
13571366
telemetrySetting: stateValues.telemetrySetting || "unset",
13581367
showRooIgnoredFiles: stateValues.showRooIgnoredFiles ?? true,
13591368
maxReadFileLine: stateValues.maxReadFileLine ?? 500,
1369+
fontSmoothing: config.get<boolean>("fontSmoothing") ?? false,
13601370
}
13611371
}
13621372

src/shared/ExtensionMessage.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -203,6 +203,7 @@ export type ExtensionState = Pick<
203203

204204
renderContext: "sidebar" | "editor"
205205
settingsImportedAt?: number
206+
fontSmoothing?: boolean
206207
}
207208

208209
export type { ClineMessage, ClineAsk, ClineSay }

webview-ui/src/App.tsx

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,15 @@ const tabsByMessageAction: Partial<Record<NonNullable<ExtensionMessage["action"]
2727
}
2828

2929
const App = () => {
30-
const { didHydrateState, showWelcome, shouldShowAnnouncement, telemetrySetting, telemetryKey, machineId } =
31-
useExtensionState()
30+
const {
31+
didHydrateState,
32+
showWelcome,
33+
shouldShowAnnouncement,
34+
telemetrySetting,
35+
telemetryKey,
36+
machineId,
37+
fontSmoothing,
38+
} = useExtensionState()
3239

3340
const [showAnnouncement, setShowAnnouncement] = useState(false)
3441
const [tab, setTab] = useState<Tab>("chat")
@@ -91,6 +98,15 @@ const App = () => {
9198
// Tell the extension that we are ready to receive messages.
9299
useEffect(() => vscode.postMessage({ type: "webviewDidLaunch" }), [])
93100

101+
// Apply font smoothing class based on setting
102+
useEffect(() => {
103+
if (fontSmoothing) {
104+
document.documentElement.classList.add("font-smoothing-enabled")
105+
} else {
106+
document.documentElement.classList.remove("font-smoothing-enabled")
107+
}
108+
}, [fontSmoothing])
109+
94110
if (!didHydrateState) {
95111
return null
96112
}

webview-ui/src/context/ExtensionStateContext.tsx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,7 @@ export interface ExtensionStateContextType extends ExtensionState {
8686
pinnedApiConfigs?: Record<string, boolean>
8787
setPinnedApiConfigs: (value: Record<string, boolean>) => void
8888
togglePinnedApiConfig: (configName: string) => void
89+
fontSmoothing?: boolean
8990
}
9091

9192
export const ExtensionStateContext = createContext<ExtensionStateContextType | undefined>(undefined)
@@ -161,6 +162,7 @@ export const ExtensionStateContextProvider: React.FC<{ children: React.ReactNode
161162
renderContext: "sidebar",
162163
maxReadFileLine: 500, // Default max read file line limit
163164
pinnedApiConfigs: {}, // Empty object for pinned API configs
165+
fontSmoothing: false,
164166
})
165167

166168
const [didHydrateState, setDidHydrateState] = useState(false)
@@ -330,6 +332,7 @@ export const ExtensionStateContextProvider: React.FC<{ children: React.ReactNode
330332

331333
return { ...prevState, pinnedApiConfigs: newPinned }
332334
}),
335+
fontSmoothing: state.fontSmoothing,
333336
}
334337

335338
return <ExtensionStateContext.Provider value={contextValue}>{children}</ExtensionStateContext.Provider>

webview-ui/src/index.css

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -196,6 +196,11 @@ html {
196196
height: 100%;
197197
}
198198

199+
html.font-smoothing-enabled {
200+
-webkit-font-smoothing: antialiased;
201+
-moz-osx-font-smoothing: grayscale;
202+
}
203+
199204
body {
200205
margin: 0;
201206
line-height: 1.25;

0 commit comments

Comments
 (0)