diff --git a/Packages/vChewing_MainAssembly/Sources/MainAssembly/SettingsUI/VwrSettingsPaneBehavior.swift b/Packages/vChewing_MainAssembly/Sources/MainAssembly/SettingsUI/VwrSettingsPaneBehavior.swift index 890d56c7..41a7645c 100644 --- a/Packages/vChewing_MainAssembly/Sources/MainAssembly/SettingsUI/VwrSettingsPaneBehavior.swift +++ b/Packages/vChewing_MainAssembly/Sources/MainAssembly/SettingsUI/VwrSettingsPaneBehavior.swift @@ -101,12 +101,12 @@ public struct VwrSettingsPaneBehavior: View { UserDef.kShareAlphanumericalModeStatusAcrossClients.bind($shareAlphanumericalModeStatusAcrossClients).render() VStack(alignment: .leading) { UserDef.kTogglingAlphanumericalModeWithLShift.bind( - $togglingAlphanumericalModeWithLShift.onChange { + $togglingAlphanumericalModeWithLShift.didChange { SessionCtl.theShiftKeyDetector.toggleWithLShift = togglingAlphanumericalModeWithLShift } ).render() UserDef.kTogglingAlphanumericalModeWithRShift.bind( - $togglingAlphanumericalModeWithRShift.onChange { + $togglingAlphanumericalModeWithRShift.didChange { SessionCtl.theShiftKeyDetector.toggleWithRShift = togglingAlphanumericalModeWithRShift } ).render() diff --git a/Packages/vChewing_MainAssembly/Sources/MainAssembly/SettingsUI/VwrSettingsPaneCandidates.swift b/Packages/vChewing_MainAssembly/Sources/MainAssembly/SettingsUI/VwrSettingsPaneCandidates.swift index 502904e0..c490cfaa 100644 --- a/Packages/vChewing_MainAssembly/Sources/MainAssembly/SettingsUI/VwrSettingsPaneCandidates.swift +++ b/Packages/vChewing_MainAssembly/Sources/MainAssembly/SettingsUI/VwrSettingsPaneCandidates.swift @@ -68,7 +68,7 @@ public struct VwrSettingsPaneCandidates: View { UserDef.kUseHorizontalCandidateList.bind($useHorizontalCandidateList).render() .pickerStyle(RadioGroupPickerStyle()) UserDef.kCandidateListTextSize.bind( - $candidateListTextSize.onChange { + $candidateListTextSize.didChange { guard !(12 ... 196).contains(candidateListTextSize) else { return } candidateListTextSize = max(12, min(candidateListTextSize, 196)) } @@ -132,7 +132,7 @@ private struct VwrSettingsPaneCandidates_SelectionKeys: View { var body: some View { UserDef.kCandidateKeys.bind( - $candidateKeys.onChange { + $candidateKeys.didChange { let value = candidateKeys let keys = value.trimmingCharacters(in: .whitespacesAndNewlines).lowercased().deduplicated // Start Error Handling. diff --git a/Packages/vChewing_MainAssembly/Sources/MainAssembly/SettingsUI/VwrSettingsPaneCassette.swift b/Packages/vChewing_MainAssembly/Sources/MainAssembly/SettingsUI/VwrSettingsPaneCassette.swift index 86012ed6..637434db 100644 --- a/Packages/vChewing_MainAssembly/Sources/MainAssembly/SettingsUI/VwrSettingsPaneCassette.swift +++ b/Packages/vChewing_MainAssembly/Sources/MainAssembly/SettingsUI/VwrSettingsPaneCassette.swift @@ -124,7 +124,7 @@ public struct VwrSettingsPaneCassette: View { .settingsDescription() Toggle( LocalizedStringKey("Enable cassette mode, suppressing phonabet input"), - isOn: $cassetteEnabled.onChange { + isOn: $cassetteEnabled.didChange { if cassetteEnabled, !LMMgr.checkCassettePathValidity(cassettePath) { if let window = CtlSettingsUI.shared?.window { IMEApp.buzz() diff --git a/Packages/vChewing_MainAssembly/Sources/MainAssembly/SettingsUI/VwrSettingsPaneDictionary.swift b/Packages/vChewing_MainAssembly/Sources/MainAssembly/SettingsUI/VwrSettingsPaneDictionary.swift index 3f6c71e4..fb0ba59f 100644 --- a/Packages/vChewing_MainAssembly/Sources/MainAssembly/SettingsUI/VwrSettingsPaneDictionary.swift +++ b/Packages/vChewing_MainAssembly/Sources/MainAssembly/SettingsUI/VwrSettingsPaneDictionary.swift @@ -148,7 +148,7 @@ public struct VwrSettingsPaneDictionary: View { ) .settingsDescription() UserDef.kShouldAutoReloadUserDataFiles.bind( - $shouldAutoReloadUserDataFiles.onChange { + $shouldAutoReloadUserDataFiles.didChange { if shouldAutoReloadUserDataFiles { LMMgr.initUserLangModels() } @@ -160,23 +160,23 @@ public struct VwrSettingsPaneDictionary: View { Section { UserDef.kUseExternalFactoryDict.bind( - $useExternalFactoryDict.onChange { + $useExternalFactoryDict.didChange { LMMgr.connectCoreDB() } ).render() UserDef.kCNS11643Enabled.bind( - $cns11643Enabled.onChange { + $cns11643Enabled.didChange { LMMgr.syncLMPrefs() } ).render() UserDef.kSymbolInputEnabled.bind( - $symbolInputEnabled.onChange { + $symbolInputEnabled.didChange { LMMgr.syncLMPrefs() } ).render() UserDef.kFetchSuggestionsFromUserOverrideModel.bind($fetchSuggestionsFromUserOverrideModel).render() UserDef.kPhraseReplacementEnabled.bind( - $phraseReplacementEnabled.onChange { + $phraseReplacementEnabled.didChange { LMMgr.syncLMPrefs() if phraseReplacementEnabled { LMMgr.loadUserPhraseReplacement() diff --git a/Packages/vChewing_MainAssembly/Sources/MainAssembly/SettingsUI/VwrSettingsPaneGeneral.swift b/Packages/vChewing_MainAssembly/Sources/MainAssembly/SettingsUI/VwrSettingsPaneGeneral.swift index abf255f6..f27464ba 100644 --- a/Packages/vChewing_MainAssembly/Sources/MainAssembly/SettingsUI/VwrSettingsPaneGeneral.swift +++ b/Packages/vChewing_MainAssembly/Sources/MainAssembly/SettingsUI/VwrSettingsPaneGeneral.swift @@ -89,7 +89,7 @@ public struct VwrSettingsPaneGeneral: View { Section { UserDef.kReadingNarrationCoverage.bind( - $readingNarrationCoverage.onChange { + $readingNarrationCoverage.didChange { SpeechSputnik.shared.refreshStatus() } ).render() @@ -99,14 +99,14 @@ public struct VwrSettingsPaneGeneral: View { UserDef.kClassicHaninKeyboardSymbolModeShortcutEnabled .bind($classicHaninKeyboardSymbolModeShortcutEnabled).render() UserDef.kUseSCPCTypingMode.bind( - $useSCPCTypingMode.onChange { + $useSCPCTypingMode.didChange { guard useSCPCTypingMode else { return } LMMgr.loadSCPCSequencesData() } ).render() if Date.isTodayTheDate(from: 0401) { UserDef.kShouldNotFartInLieuOfBeep.bind( - $shouldNotFartInLieuOfBeep.onChange { onFartControlChange() } + $shouldNotFartInLieuOfBeep.didChange { onFartControlChange() } ).render() } } diff --git a/Packages/vChewing_MainAssembly/Sources/MainAssembly/SettingsUI/VwrSettingsPaneOutput.swift b/Packages/vChewing_MainAssembly/Sources/MainAssembly/SettingsUI/VwrSettingsPaneOutput.swift index 0c8c4f7d..8a6f9618 100644 --- a/Packages/vChewing_MainAssembly/Sources/MainAssembly/SettingsUI/VwrSettingsPaneOutput.swift +++ b/Packages/vChewing_MainAssembly/Sources/MainAssembly/SettingsUI/VwrSettingsPaneOutput.swift @@ -36,14 +36,14 @@ public struct VwrSettingsPaneOutput: View { Form { Section { UserDef.kChineseConversionEnabled.bind( - $chineseConversionEnabled.onChange { + $chineseConversionEnabled.didChange { if chineseConversionEnabled, shiftJISShinjitaiOutputEnabled { shiftJISShinjitaiOutputEnabled = false } } ).render() UserDef.kShiftJISShinjitaiOutputEnabled.bind( - $shiftJISShinjitaiOutputEnabled.onChange { + $shiftJISShinjitaiOutputEnabled.didChange { if chineseConversionEnabled, shiftJISShinjitaiOutputEnabled { chineseConversionEnabled = false } diff --git a/Packages/vChewing_PhraseEditorUI/Sources/PhraseEditorUI/PhraseEditorUI.swift b/Packages/vChewing_PhraseEditorUI/Sources/PhraseEditorUI/PhraseEditorUI.swift index 4143a6f8..92e4f2a4 100644 --- a/Packages/vChewing_PhraseEditorUI/Sources/PhraseEditorUI/PhraseEditorUI.swift +++ b/Packages/vChewing_PhraseEditorUI/Sources/PhraseEditorUI/PhraseEditorUI.swift @@ -195,7 +195,7 @@ public struct VwrPhraseEditorUI: View { public var body: some View { VStack(spacing: 4) { HStack { - Picker("", selection: $selInputMode.onChange { dropDownMenuDidChange() }) { + Picker("", selection: $selInputMode.didChange { dropDownMenuDidChange() }) { switch currentIMEInputMode { case .imeModeCHS: Text(Shared.InputMode.imeModeCHS.localizedDescription).tag(Shared.InputMode.imeModeCHS) @@ -215,7 +215,7 @@ public struct VwrPhraseEditorUI: View { } } .labelsHidden() - Picker("", selection: $selUserDataType.onChange { dropDownMenuDidChange() }) { + Picker("", selection: $selUserDataType.didChange { dropDownMenuDidChange() }) { Text(vChewingLM.ReplacableUserDataType.thePhrases.localizedDescription).tag( vChewingLM.ReplacableUserDataType.thePhrases) Text(vChewingLM.ReplacableUserDataType.theFilter.localizedDescription).tag( @@ -251,7 +251,9 @@ public struct VwrPhraseEditorUI: View { .disabled(selInputMode == .imeModeNULL || isLoading) .frame(minWidth: 320, minHeight: 240) .onChange(of: fileChangeIndicator.id) { _ in - if Self.autoReloadExternalModifications { update() } + Task { + if Self.autoReloadExternalModifications { update() } + } } } @@ -267,7 +269,7 @@ public struct VwrPhraseEditorUI: View { if selUserDataType == .thePhrases { TextField( lblAddPhraseTag3, - text: $txtAddPhraseField3.onChange { + text: $txtAddPhraseField3.didChange { guard let weightVal = Double(txtAddPhraseField3) else { return } if weightVal > 0 { txtAddPhraseField3 = "" } } @@ -288,7 +290,7 @@ public struct VwrPhraseEditorUI: View { HStack { Toggle( LocalizedStringKey("This editor only: Auto-reload modifications happened outside of this editor"), - isOn: $selAutoReloadExternalModifications.onChange { + isOn: $selAutoReloadExternalModifications.didChange { Self.autoReloadExternalModifications = selAutoReloadExternalModifications } ) diff --git a/Packages/vChewing_SwiftExtension/Sources/SwiftExtension/SwiftUIExtension.swift b/Packages/vChewing_SwiftExtension/Sources/SwiftExtension/SwiftUIExtension.swift index b0e58017..65b275b9 100644 --- a/Packages/vChewing_SwiftExtension/Sources/SwiftExtension/SwiftUIExtension.swift +++ b/Packages/vChewing_SwiftExtension/Sources/SwiftExtension/SwiftUIExtension.swift @@ -8,13 +8,13 @@ import SwiftUI -// MARK: - Add "onChange" support. +// MARK: - Add "didChange" support to bindings. // Ref: https://mjeld.com/swiftui-macos-10-15-toggle-onchange/ @available(macOS 10.15, *) public extension Binding { - func onChange(_ action: @escaping () -> Void) -> Binding { + func didChange(_ action: @escaping () -> Void) -> Binding { Binding( get: { wrappedValue