Skip to content

Commit e73b510

Browse files
authored
refactor: Refactor font changes codes in ViewCommands (#1285)
* refactor: Add command to change terminal font size Signed-off-by: Qian Qian "Cubik"‎ <[email protected]> * refactor(ViewCommands): Use more specific `@AppSettings` Signed-off-by: Qian Qian "Cubik"‎ <[email protected]> * feat: Disable font size adjustment if no opened workspace Signed-off-by: Qian Qian "Cubik"‎ <[email protected]> * fix: Prevent font size to go over max value (`288`) Signed-off-by: Qian Qian "Cubik"‎ <[email protected]> * refactor(ViewCommands): Remove unused `CodeEditDocumentController` Signed-off-by: Qian Qian "Cubik"‎ <[email protected]> --------- Signed-off-by: Qian Qian "Cubik"‎ <[email protected]>
1 parent 0bfe904 commit e73b510

File tree

1 file changed

+13
-11
lines changed

1 file changed

+13
-11
lines changed

CodeEdit/Features/WindowCommands/ViewCommands.swift

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,11 @@
88
import SwiftUI
99

1010
struct ViewCommands: Commands {
11-
@AppSettings(\.textEditing.font) var font
11+
@AppSettings(\.textEditing.font.size) var editorFontSize
12+
@AppSettings(\.terminal.font.size) var terminalFontSize
1213

1314
@State var windowController: CodeEditWindowController?
1415

15-
private let documentController: CodeEditDocumentController = CodeEditDocumentController()
1616
private let statusBarViewModel: StatusBarViewModel = StatusBarViewModel()
1717

1818
var navigatorCollapsed: Bool {
@@ -31,24 +31,26 @@ struct ViewCommands: Commands {
3131
.keyboardShortcut("p", modifiers: [.shift, .command])
3232

3333
Button("Increase font size") {
34-
if CodeEditDocumentController.shared.documents.count > 1 {
35-
font.size += 1
34+
if !(editorFontSize >= 288) {
35+
editorFontSize += 1
36+
}
37+
if !(terminalFontSize >= 288) {
38+
terminalFontSize += 1
3639
}
37-
font.size += 1
3840
}
3941
.keyboardShortcut("+")
42+
.disabled(windowController == nil)
4043

4144
Button("Decrease font size") {
42-
if CodeEditDocumentController.shared.documents.count > 1 {
43-
if !(font.size <= 1) {
44-
font.size -= 1
45-
}
45+
if !(editorFontSize <= 1) {
46+
editorFontSize -= 1
4647
}
47-
if !(font.size <= 1) {
48-
font.size -= 1
48+
if !(terminalFontSize <= 1) {
49+
terminalFontSize -= 1
4950
}
5051
}
5152
.keyboardShortcut("-")
53+
.disabled(windowController == nil)
5254

5355
Button("Customize Toolbar...") {
5456

0 commit comments

Comments
 (0)