Skip to content

Commit d5218a8

Browse files
authored
Merge pull request #1561 from ychin/whatsnew-fontsize-allow-anchors
Add font size up/down support and allow anchor links for What's New page
2 parents 7861c78 + 7402362 commit d5218a8

File tree

1 file changed

+29
-2
lines changed

1 file changed

+29
-2
lines changed

src/MacVim/MMWhatsNewController.m

Lines changed: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,26 @@ - (void)windowWillClose:(NSNotification *)notification
140140
return;
141141
}
142142

143+
// Font size delegates for menu items
144+
145+
#if defined(MAC_OS_VERSION_11_0) && MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_VERSION_11_0
146+
- (IBAction)fontSizeUp:(id)sender
147+
{
148+
if (@available(macos 11.0, *)) {
149+
CGFloat pageZoom = _webView.pageZoom + 0.25;
150+
_webView.pageZoom = pageZoom > 3.0 ? 3.0 : pageZoom;
151+
}
152+
}
153+
154+
- (IBAction)fontSizeDown:(id)sender
155+
{
156+
if (@available(macos 11.0, *)) {
157+
CGFloat pageZoom = _webView.pageZoom - 0.25;
158+
_webView.pageZoom = pageZoom < 0.25 ? 0.25 : pageZoom;
159+
}
160+
}
161+
#endif
162+
143163
// WKNavigationDelegate methods
144164

145165
/// Tells web view how to handle links and navigation. Current behavior is
@@ -149,14 +169,21 @@ - (void)webView:(WKWebView *)webView decidePolicyForNavigationAction:(WKNavigati
149169
NSURLRequest *request = navigationAction.request;
150170
NSURL *requestURL = request.URL;
151171

152-
if ([requestURL isEqual:_whatsNewURL]) {
172+
if ([requestURL.scheme isEqual:_whatsNewURL.scheme] &&
173+
[requestURL.host isEqual:_whatsNewURL.host] &&
174+
[requestURL.port isEqual:_whatsNewURL.port] &&
175+
[requestURL.path isEqual:_whatsNewURL.path] &&
176+
[requestURL.query isEqual:_whatsNewURL.query])
177+
{
178+
// Only allow if everything except for fragment is the same (which
179+
// we allow so that table of contents anchor links would work).
153180
decisionHandler(WKNavigationActionPolicyAllow);
154181
}
155182
else {
156183
// We want to open any links in the release notes with a browser instead.
157184
decisionHandler(WKNavigationActionPolicyCancel);
158185

159-
if ([request.URL.scheme isEqualToString:@"https"]) {
186+
if ([requestURL.scheme isEqualToString:@"https"]) {
160187
// Just try to be sane and only open https:// urls. There should be
161188
// no reason why the release notes should contain other schemes and it
162189
// would be an indication something is wrong or malicious (e.g. file:

0 commit comments

Comments
 (0)