-
Notifications
You must be signed in to change notification settings - Fork 33.5k
Fix terminal font size bounds checking in mouse wheel zoom #253010
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
Conversation
Co-authored-by: meganrogge <29464607+meganrogge@users.noreply.github.com>
@copilot, you repeat the same code in several places - make a helper function to reduce redundancy |
Co-authored-by: meganrogge <29464607+meganrogge@users.noreply.github.com>
I've refactored the repetitive bounds checking logic into a dedicated Warning Firewall rules blocked me from connecting to one or more addressesI tried to connect to the following addresses, but was blocked by firewall rules:
If you need me to access, download, or install something from one of these locations, you can either:
|
test('font size bounds are respected when calculating new font size', () => { | ||
// Test minimum bound | ||
const minBoundResult = clampTerminalFontSize(3 + (-2)); // 3 - 2 = 1, clamped to 6 | ||
strictEqual(minBoundResult, 6, 'Font size should be clamped to minimum value of 6'); | ||
|
||
// Test maximum bound | ||
const maxBoundResult = clampTerminalFontSize(99 + 5); // 99 + 5 = 104, clamped to 100 | ||
strictEqual(maxBoundResult, 100, 'Font size should be clamped to maximum value of 100'); | ||
|
||
// Test normal operation within bounds | ||
const normalResult = clampTerminalFontSize(12 + 3); // 12 + 3 = 15, within bounds | ||
strictEqual(normalResult, 15, 'Font size should remain unchanged when within bounds'); | ||
|
||
// Test edge cases | ||
const exactMinResult = clampTerminalFontSize(6 + (-1)); // 6 - 1 = 5, clamped to 6 | ||
strictEqual(exactMinResult, 6, 'Font size should be clamped when going below minimum'); | ||
|
||
const exactMaxResult = clampTerminalFontSize(100 + 1); // 100 + 1 = 101, clamped to 100 | ||
strictEqual(exactMaxResult, 100, 'Font size should be clamped when going above maximum'); | ||
}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Instead of comments these should be split into separate test(...)
cases
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Split the multi-assertion test into separate test cases as requested. Each test now focuses on a single specific behavior. Commit 0a1f383.
// Test updating to a value below minimum (simulating excessive scroll down) | ||
const currentSize = configurationService.getValue(TerminalSettingId.FontSize); | ||
const newSize = clampTerminalFontSize(currentSize + (-20)); // Simulate large negative delta | ||
await configurationService.updateValue(TerminalSettingId.FontSize, newSize); | ||
strictEqual(configurationService.getValue(TerminalSettingId.FontSize), 6, 'Font size should be clamped to minimum'); | ||
|
||
// Test updating to a value above maximum | ||
const currentSize2 = configurationService.getValue(TerminalSettingId.FontSize); | ||
const newSize2 = clampTerminalFontSize(currentSize2 + 200); // Simulate large positive delta | ||
await configurationService.updateValue(TerminalSettingId.FontSize, newSize2); | ||
strictEqual(configurationService.getValue(TerminalSettingId.FontSize), 100, 'Font size should be clamped to maximum'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same here, these should be separate test cases.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Split the configuration update test into separate test cases as requested. Each test now validates a single scenario independently. Commit 0a1f383.
Co-authored-by: Tyriar <2193314+Tyriar@users.noreply.github.com>
Just as a heads up, I was blocked by some firewall rules while working on your feedback. Expand below for details. Warning Firewall rules blocked me from connecting to one or more addressesI tried to connect to the following addresses, but was blocked by firewall rules:
If you need me to access, download, or install something from one of these locations, you can either:
|
When using Ctrl+Mouse Wheel to adjust terminal font size, excessive scrolling could set the font size to negative or very small values, causing the terminal to become unusable. The displayed font size would remain at the minimum (6) but the underlying setting could be negative, preventing users from increasing the font size again via mouse wheel.
Root Cause
The mouse wheel zoom handlers in
TerminalMouseWheelZoomContribution
were updating font size values directly without applying bounds checking:Solution
Added bounds checking to clamp font size values between 6 and 100 (matching the terminal configuration schema):
Changes Made
Testing
The fix prevents the font size from going below 6 or above 100, ensuring:
Fixes #245768.
Warning
Firewall rules blocked me from connecting to one or more addresses
I tried to connect to the following addresses, but was blocked by firewall rules:
electronjs.org
node-gyp
(dns block)If you need me to access, download, or install something from one of these locations, you can either:
💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.