CodeEditApp / CodeEditSourceEditor

A code editor view written in Swift powered by tree-sitter.
https://codeeditapp.github.io/CodeEditSourceEditor/documentation/codeeditsourceeditor
MIT License
504 stars 74 forks source link

Fixes text binding update #160

Closed miguel-arrf closed 1 year ago

miguel-arrf commented 1 year ago

Description

The STTextViewDelegate textDidChange function changed to textViewDidChangeText. Without this change, the text binding value wasn't updated.

Before, in a situation like the one below, the prompt variable was never updated since the delegate function was not called because of the mismatched signature.

@State var prompt: String = "..."
(...)

 CodeEditTextView(
    $prompt,
    language: .default,
    theme: $theme,
    font: $font,
    tabWidth: $tabWidth,
    lineHeight: $lineHeight, wrapLines: .constant(true),
    editorOverscroll: $editorOverscroll
)
.onChange(of: prompt, perform: { promptUpdate in
    print(promptUpdate)
})

With the proposed update, the behaviour is as expected. The onChange is now triggered.

The STTextViewDelegate: https://github.com/krzyzanowskim/STTextView/blob/main/Sources/STTextView/STTextViewDelegate.swift

Checklist