diff --git a/SwiftNeoVim/NeoVimView.swift b/SwiftNeoVim/NeoVimView.swift index 6b6c7559..88991368 100644 --- a/SwiftNeoVim/NeoVimView.swift +++ b/SwiftNeoVim/NeoVimView.swift @@ -18,10 +18,16 @@ private struct RowRun: CustomStringConvertible { } public class NeoVimView: NSView { + + public static let minFontSize = CGFloat(4) + public static let maxFontSize = CGFloat(128) + public static let defaultFont = NSFont(name: "Menlo", size: 13)! public let uuid = NSUUID().UUIDString public weak var delegate: NeoVimViewDelegate? + private let fontManager = NSFontManager.sharedFontManager() + private let agent: NeoVimAgent private let grid = Grid() @@ -78,7 +84,7 @@ public class NeoVimView: NSView { } override init(frame rect: NSRect = CGRect.zero) { - self._font = NSFont(name: "Menlo", size: 13)! + self._font = NeoVimView.defaultFont self.drawer = TextDrawer(font: self._font) self.agent = NeoVimAgent(uuid: self.uuid) @@ -520,6 +526,29 @@ extension NeoVimView: NSTextInputClient { } } +// MARK: - Gesture Events +extension NeoVimView { + + override public func magnifyWithEvent(event: NSEvent) { + let factor = 1 + event.magnification + let targetSize = self.capFontSize(round(self._font.pointSize * factor)) + + self.font = self.fontManager.convertFont(self._font, toSize: targetSize) + } + + private func capFontSize(size: CGFloat) -> CGFloat { + guard size >= NeoVimView.minFontSize else { + return NeoVimView.minFontSize + } + + guard size <= NeoVimView.maxFontSize else { + return NeoVimView.maxFontSize + } + + return size + } +} + // MARK: - Mouse Events extension NeoVimView { diff --git a/VimR/PrefStore.swift b/VimR/PrefStore.swift index 6994731f..ec179c4d 100644 --- a/VimR/PrefStore.swift +++ b/VimR/PrefStore.swift @@ -15,9 +15,9 @@ private class PrefKeys { class PrefStore: Store { private static let compatibleVersion = "38" - private static let defaultEditorFont = NSFont(name: "Menlo", size: 13)! - static let minimumEditorFontSize = CGFloat(4) - static let maximumEditorFontSize = CGFloat(128) + private static let defaultEditorFont = NeoVimView.defaultFont + static let minimumEditorFontSize = NeoVimView.maxFontSize + static let maximumEditorFontSize = NeoVimView.minFontSize private let source: Observable private let disposeBag = DisposeBag()