Skip to content

get cursor position with binding in swiftui view#9

Closed
joehinkle11 wants to merge 1 commit intoActuallyTaylor:mainfrom
joehinkle11:main
Closed

get cursor position with binding in swiftui view#9
joehinkle11 wants to merge 1 commit intoActuallyTaylor:mainfrom
joehinkle11:main

Conversation

@joehinkle11
Copy link
Contributor

Example usage

struct ContentView: View {
    @State var text = "hello"
    @State var cursorPosition: CGRect? = nil
    
    @ViewBuilder
    var autocompleteOverlay: some View {
        if let cursorPosition = cursorPosition {
            VStack {
                Text("You are typing here")
                Image(systemName: "arrow.down")
                    .foregroundColor(Color.red)
            }.offset(y: -20).position(x: cursorPosition.midX, y: cursorPosition.midY)
        }
    }
    
    var body: some View {
        ZStack {
            VStack {
                Text("firefly test")
                FireflySyntaxEditor(
                    text: $text,
                    cursorPosition: $cursorPosition,
                    language: "swift",
                    theme: "Xcode Light",
                    fontName: "system",
                    didChangeText: { _ in},
                    didChangeSelectedRange: {_,_ in},
                    textViewDidBeginEditing: {_ in}
                ).overlay(autocompleteOverlay)
            }
        }
    }
}

ActuallyTaylor pushed a commit that referenced this pull request Jul 1, 2021
#9 Now supports macOS
#11 Does not yet support macOS
@ActuallyTaylor
Copy link
Owner

This has been merged into https://github.com/ActuallyZach/Firefly/tree/MacOS

@ActuallyTaylor ActuallyTaylor reopened this Jul 5, 2021
@joehinkle11 joehinkle11 deleted the main branch June 14, 2022 07:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants