// A LONG TEXT, WHOLE SCREEN (door row 8). A longtext column is too long// for one line, so a tap on its words opens them on the whole screen, on the// same paper in the same typewriter, the caret at the end: a note's body, a// todo's notes, any longtext a card shows. Done writes them and returns to// the same card at the same page; words left as they were write nothing.// Every other text column is written in the short-text input// (`DeckLineInput`).//// The presenter is the shell's writing layer (`DeckWritingLayer`), over the// whole stack: the deck's editing presents no sheet of its own// (`DeckNoSheetsTests`).importCottonKitimportCottonPaperimportCottonVoiceimportSwiftUIstructDeckLongTextEditor: View {/// The record's title, over its words.let title: String?/// The words as the card showed them.let words: String/// Where a dictation here is: the table, column and record written.var voice: VoicePlanRequest = VoicePlanRequest(surface: "note", mode: .dictate)/// The words to write, nil when nothing changed.let done: (String?) -> Void @Environment(\.theme) privatevar theme @Environment(\.cottonCore) privatevar core @State privatevar draft = "" @State privatevar selection: TextSelection? @State privatevar dictation: VoiceField? @FocusState privatevar focused: Boolvar body: someView { VStack(alignment: .leading, spacing: 0) { HStack {iflet title {Text(title) .font(CottonFonts.serif(NoteFaceKnobs.titleSize)) .foregroundStyle(theme.print(.ink)) .lineLimit(1) .accessibilityAddTraits(.isHeader) }Spacer()NavCircle(symbol: "checkmark", label: ShellLines.line("lists", "done")) { finish() } .accessibilityIdentifier("deck-note-editor-done") } .padding(.horizontal, DeckKnobs.lineSide) .padding(.top, 12) .padding(.bottom, 8)TextEditor(text: $draft, selection: $selection) .font(CottonFonts.type(NoteFaceKnobs.bodySize + 2)) .lineSpacing(NoteFaceKnobs.bodyLeading) .foregroundStyle(theme.print(.ink)) .tint(theme.print(.red)) .scrollContentBackground(.hidden) .focused($focused) .padding(.horizontal, DeckKnobs.lineSide - 5) .accessibilityIdentifier("deck-note-editor") .onChange(of: draft) { _, now in dictation?.fieldChanged(now) } .onChange(of: selection) { _, now iniflet range = draft.utf16Range(now) { dictation?.selectionChanged(range) } }// The mic, where every writer has it: the trailing end of the bar// on the keyboard.iflet dictation {VoiceFieldBar( field: dictation, identifier: "deck-note-editor-mic", request: { voice }, text: { draft }, selection: { draft.utf16Range(selection) }, write: { draft = $0 }) .padding(.horizontal, DeckKnobs.lineSide - 12) .padding(.vertical, 4) .background(theme.colors.ground.color) } } .background(theme.colors.ground.color.ignoresSafeArea()) .onAppear { draft = words focused = trueif dictation == nil, let core { dictation = VoiceField(session: VoiceSessions.make(core: core), inlineTentative: false) } } .onDisappear { dictation?.session.cancel() } }privatefunc finish() {// Done while dictating keeps what was heard.iflet dictation, dictation.isActive {Task { draft = await dictation.stop() finish() }return } focused = falselet text = draft.trimmingCharacters(in: .whitespacesAndNewlines) done(text == words.trimmingCharacters(in: .whitespacesAndNewlines) ? nil : text) }}