PadXcode-iPad/Editor/JumpToLineView.swift
2026-04-12 00:46:30 -07:00

31 lines
989 B
Swift
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import SwiftUI
struct JumpToLineView: View {
@Binding var isPresented: Bool
let totalLines: Int
let onJump: (Int) -> Void
@State private var input = ""
@FocusState private var focused: Bool
var body: some View {
VStack(spacing: 16) {
Text("Jump to Line").font(.headline)
HStack {
TextField("Line (1\(totalLines))", text: $input)
.textFieldStyle(.roundedBorder).keyboardType(.numberPad).focused($focused).onSubmit { commit() }
Button("Go", action: commit).buttonStyle(.borderedProminent).disabled(parsed == nil)
}
}
.padding(24).frame(width: 320)
.onAppear { focused = true }
}
private var parsed: Int? {
guard let n = Int(input), n >= 1, n <= totalLines else { return nil }
return n
}
private func commit() {
guard let line = parsed else { return }
onJump(line); isPresented = false
}
}