Skip to content

Commit cbd2345

Browse files
committed
Merge PR MacDownApp#1364: Cmd+/Cmd- zoom shortcuts (adapted to WKWebView pageZoom)
2 parents dae49ff + 69fd4fd commit cbd2345

3 files changed

Lines changed: 32 additions & 3 deletions

File tree

MacDown/Code/Document/MPDocument.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,4 +19,7 @@
1919
@property (nonatomic, readwrite) NSString *markdown;
2020
@property (nonatomic, readonly) NSString *html;
2121

22+
- (IBAction)zoomIn:(id)sender;
23+
- (IBAction)zoomOut:(id)sender;
24+
2225
@end

MacDown/Code/Document/MPDocument.m

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1788,9 +1788,6 @@ - (void)updatePreviewBackgroundColorCache
17881788

17891789
- (void)scaleWebview
17901790
{
1791-
if (!self.preferences.previewZoomRelativeToBaseFontSize)
1792-
return;
1793-
17941791
CGFloat fontSize = self.preferences.editorBaseFontSize;
17951792
if (fontSize <= 0.0)
17961793
return;
@@ -1803,6 +1800,24 @@ - (void)scaleWebview
18031800
self.preview.pageZoom = scale;
18041801
}
18051802

1803+
- (IBAction)zoomIn:(id)sender
1804+
{
1805+
NSFont *currentFont = self.preferences.editorBaseFont;
1806+
CGFloat newSize = currentFont.pointSize + 1.0;
1807+
NSFont *newFont = [NSFont fontWithName:currentFont.fontName size:newSize];
1808+
self.preferences.editorBaseFont = newFont;
1809+
[self scaleWebview];
1810+
}
1811+
1812+
- (IBAction)zoomOut:(id)sender
1813+
{
1814+
NSFont *currentFont = self.preferences.editorBaseFont;
1815+
CGFloat newSize = MAX(currentFont.pointSize - 1.0, 8.0);
1816+
NSFont *newFont = [NSFont fontWithName:currentFont.fontName size:newSize];
1817+
self.preferences.editorBaseFont = newFont;
1818+
[self scaleWebview];
1819+
}
1820+
18061821
- (void)updateHeaderLocationsWithCompletion:(void (^)(void))completion
18071822
{
18081823
// Cache the locations of all of the reference nodes in the editor view.

MacDown/Localization/Base.lproj/MainMenu.xib

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -407,6 +407,17 @@
407407
</connections>
408408
</menuItem>
409409
<menuItem isSeparatorItem="YES" id="QMZ-Ld-Nza"/>
410+
<menuItem title="Zoom In" keyEquivalent="+" id="zIn-01-ABC">
411+
<connections>
412+
<action selector="zoomIn:" target="-1" id="zIn-02-DEF"/>
413+
</connections>
414+
</menuItem>
415+
<menuItem title="Zoom Out" keyEquivalent="-" id="zOt-01-GHI">
416+
<connections>
417+
<action selector="zoomOut:" target="-1" id="zOt-02-JKL"/>
418+
</connections>
419+
</menuItem>
420+
<menuItem isSeparatorItem="YES" id="zSp-01-MNO"/>
410421
<menuItem title="Enter Full Screen" keyEquivalent="f" id="1gz-YB-DZE">
411422
<modifierMask key="keyEquivalentModifierMask" control="YES" command="YES"/>
412423
<connections>

0 commit comments

Comments
 (0)