mirror of
https://github.com/qvacua/vimr.git
synced 2024-12-29 00:34:26 +03:00
GH-270 React to linespacing change
This commit is contained in:
parent
9a43b04134
commit
38f46e50eb
@ -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
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
@ -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
|
||||
})
|
||||
}
|
||||
}
|
||||
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user