From 38f46e50eb42a39cf5c10acfdfbab156333e2cfc Mon Sep 17 00:00:00 2001 From: Tae Won Ha Date: Thu, 27 Oct 2016 08:21:29 +0200 Subject: [PATCH] GH-270 React to linespacing change --- VimR/AppearancePrefPane.swift | 57 ++++++++++++++++++++++++++++++---- VimR/MainWindowComponent.swift | 8 +++-- VimR/PrefStore.swift | 11 ++++--- 3 files changed, 62 insertions(+), 14 deletions(-) diff --git a/VimR/AppearancePrefPane.swift b/VimR/AppearancePrefPane.swift index 93a2560a..d46c9bb4 100644 --- a/VimR/AppearancePrefPane.swift +++ b/VimR/AppearancePrefPane.swift @@ -199,6 +199,10 @@ class AppearancePrefPane: PrefPane, NSComboBoxDelegate, NSControlTextEditingDele self.previewArea.turnOffLigatures(self) } } + + override func windowWillClose() { + self.linespacingAction() + } } // MARK: - Actions @@ -251,18 +255,59 @@ extension AppearancePrefPane { } func linespacingAction() { - + let newLinespacing = self.cappedLinespacing(self.linespacingField.floatValue) + self.set(data: AppearancePrefData(editorFont: self.data.editorFont, + editorLinespacing: newLinespacing, + editorUsesLigatures: self.data.editorUsesLigatures)) + } + + fileprivate func cappedLinespacing(_ linespacing: Float) -> CGFloat { + let cgfLinespacing = CGFloat(linespacing) + + guard cgfLinespacing >= PrefStore.minEditorLinespacing else { + return PrefStore.defaultEditorLinespacing + } + + guard cgfLinespacing <= PrefStore.maxEditorLinespacing else { + return PrefStore.maxEditorLinespacing + } + + return cgfLinespacing } fileprivate func cappedFontSize(_ size: Int) -> CGFloat { - guard size >= 4 else { - return 13 + let cgfSize = CGFloat(size) + + guard cgfSize >= PrefStore.minEditorFontSize else { + return PrefStore.defaultEditorFontSize } - guard size <= 128 else { - return 128 + guard cgfSize <= PrefStore.maxEditorFontSize else { + return PrefStore.maxEditorFontSize } - return CGFloat(size) + return cgfSize } } + + + + + + + + + + + + + + + + + + + + + + diff --git a/VimR/MainWindowComponent.swift b/VimR/MainWindowComponent.swift index 79c8d7c5..2c95fd72 100644 --- a/VimR/MainWindowComponent.swift +++ b/VimR/MainWindowComponent.swift @@ -33,7 +33,7 @@ class MainWindowComponent: WindowComponent, NSWindowDelegate, NSUserInterfaceVal fileprivate static let nibName = "MainWindow" fileprivate var defaultEditorFont: NSFont - fileprivate var usesLigatures: Bool +// fileprivate var usesLigatures: Bool fileprivate var _cwd: URL = FileUtils.userHomeUrl @@ -85,7 +85,6 @@ class MainWindowComponent: WindowComponent, NSWindowDelegate, NSUserInterfaceVal self.workspace = Workspace(mainView: self.neoVimView) self.defaultEditorFont = initialData.appearance.editorFont - self.usesLigatures = initialData.appearance.editorUsesLigatures self.fileItemService = fileItemService self._cwd = cwd @@ -107,7 +106,8 @@ class MainWindowComponent: WindowComponent, NSWindowDelegate, NSUserInterfaceVal self.neoVimView.cwd = cwd // This will publish the MainWindowAction.changeCwd action for the file browser. self.neoVimView.delegate = self self.neoVimView.font = self.defaultEditorFont - self.neoVimView.usesLigatures = self.usesLigatures + self.neoVimView.usesLigatures = initialData.appearance.editorUsesLigatures + self.neoVimView.linespacing = initialData.appearance.editorLinespacing self.neoVimView.open(urls: urls) // We don't call self.fileItemService.monitor(url: cwd) here since self.neoVimView.cwd = cwd causes the call @@ -179,10 +179,12 @@ class MainWindowComponent: WindowComponent, NSWindowDelegate, NSUserInterfaceVal .filter { [unowned self] appearanceData in !appearanceData.editorFont.isEqual(to: self.neoVimView.font) || appearanceData.editorUsesLigatures != self.neoVimView.usesLigatures + || appearanceData.editorLinespacing != self.neoVimView.linespacing } .subscribe(onNext: { [unowned self] appearance in self.neoVimView.usesLigatures = appearance.editorUsesLigatures self.neoVimView.font = appearance.editorFont + self.neoVimView.linespacing = appearance.editorLinespacing }) } } diff --git a/VimR/PrefStore.swift b/VimR/PrefStore.swift index 6f323904..328272f2 100644 --- a/VimR/PrefStore.swift +++ b/VimR/PrefStore.swift @@ -43,10 +43,11 @@ class PrefStore: StandardFlow { fileprivate static let defaultEditorFont = NeoVimView.defaultFont static let minEditorFontSize = NeoVimView.minFontSize static let maxEditorFontSize = NeoVimView.maxFontSize + static let defaultEditorFontSize = NeoVimView.defaultFont.pointSize - fileprivate static let defaultEditorFontLinespacing = NeoVimView.defaultLinespacing - static let minEditorFontLinespacing = NeoVimView.minLinespacing - static let maxEditorFontLinespacing = NeoVimView.maxLinespacing + static let defaultEditorLinespacing = NeoVimView.defaultLinespacing + static let minEditorLinespacing = NeoVimView.minLinespacing + static let maxEditorLinespacing = NeoVimView.maxLinespacing fileprivate let userDefaults = UserDefaults.standard fileprivate let fontManager = NSFontManager.shared() @@ -137,8 +138,8 @@ class PrefStore: StandardFlow { } fileprivate func saneLinespacing(_ linespacing: CGFloat) -> CGFloat { - guard linespacing >= PrefStore.minEditorFontLinespacing && linespacing <= PrefStore.maxEditorFontLinespacing else { - return PrefStore.defaultEditorFontLinespacing + guard linespacing >= PrefStore.minEditorLinespacing && linespacing <= PrefStore.maxEditorLinespacing else { + return PrefStore.defaultEditorLinespacing } return linespacing