PhraseEditorUI // Remove isSaved() to solve an issue with TextEditor.

This commit is contained in:
ShikiSuen 2022-12-08 16:52:13 +08:00
parent 89d2884ea2
commit 31ae856530
1 changed files with 4 additions and 9 deletions

View File

@ -43,7 +43,6 @@ public struct VwrPhraseEditorUI: View {
@State public var selInputMode: Shared.InputMode = .imeModeNULL @State public var selInputMode: Shared.InputMode = .imeModeNULL
@State public var selUserDataType: vChewingLM.ReplacableUserDataType = .thePhrases @State public var selUserDataType: vChewingLM.ReplacableUserDataType = .thePhrases
@State private var isLoading = false @State private var isLoading = false
@State private var isSaved = false
public var currentIMEInputMode: Shared.InputMode { public var currentIMEInputMode: Shared.InputMode {
delegate?.currentInputMode ?? selInputMode delegate?.currentInputMode ?? selInputMode
@ -79,7 +78,6 @@ public struct VwrPhraseEditorUI: View {
isLoading = true isLoading = true
DispatchQueue.main.async { DispatchQueue.main.async {
txtContent = delegate.retrieveData(mode: selInputMode, type: selUserDataType) txtContent = delegate.retrieveData(mode: selInputMode, type: selUserDataType)
isSaved = true
isLoading = false isLoading = false
} }
} }
@ -145,7 +143,6 @@ public struct VwrPhraseEditorUI: View {
arrResult.insert("\n", at: 0) arrResult.insert("\n", at: 0)
} }
txtContent.append(arrResult.joined(separator: " ") + "\n") txtContent.append(arrResult.joined(separator: " ") + "\n")
isSaved = false
clearAllFields() clearAllFields()
} }
@ -161,14 +158,13 @@ public struct VwrPhraseEditorUI: View {
} }
private func saveAndReload() { private func saveAndReload() {
guard let delegate = delegate, selInputMode != .imeModeNULL, !isSaved else { return } guard let delegate = delegate, selInputMode != .imeModeNULL else { return }
let toSave = txtContent let toSave = txtContent
txtContent = NSLocalizedString("Loading…", comment: "") txtContent = NSLocalizedString("Loading…", comment: "")
isLoading = true isLoading = true
let newResult = delegate.saveData(mode: selInputMode, type: selUserDataType, data: toSave) let newResult = delegate.saveData(mode: selInputMode, type: selUserDataType, data: toSave)
txtContent = newResult txtContent = newResult
isLoading = false isLoading = false
isSaved = true
} }
private func consolidate() { private func consolidate() {
@ -180,7 +176,6 @@ public struct VwrPhraseEditorUI: View {
delegate.tagOverrides(in: &txtContent, mode: selInputMode) delegate.tagOverrides(in: &txtContent, mode: selInputMode)
} }
isLoading = false isLoading = false
isSaved = false
} }
} }
@ -237,11 +232,11 @@ public struct VwrPhraseEditorUI: View {
Button("Save") { Button("Save") {
DispatchQueue.main.async { saveAndReload() } DispatchQueue.main.async { saveAndReload() }
}.keyboardShortcut("s", modifiers: [.command]) }.keyboardShortcut("s", modifiers: [.command])
.disabled(isSaved || delegate == nil) .disabled(delegate == nil)
} else { } else {
Button("Save") { Button("Save") {
DispatchQueue.main.async { saveAndReload() } DispatchQueue.main.async { saveAndReload() }
}.disabled(isSaved || delegate == nil) }
} }
Button("...") { Button("...") {
DispatchQueue.main.async { DispatchQueue.main.async {
@ -251,7 +246,7 @@ public struct VwrPhraseEditorUI: View {
} }
} }
TextEditorEX(text: $txtContent.onChange { isSaved = false }) TextEditorEX(text: $txtContent)
.disabled(selInputMode == .imeModeNULL || isLoading) .disabled(selInputMode == .imeModeNULL || isLoading)
.frame(minWidth: 320, minHeight: 240) .frame(minWidth: 320, minHeight: 240)
.backport.onChange(of: fileChangeIndicator.id) { _ in .backport.onChange(of: fileChangeIndicator.id) { _ in