From d5b496fe5ca8562feca921217c01f6df1782374e Mon Sep 17 00:00:00 2001 From: Steve Stonebraker Date: Mon, 2 Mar 2026 21:46:04 -0600 Subject: [PATCH] Add Cmd+/Cmd- keyboard shortcuts for zoom Implements zoom in/out functionality with Cmd+ and Cmd- shortcuts. Both editor and preview panes scale together. - Add zoomIn: and zoomOut: IBAction methods to MPDocument - Add Zoom In/Out menu items to View menu with keyboard shortcuts - Remove preference check to always scale preview with editor - Minimum zoom size set to 8pt to prevent unreadable text Closes #482 --- MacDown/Code/Document/MPDocument.h | 3 +++ MacDown/Code/Document/MPDocument.m | 22 +++++++++++++++++--- MacDown/Localization/Base.lproj/MainMenu.xib | 11 ++++++++++ 3 files changed, 33 insertions(+), 3 deletions(-) diff --git a/MacDown/Code/Document/MPDocument.h b/MacDown/Code/Document/MPDocument.h index 387f4675..64b39ee8 100644 --- a/MacDown/Code/Document/MPDocument.h +++ b/MacDown/Code/Document/MPDocument.h @@ -19,4 +19,7 @@ @property (nonatomic, readwrite) NSString *markdown; @property (nonatomic, readonly) NSString *html; +- (IBAction)zoomIn:(id)sender; +- (IBAction)zoomOut:(id)sender; + @end diff --git a/MacDown/Code/Document/MPDocument.m b/MacDown/Code/Document/MPDocument.m index acbc77ff..054b8b03 100644 --- a/MacDown/Code/Document/MPDocument.m +++ b/MacDown/Code/Document/MPDocument.m @@ -1690,9 +1690,6 @@ - (void)redrawDivider - (void)scaleWebview { - if (!self.preferences.previewZoomRelativeToBaseFontSize) - return; - CGFloat fontSize = self.preferences.editorBaseFontSize; if (fontSize <= 0.0) return; @@ -1714,6 +1711,25 @@ - (void)scaleWebview #endif } + +- (IBAction)zoomIn:(id)sender +{ + NSFont *currentFont = self.preferences.editorBaseFont; + CGFloat newSize = currentFont.pointSize + 1.0; + NSFont *newFont = [NSFont fontWithName:currentFont.fontName size:newSize]; + self.preferences.editorBaseFont = newFont; + [self scaleWebview]; +} + +- (IBAction)zoomOut:(id)sender +{ + NSFont *currentFont = self.preferences.editorBaseFont; + CGFloat newSize = MAX(currentFont.pointSize - 1.0, 8.0); + NSFont *newFont = [NSFont fontWithName:currentFont.fontName size:newSize]; + self.preferences.editorBaseFont = newFont; + [self scaleWebview]; +} + -(void) updateHeaderLocations { CGFloat offset = NSMinY(self.preview.enclosingScrollView.contentView.bounds); diff --git a/MacDown/Localization/Base.lproj/MainMenu.xib b/MacDown/Localization/Base.lproj/MainMenu.xib index ad3ef6c3..eec0fd82 100644 --- a/MacDown/Localization/Base.lproj/MainMenu.xib +++ b/MacDown/Localization/Base.lproj/MainMenu.xib @@ -407,6 +407,17 @@ + + + + + + + + + + +