Skip to content

[iOS] The scroll position doesn't change when the text is changed from the parent view #132

@kkebo

Description

@kkebo

Description

The scroll position doesn't change when the text is changed from the parent view.

ScreenRecording_05-05-2025.03-00-46_1.mp4

How to reproduce the issue

  1. Create a new iOS app
  2. Add CodeEditorView as a dependency
  3. Write the following code:
    import SwiftUI
    import CodeEditorView
    
    struct ContentView: View {
        @State private var text = ""
        @State private var position = CodeEditor.Position()
    
        var body: some View {
            VStack {
                Button("Clear") {
                    text.removeAll()
                }
                .buttonStyle(.borderedProminent)
                .controlSize(.large)
                CodeEditor(text: $text, position: $position, messages: .constant([]))
                    .frame(height: 100)
            }
            .onChange(of: position) { oldValue, newValue in
                print(oldValue, newValue)
            }
        }
    }
  4. Run it
  5. Tap CodeEditor to put the cursor on it
  6. Press the return key repeatedly until it begins to scroll down
  7. Tap "Clear" button

Expected behavior

CodeEditor will scroll up to the first line just like when you tap "Select All" and press the delete key.

ScreenRecording_05-05-2025.04-03-31_1.mp4

Actual behavior

The text will be removed, but the scroll position won't be changed and you can't even scroll on it until you input some text. Also, onChange(of: position) won't be called.

Environment

  • CodeEditorView 0.15.4 and main (aba6c18)
  • iPadOS 18.5 Developer Beta 4

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Projects

    Status

    To do

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions