TextEditorEX // Remove (buggy) tooltip binding support.
- This binding causes responsiveness issues towards the editor.
This commit is contained in:
parent
495270c4da
commit
ac6b53b3ec
|
@ -248,7 +248,7 @@ public struct VwrPhraseEditorUI: View {
|
|||
}
|
||||
}
|
||||
|
||||
TextEditorEX(text: $txtContent, tooltip: $textEditorTooltip)
|
||||
TextEditorEX(text: $txtContent)
|
||||
.disabled(selInputMode == .imeModeNULL || isLoading)
|
||||
.frame(minWidth: 320, minHeight: 240)
|
||||
.backport.onChange(of: fileChangeIndicator.id) { _ in
|
||||
|
|
|
@ -89,11 +89,9 @@ public struct VisualEffectView: NSViewRepresentable {
|
|||
/// A much faster alternative than Apple official TextEditor.
|
||||
public struct TextEditorEX: NSViewRepresentable {
|
||||
@Binding var text: String
|
||||
@Binding var tooltip: String
|
||||
|
||||
public init(text: Binding<String>, tooltip: Binding<String>) {
|
||||
public init(text: Binding<String>) {
|
||||
_text = text
|
||||
_tooltip = tooltip
|
||||
}
|
||||
|
||||
public func makeNSView(context: Context) -> NSScrollView {
|
||||
|
@ -101,23 +99,20 @@ public struct TextEditorEX: NSViewRepresentable {
|
|||
}
|
||||
|
||||
public func updateNSView(_ nsView: NSScrollView, context _: Context) {
|
||||
if let textArea = nsView.documentView as? NSTextView {
|
||||
if textArea.string != text { textArea.string = text }
|
||||
if textArea.toolTip != tooltip { textArea.toolTip = tooltip }
|
||||
if let textArea = nsView.documentView as? NSTextView, textArea.string != self.text {
|
||||
textArea.string = text
|
||||
}
|
||||
}
|
||||
|
||||
public func makeCoordinator() -> Coordinator {
|
||||
Coordinator(text: $text, tooltip: $tooltip)
|
||||
Coordinator(text: $text)
|
||||
}
|
||||
|
||||
public class Coordinator: NSObject, NSTextViewDelegate {
|
||||
public var text: Binding<String>
|
||||
public var tooltip: Binding<String>
|
||||
|
||||
public init(text: Binding<String>, tooltip: Binding<String>) {
|
||||
public init(text: Binding<String>) {
|
||||
self.text = text
|
||||
self.tooltip = tooltip
|
||||
}
|
||||
|
||||
public func textView(_ textView: NSTextView, shouldChangeTextIn range: NSRange, replacementString text: String?)
|
||||
|
@ -125,7 +120,6 @@ public struct TextEditorEX: NSViewRepresentable {
|
|||
{
|
||||
defer {
|
||||
self.text.wrappedValue = (textView.string as NSString).replacingCharacters(in: range, with: text!)
|
||||
self.tooltip.wrappedValue = (textView.toolTip as? NSString ?? "").replacingCharacters(in: range, with: text!)
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue