add Cmd+=/Cmd+- zoom with persistent zoom level in config
This commit is contained in:
parent
53e1832644
commit
108484481a
|
|
@ -132,6 +132,21 @@ class AppDelegate: NSObject, NSApplicationDelegate {
|
||||||
toggleItem.keyEquivalentModifierMask = .control
|
toggleItem.keyEquivalentModifierMask = .control
|
||||||
toggleItem.target = self
|
toggleItem.target = self
|
||||||
menu.addItem(toggleItem)
|
menu.addItem(toggleItem)
|
||||||
|
|
||||||
|
menu.addItem(.separator())
|
||||||
|
|
||||||
|
let zoomInItem = NSMenuItem(title: "Zoom In", action: #selector(zoomIn), keyEquivalent: "=")
|
||||||
|
zoomInItem.target = self
|
||||||
|
menu.addItem(zoomInItem)
|
||||||
|
|
||||||
|
let zoomOutItem = NSMenuItem(title: "Zoom Out", action: #selector(zoomOut), keyEquivalent: "-")
|
||||||
|
zoomOutItem.target = self
|
||||||
|
menu.addItem(zoomOutItem)
|
||||||
|
|
||||||
|
let actualSizeItem = NSMenuItem(title: "Actual Size", action: #selector(zoomReset), keyEquivalent: "0")
|
||||||
|
actualSizeItem.target = self
|
||||||
|
menu.addItem(actualSizeItem)
|
||||||
|
|
||||||
item.submenu = menu
|
item.submenu = menu
|
||||||
return item
|
return item
|
||||||
}
|
}
|
||||||
|
|
@ -191,6 +206,24 @@ class AppDelegate: NSObject, NSApplicationDelegate {
|
||||||
NotificationCenter.default.post(name: .toggleSidebar, object: nil)
|
NotificationCenter.default.post(name: .toggleSidebar, object: nil)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@objc private func zoomIn() {
|
||||||
|
ConfigManager.shared.zoomLevel += 1
|
||||||
|
NotificationCenter.default.post(name: .settingsChanged, object: nil)
|
||||||
|
}
|
||||||
|
|
||||||
|
@objc private func zoomOut() {
|
||||||
|
let current = ConfigManager.shared.zoomLevel
|
||||||
|
if 11 + current > 8 {
|
||||||
|
ConfigManager.shared.zoomLevel -= 1
|
||||||
|
NotificationCenter.default.post(name: .settingsChanged, object: nil)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@objc private func zoomReset() {
|
||||||
|
ConfigManager.shared.zoomLevel = 0
|
||||||
|
NotificationCenter.default.post(name: .settingsChanged, object: nil)
|
||||||
|
}
|
||||||
|
|
||||||
private func setupTitleBar() {
|
private func setupTitleBar() {
|
||||||
let accessory = TitleBarAccessoryController()
|
let accessory = TitleBarAccessoryController()
|
||||||
window.addTitlebarAccessoryViewController(accessory)
|
window.addTitlebarAccessoryViewController(accessory)
|
||||||
|
|
|
||||||
|
|
@ -52,4 +52,9 @@ class ConfigManager {
|
||||||
get { config["lineIndicatorMode"] ?? "on" }
|
get { config["lineIndicatorMode"] ?? "on" }
|
||||||
set { config["lineIndicatorMode"] = newValue; save() }
|
set { config["lineIndicatorMode"] = newValue; save() }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var zoomLevel: CGFloat {
|
||||||
|
get { CGFloat(Double(config["zoomLevel"] ?? "0") ?? 0) }
|
||||||
|
set { config["zoomLevel"] = String(Double(newValue)); save() }
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -36,7 +36,7 @@ struct SidebarView: View {
|
||||||
Spacer()
|
Spacer()
|
||||||
Text("No notes yet")
|
Text("No notes yet")
|
||||||
.foregroundColor(Color(ns: Theme.current.overlay1))
|
.foregroundColor(Color(ns: Theme.current.overlay1))
|
||||||
.font(.system(size: 13))
|
.font(Font(Theme.sidebarFont as CTFont))
|
||||||
Spacer()
|
Spacer()
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
|
@ -124,11 +124,13 @@ struct NoteRow: View {
|
||||||
var body: some View {
|
var body: some View {
|
||||||
VStack(alignment: .leading, spacing: 2) {
|
VStack(alignment: .leading, spacing: 2) {
|
||||||
Text(note.title)
|
Text(note.title)
|
||||||
.font(.system(size: 13, weight: isActive ? .semibold : .regular))
|
.font(Font(isActive
|
||||||
|
? NSFontManager.shared.convert(Theme.sidebarFont, toHaveTrait: .boldFontMask) as CTFont
|
||||||
|
: Theme.sidebarFont as CTFont))
|
||||||
.foregroundColor(Color(ns: Theme.current.text))
|
.foregroundColor(Color(ns: Theme.current.text))
|
||||||
.lineLimit(1)
|
.lineLimit(1)
|
||||||
Text(dateFormatter.string(from: note.lastModified))
|
Text(dateFormatter.string(from: note.lastModified))
|
||||||
.font(.system(size: 11))
|
.font(Font(Theme.sidebarDateFont as CTFont))
|
||||||
.foregroundColor(Color(ns: Theme.current.subtext0))
|
.foregroundColor(Color(ns: Theme.current.subtext0))
|
||||||
}
|
}
|
||||||
.frame(maxWidth: .infinity, alignment: .leading)
|
.frame(maxWidth: .infinity, alignment: .leading)
|
||||||
|
|
|
||||||
|
|
@ -101,10 +101,18 @@ struct Theme {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static let editorFont = NSFont.monospacedSystemFont(ofSize: 13, weight: .regular)
|
static var editorFont: NSFont {
|
||||||
static let gutterFont = NSFont.monospacedSystemFont(ofSize: 11, weight: .regular)
|
NSFont.monospacedSystemFont(ofSize: max(8, 13 + ConfigManager.shared.zoomLevel), weight: .regular)
|
||||||
static let sidebarFont = NSFont.systemFont(ofSize: 13, weight: .regular)
|
}
|
||||||
static let sidebarDateFont = NSFont.systemFont(ofSize: 11, weight: .regular)
|
static var gutterFont: NSFont {
|
||||||
|
NSFont.monospacedSystemFont(ofSize: max(8, 11 + ConfigManager.shared.zoomLevel), weight: .regular)
|
||||||
|
}
|
||||||
|
static var sidebarFont: NSFont {
|
||||||
|
NSFont.systemFont(ofSize: max(8, 13 + ConfigManager.shared.zoomLevel), weight: .regular)
|
||||||
|
}
|
||||||
|
static var sidebarDateFont: NSFont {
|
||||||
|
NSFont.systemFont(ofSize: max(8, 11 + ConfigManager.shared.zoomLevel), weight: .regular)
|
||||||
|
}
|
||||||
|
|
||||||
struct SyntaxColors {
|
struct SyntaxColors {
|
||||||
let keyword: NSColor
|
let keyword: NSColor
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue