kyle-n / HighlightedTextEditor

A SwiftUI view for dynamically highlighting user input
MIT License
726 stars 69 forks source link

Undo? #69

Closed fakerybakery closed 1 year ago

fakerybakery commented 1 year ago

Is your feature request related to a problem? Please describe. I noticed that this library does not allow undoing text. #34 allows an undo manager, however I wasn't able to figure out how to undo text.

Describe the solution you'd like Would it be possible to allow Command Z on macOS?

Thank you!

RosTeHeA commented 1 year ago

Would love the same!

kyle-n commented 1 year ago

You can enable undo/redo using .introspect().

import SwiftUI
import HighlightedTextEditor

struct ContentView: View {
    @State private var text = "one"

    var body: some View {
        VStack {
            HighlightedTextEditor(text: $text, highlightRules: .markdown)
                .introspect { editor in
                    editor.textView.allowsUndo = true
                }
        }
    }
}

I will release a new version of this library with allowsUndo on by default. Until then, I recommend this workaround.

RosTeHeA commented 1 year ago

Oh my - you just saved me so much time with this response—I had literally pulled up Stack Overflow and was about to try a more "hacky" approach. Thank you, and thank you for this library!

Michael On Jul 31, 2023 at 2:20 PM -0600, Kyle Nazario @.***>, wrote:

Closed #69 as completed. — Reply to this email directly, view it on GitHub, or unsubscribe. You are receiving this because you commented.Message ID: @.***>