Skip to content

Commit

Permalink
Fixed delay in synchronization of font size increment and decrement (#…
Browse files Browse the repository at this point in the history
…1609)

* Fix font resize #1396

* Improve readability

* Remove deprecated code
  • Loading branch information
ibrahimcetin authored Mar 11, 2024
1 parent 0947f30 commit 7c773f9
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 20 deletions.
21 changes: 5 additions & 16 deletions CodeEdit/Features/Settings/Models/AppSettings.swift
Original file line number Diff line number Diff line change
Expand Up @@ -15,35 +15,24 @@ struct AppSettings<T>: DynamicProperty where T: Equatable {

let keyPath: WritableKeyPath<SettingsData, T>

@available(*,
deprecated,
message: """
Use init(_ keyPath:) instead, otherwise the view will be reevaluated on every settings change.
"""
)
init() where T == SettingsData {
self.keyPath = \.self
self.settings = .init(\.settings)
}

init(_ keyPath: WritableKeyPath<SettingsData, T>) {
self.keyPath = keyPath
let newKeyPath = (\EnvironmentValues.settings).appending(path: keyPath)
self.settings = .init(newKeyPath)
let settingsKeyPath = (\EnvironmentValues.settings).appending(path: keyPath)
self.settings = Environment(settingsKeyPath)
}

var wrappedValue: T {
get {
settings.wrappedValue
Settings.shared.preferences[keyPath: keyPath]
}
nonmutating set {
Settings.shared.preferences[keyPath: keyPath] = newValue
}
}

var projectedValue: Binding<T> {
.init {
settings.wrappedValue
Binding {
Settings.shared.preferences[keyPath: keyPath]
} set: {
Settings.shared.preferences[keyPath: keyPath] = $0
}
Expand Down
8 changes: 4 additions & 4 deletions CodeEdit/Features/WindowCommands/ViewCommands.swift
Original file line number Diff line number Diff line change
Expand Up @@ -47,20 +47,20 @@ struct ViewCommands: Commands {

Menu("Font Size") {
Button("Increase") {
if !(editorFontSize >= 288) {
if editorFontSize < 288 {
editorFontSize += 1
}
if !(terminalFontSize >= 288) {
if terminalFontSize < 288 {
terminalFontSize += 1
}
}
.keyboardShortcut("+")

Button("Decrease") {
if !(editorFontSize <= 1) {
if editorFontSize > 1 {
editorFontSize -= 1
}
if !(terminalFontSize <= 1) {
if terminalFontSize > 1 {
terminalFontSize -= 1
}
}
Expand Down

0 comments on commit 7c773f9

Please sign in to comment.