From 60b646205526c9cc614bd8a89dde09039e41b8c4 Mon Sep 17 00:00:00 2001 From: Pluviobyte <94058511+Pluviobyte@users.noreply.github.com> Date: Thu, 28 May 2026 01:47:14 +0800 Subject: [PATCH] Fix marked text handling in editor --- Textream/Textream/HighlightingTextEditor.swift | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/Textream/Textream/HighlightingTextEditor.swift b/Textream/Textream/HighlightingTextEditor.swift index 1ec67ee..e24b30e 100644 --- a/Textream/Textream/HighlightingTextEditor.swift +++ b/Textream/Textream/HighlightingTextEditor.swift @@ -68,6 +68,10 @@ struct HighlightingTextEditor: NSViewRepresentable { func updateNSView(_ scrollView: NSScrollView, context: Context) { guard let textView = scrollView.documentView as? NSTextView else { return } + if textView.hasMarkedText() { + return + } + if textView.string != text { let selectedRanges = textView.selectedRanges textView.string = text @@ -106,12 +110,14 @@ struct HighlightingTextEditor: NSViewRepresentable { func textDidChange(_ notification: Notification) { guard let textView = notification.object as? NSTextView else { return } + guard !textView.hasMarkedText() else { return } parent.text = textView.string applyHighlighting(textView) } func textViewDidChangeSelection(_ notification: Notification) { guard let textView = notification.object as? NSTextView else { return } + guard !textView.hasMarkedText() else { return } let pos = textView.selectedRange().location if parent.editorCaretPosition != pos { DispatchQueue.main.async { [weak self] in @@ -141,6 +147,7 @@ struct HighlightingTextEditor: NSViewRepresentable { func applyHighlighting(_ textView: NSTextView) { guard let textStorage = textView.textStorage else { return } + guard !textView.hasMarkedText() else { return } let fullRange = NSRange(location: 0, length: textStorage.length) let text = textStorage.string