32 lines
989 B
Swift
32 lines
989 B
Swift
|
|
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
|
|||
|
|
}
|
|||
|
|
}
|