Docs native S1b: commands held for long show disabled; a click in a key's wait runs after it
Fable on #173, note 4. Without .allowsHitTesting(isEnabled) on the inspector and the iPhone toolbar, a click while a key was pending reached the control and the command refused it silently. - A toolbar, inspector or Format menu command now goes through DocsModel.whenCommandsReady: it runs at once if commands can run, else as soon as the pending input has been drawn (the last one asked for wins; dropped if editing becomes unavailable). ⌘B typed right behind a letter is no longer dropped either. - Held for longer than a glance (650 ms, the busy-button rule: a paused replica, a long composition), the inspector, the toolbar and the Format menu show disabled (observed commandsHeld). A key's few milliseconds never set it, so the panel neither blinks nor is evaluated per key. Tests: a bold clicked while a key is pending applies once the key is drawn (it was dropped); commands held for long show disabled and a key's wait never does (seen to fail with either half removed).
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
6 files changed,
+145
−44
native/apple/Sources/DocsKit/DocsEditorCommands.swift+17 −16native/apple/Sources/DocsKit/DocsEditorContext.swift+7 −0native/apple/Sources/DocsKit/DocsFormatInspector.swift+24 −18native/apple/Sources/DocsKit/DocsModel.swift+52 −1native/apple/Sources/DocsKit/EditorToolbar.swift+15 −9native/apple/Tests/DocsKitTests/SurfaceChromeTests.swift+30 −0
diff --git a/native/apple/Sources/DocsKit/DocsEditorCommands.swift b/native/apple/Sources/DocsKit/DocsEditorCommands.swift| index 9556ae7..9e377b9 100644 |
| --- a/native/apple/Sources/DocsKit/DocsEditorCommands.swift |
| +++ b/native/apple/Sources/DocsKit/DocsEditorCommands.swift |
| @@ -20,46 +20,47 @@ public struct DocsEditorCommands: Commands { |
| CommandMenu(text("docs.editor.menu.format")) { |
| Group { |
| - Button { editor?.actions?.perform("bold") } label: { text("docs.editor.toolbar.bold") }.keyboardShortcut("b") |
| - Button { editor?.actions?.perform("italic") } label: { text("docs.editor.toolbar.italic") }.keyboardShortcut("i") |
| - Button { editor?.actions?.perform("code") } label: { text("docs.editor.toolbar.code") } |
| + Button { editor?.ready { $0.perform("bold") } } label: { text("docs.editor.toolbar.bold") }.keyboardShortcut("b") |
| + Button { editor?.ready { $0.perform("italic") } } label: { text("docs.editor.toolbar.italic") }.keyboardShortcut("i") |
| + Button { editor?.ready { $0.perform("code") } } label: { text("docs.editor.toolbar.code") } |
| Divider() |
| // Body text and Heading 1–3, as the web: Headings 4–6 still |
| // render and edit, but are not offered. |
| Menu { |
| - Button { editor?.actions?.block("paragraph") } label: { text("docs.editor.toolbar.block.paragraph") } |
| + Button { editor?.ready { $0.block("paragraph") } } label: { text("docs.editor.toolbar.block.paragraph") } |
| ForEach(1...3, id: \.self) { level in |
| - Button { editor?.actions?.block("heading", level: level) } label: { text(EditorToolbar.headingKey(level)) } |
| + Button { editor?.ready { $0.block("heading", level: level) } } label: { text(EditorToolbar.headingKey(level)) } |
| } |
| } label: { text("docs.editor.toolbar.block") } |
| - Button { editor?.actions?.block("bullet_list") } label: { text("docs.editor.toolbar.bulletlist") } |
| - Button { editor?.actions?.block("ordered_list") } label: { text("docs.editor.toolbar.orderedlist") } |
| - Button { editor?.actions?.block("blockquote") } label: { text("docs.editor.toolbar.quote") } |
| + Button { editor?.ready { $0.block("bullet_list") } } label: { text("docs.editor.toolbar.bulletlist") } |
| + Button { editor?.ready { $0.block("ordered_list") } } label: { text("docs.editor.toolbar.orderedlist") } |
| + Button { editor?.ready { $0.block("blockquote") } } label: { text("docs.editor.toolbar.quote") } |
| Divider() |
| Menu { |
| // Each family's name in its own face; SwiftUI carries the |
| // font into the menu item's attributed title. |
| ForEach(DocsFontPicker.entries) { entry in |
| - Button { editor?.actions?.setFont(entry.key) } label: { DocsFontPicker.label(entry) } |
| + Button { editor?.ready { $0.setFont(entry.key) } } label: { DocsFontPicker.label(entry) } |
| } |
| } label: { text("docs.editor.toolbar.font") } |
| Menu { |
| ForEach(Self.sizes, id: \.self) { size in |
| - Button(size.formatted()) { editor?.actions?.format("size_" + String(size), exclusive: Self.sizes.map { "size_" + String($0) } + ["size_sm", "size_lg", "size_xl"]) } |
| + Button(size.formatted()) { editor?.ready { $0.format("size_" + String(size), exclusive: Self.sizes.map { "size_" + String($0) } + ["size_sm", "size_lg", "size_xl"]) } } |
| } |
| } label: { text("docs.editor.toolbar.size") } |
| Divider() |
| ForEach(["left", "center", "right"], id: \.self) { value in |
| - Button { editor?.actions?.blockAttribute("align", value: value == "left" ? nil : value) } label: { text("docs.editor.toolbar.align." + value) } |
| + Button { editor?.ready { $0.blockAttribute("align", value: value == "left" ? nil : value) } } label: { text("docs.editor.toolbar.align." + value) } |
| } |
| Divider() |
| - Button { editor?.actions?.perform("indent") } label: { text("docs.editor.menu.format.indent") } |
| - Button { editor?.actions?.perform("outdent") } label: { text("docs.editor.menu.format.outdent") } |
| - Button { editor?.actions?.perform("clear-format") } label: { text("docs.editor.menu.format.clear") } |
| + Button { editor?.ready { $0.perform("indent") } } label: { text("docs.editor.menu.format.indent") } |
| + Button { editor?.ready { $0.perform("outdent") } } label: { text("docs.editor.menu.format.outdent") } |
| + Button { editor?.ready { $0.perform("clear-format") } } label: { text("docs.editor.menu.format.clear") } |
| // isAvailable, not isEnabled: that one moves on every key (input |
| // pending), and the menu bar's commands were evaluated again with |
| - // it. Each command checks it as it runs. |
| - }.disabled(editor?.actions?.isAvailable != true || !(NSApp.keyWindow?.firstResponder is DocsTextView)) |
| + // it. A command chosen then runs once the input is drawn; held for |
| + // longer, the menu shows disabled. |
| + }.disabled(editor?.actions?.isAvailable != true || editor?.model.commandsHeld == true || !(NSApp.keyWindow?.firstResponder is DocsTextView)) |
| } |
| CommandGroup(after: .toolbar) { |
| // Disabled in a reader's window and in the home window (no |
diff --git a/native/apple/Sources/DocsKit/DocsEditorContext.swift b/native/apple/Sources/DocsKit/DocsEditorContext.swift| index 2fa3e3b..e25036a 100644 |
| --- a/native/apple/Sources/DocsKit/DocsEditorContext.swift |
| +++ b/native/apple/Sources/DocsKit/DocsEditorContext.swift |
| @@ -20,6 +20,13 @@ struct DocsEditorContext { |
| guard NSApp.keyWindow?.firstResponder is DocsTextView, model.history.loaded else { return nil } |
| return DocumentCommands(model: model, content: model.surface.content) |
| } |
| + /// A Format menu command: now, or once the input pending when it was |
| + /// chosen has been drawn (`DocsModel.whenCommandsReady`). |
| + @MainActor func ready(_ command: @escaping @MainActor (DocumentCommands) -> Void) { |
| + guard actions != nil else { return } |
| + let model = self.model |
| + model.whenCommandsReady { command(DocumentCommands(model: model, content: model.surface.content)) } |
| + } |
| } |
| extension FocusedValues { @Entry var docsEditor: DocsEditorContext? } |
| #endif |
diff --git a/native/apple/Sources/DocsKit/DocsFormatInspector.swift b/native/apple/Sources/DocsKit/DocsFormatInspector.swift| index c9dbc6f..c7e7383 100644 |
| --- a/native/apple/Sources/DocsKit/DocsFormatInspector.swift |
| +++ b/native/apple/Sources/DocsKit/DocsFormatInspector.swift |
| @@ -25,6 +25,12 @@ import SwiftUI |
| static let sizes = [8, 9, 10, 11, 12, 14, 18, 24, 36, 48, 72] |
| private var actions: DocumentCommands { DocumentCommands(model: model, content: model.surface.content) } |
| + /// Runs a command now, or once the input pending when it was clicked |
| + /// has been drawn (`DocsModel.whenCommandsReady`). |
| + private func ready(_ command: @escaping @MainActor (DocumentCommands) -> Void) { |
| + let model = self.model |
| + model.whenCommandsReady { command(DocumentCommands(model: model, content: model.surface.content)) } |
| + } |
| var body: some View { |
| #if DOCS_PROBES |
| @@ -42,29 +48,29 @@ import SwiftUI |
| } |
| section("docs.editor.toolbar.group.text") { |
| DocsSegmentedRow(items: [ |
| - .init(key: "docs.editor.toolbar.bold", icon: "bold", on: selection.marks.contains("strong")) { actions.perform("bold") }, |
| - .init(key: "docs.editor.toolbar.italic", icon: "italic", on: selection.marks.contains("em")) { actions.perform("italic") }, |
| - .init(key: "docs.editor.toolbar.code", icon: "chevron.left.forwardslash.chevron.right", on: selection.marks.contains("code")) { actions.perform("code") }, |
| + .init(key: "docs.editor.toolbar.bold", icon: "bold", on: selection.marks.contains("strong")) { ready { $0.perform("bold") } }, |
| + .init(key: "docs.editor.toolbar.italic", icon: "italic", on: selection.marks.contains("em")) { ready { $0.perform("italic") } }, |
| + .init(key: "docs.editor.toolbar.code", icon: "chevron.left.forwardslash.chevron.right", on: selection.marks.contains("code")) { ready { $0.perform("code") } }, |
| ]) |
| } |
| section("docs.editor.toolbar.group.align") { |
| DocsSegmentedRow(items: ["left", "center", "right"].map { value in |
| .init(key: "docs.editor.toolbar.align." + value, icon: "text.align" + value, on: selection.alignment == value) { |
| - actions.blockAttribute("align", value: value == "left" ? nil : value) |
| + ready { $0.blockAttribute("align", value: value == "left" ? nil : value) } |
| } |
| }) |
| } |
| section("docs.editor.toolbar.group.lists") { |
| DocsSegmentedRow(items: [ |
| - .init(key: "docs.editor.toolbar.bulletlist", icon: "list.bullet", on: selection.blocks.contains("bullet_list")) { actions.block("bullet_list") }, |
| - .init(key: "docs.editor.toolbar.orderedlist", icon: "list.number", on: selection.blocks.contains("ordered_list")) { actions.block("ordered_list") }, |
| - .init(key: "docs.editor.toolbar.quote", icon: "text.quote", on: selection.blocks.contains("blockquote")) { actions.block("blockquote") }, |
| + .init(key: "docs.editor.toolbar.bulletlist", icon: "list.bullet", on: selection.blocks.contains("bullet_list")) { ready { $0.block("bullet_list") } }, |
| + .init(key: "docs.editor.toolbar.orderedlist", icon: "list.number", on: selection.blocks.contains("ordered_list")) { ready { $0.block("ordered_list") } }, |
| + .init(key: "docs.editor.toolbar.quote", icon: "text.quote", on: selection.blocks.contains("blockquote")) { ready { $0.block("blockquote") } }, |
| ]) |
| // Native keeps the mock-up's second row (spec §13 Q2). |
| DocsSegmentedRow(items: [ |
| - .init(key: "docs.editor.menu.format.outdent", icon: "decrease.indent", on: false, mirrors: true) { actions.perform("outdent") }, |
| - .init(key: "docs.editor.menu.format.indent", icon: "increase.indent", on: false, mirrors: true) { actions.perform("indent") }, |
| - .init(key: "docs.editor.menu.format.clear", icon: "eraser", on: false, enabled: selection.hasSelection) { actions.perform("clear-format") }, |
| + .init(key: "docs.editor.menu.format.outdent", icon: "decrease.indent", on: false, mirrors: true) { ready { $0.perform("outdent") } }, |
| + .init(key: "docs.editor.menu.format.indent", icon: "increase.indent", on: false, mirrors: true) { ready { $0.perform("indent") } }, |
| + .init(key: "docs.editor.menu.format.clear", icon: "eraser", on: false, enabled: selection.hasSelection) { ready { $0.perform("clear-format") } }, |
| ]) |
| } |
| } |
| @@ -80,10 +86,10 @@ import SwiftUI |
| .compositingGroup() |
| .shadow(color: .black.opacity(colorScheme == .dark ? 0.4 : 0.14), radius: 16, y: 6) |
| // Replica work briefly gates commands on every keystroke; keep that |
| - // out of the disabled styling so the panel does not blink. Each |
| - // command checks it as it runs (DocumentCommands.isEnabled): read |
| - // here, it re-evaluated this panel twice a key (S1b, step 0). |
| - .disabled(!actions.isAvailable) |
| + // out of the disabled styling so the panel does not blink (and is |
| + // not evaluated again twice a key, S1b step 0): a click then runs |
| + // once the input is drawn. Held for longer, the panel shows disabled. |
| + .disabled(!actions.isAvailable || model.commandsHeld) |
| .accessibilityElement(children: .contain) |
| .accessibilityLabel(Text("docs.editor.inspector.label", bundle: DocsResources.bundle)) |
| .accessibilityIdentifier("docs.format.inspector") |
| @@ -115,8 +121,8 @@ import SwiftUI |
| let strings = DocsStrings(locale: locale) |
| let entries = Self.styleEntries(selected: selection.style, strings: strings) |
| return DocsPopUp(entries: entries, selected: selection.style, label: strings("docs.editor.toolbar.block"), identifier: "docs.style-picker") { style in |
| - if style.hasPrefix("heading"), let level = Int(style.dropFirst("heading".count)) { actions.block("heading", level: level) } |
| - else { actions.block("paragraph") } |
| + if style.hasPrefix("heading"), let level = Int(style.dropFirst("heading".count)) { ready { $0.block("heading", level: level) } } |
| + else { ready { $0.block("paragraph") } } |
| } |
| .frame(maxWidth: .infinity) |
| } |
| @@ -126,7 +132,7 @@ import SwiftUI |
| private func fontPicker(_ selection: DocumentToolbarSelection) -> some View { |
| let strings = DocsStrings(locale: locale) |
| return DocsPopUp(entries: DocsFontPicker.entries.map { .init(id: $0.key, title: $0.name, font: $0.font) }, |
| - selected: selection.font, label: strings("native.font"), identifier: "docs.font-picker") { actions.setFont($0) } |
| + selected: selection.font, label: strings("native.font"), identifier: "docs.font-picker") { key in ready { $0.setFont(key) } } |
| .frame(minWidth: 0, maxWidth: .infinity) |
| } |
| @@ -159,7 +165,7 @@ import SwiftUI |
| let strings = DocsStrings(locale: locale) |
| return DocsPopUp(entries: Self.sizes.map { .init(id: String($0), title: $0.formatted(.number.locale(locale)), font: nil) }, |
| selected: String(selection.size), label: strings("docs.editor.toolbar.size"), identifier: "docs.size-picker") { size in |
| - actions.format("size_" + size, exclusive: Self.sizes.map { "size_" + String($0) } + ["size_sm", "size_lg", "size_xl"]) |
| + ready { $0.format("size_" + size, exclusive: Self.sizes.map { "size_" + String($0) } + ["size_sm", "size_lg", "size_xl"]) } |
| } |
| } |
| } |
diff --git a/native/apple/Sources/DocsKit/DocsModel.swift b/native/apple/Sources/DocsKit/DocsModel.swift| index e5c03eb..de6165b 100644 |
| --- a/native/apple/Sources/DocsKit/DocsModel.swift |
| +++ b/native/apple/Sources/DocsKit/DocsModel.swift |
| @@ -55,6 +55,22 @@ import RastrilloNative |
| /// The formatting at the selection, for the toolbar: one value, |
| /// assigned only when it differs (spec §7 Design 10). |
| private(set) var toolbarSelection = DocumentToolbarSelection() |
| + /// Commands have been held back (input pending, composing, a |
| + /// generation catching up) for longer than a glance: the toolbar, |
| + /// inspector and Format menu show disabled until they can run. Not for |
| + /// the few milliseconds every key holds them, which would make the |
| + /// panel blink and SwiftUI evaluate it on every key (S1b step 0). A |
| + /// click in those milliseconds runs when they end (`whenCommandsReady`). |
| + @ObservationIgnored private var _commandsHeld = false |
| + private(set) var commandsHeld: Bool { |
| + get { access(keyPath: \.commandsHeld); return _commandsHeld } |
| + set { guard newValue != _commandsHeld else { return }; withMutation(keyPath: \.commandsHeld) { _commandsHeld = newValue } } |
| + } |
| + /// How long commands may be held before they show disabled: the |
| + /// busy-button rule's 650 ms. |
| + static var commandsHeldAfter: Duration = .milliseconds(650) |
| + @ObservationIgnored private var holdTask: Task<Void, Never>? |
| + @ObservationIgnored private var readyAction: (@MainActor () -> Void)? |
| /// The image sources of the document drawn, for the image loader. |
| private(set) var imageSources: [String] = [] |
| /// Moves when the editor asks for Open a document… (⌘K): the window |
| @@ -448,6 +464,7 @@ import RastrilloNative |
| } |
| editing.append(command) |
| if editingTask == nil { editingTask = Task { await drainEdits() } } |
| + holdCommands() |
| return true |
| } |
| private func drainEdits() async { |
| @@ -477,6 +494,7 @@ import RastrilloNative |
| } |
| func compositionChanged(_ active: Bool) { |
| composing = active |
| + if active { holdCommands() } |
| if !active { |
| // Trigger (c): composition ended. |
| surface.flushIfDeferred() |
| @@ -855,10 +873,43 @@ import RastrilloNative |
| let probeStart = DocsProbes.now() |
| defer { DocsProbes.toolbarRefreshes += 1; DocsProbes.toolbarRefreshMs += DocsProbes.ms(since: probeStart) } |
| #endif |
| - guard let value = DocumentToolbarSelection(commands: DocumentCommands(model: self, content: surface.content)), |
| + let commands = DocumentCommands(model: self, content: surface.content) |
| + if commands.isEnabled || !commands.isAvailable { releaseCommands(run: commands.isEnabled) } |
| + guard let value = DocumentToolbarSelection(commands: commands), |
| value != toolbarSelection else { return } |
| toolbarSelection = value |
| } |
| + /// A toolbar, inspector or menu command: now if commands can run, else |
| + /// as soon as they can (the input pending when it was clicked has been |
| + /// drawn), so a click never does nothing. The last one asked for wins. |
| + func whenCommandsReady(_ action: @escaping @MainActor () -> Void) { |
| + let commands = DocumentCommands(model: self, content: surface.content) |
| + if commands.isEnabled { action(); return } |
| + guard commands.isAvailable else { return } |
| + readyAction = action |
| + holdCommands() |
| + } |
| + /// Commands are held from now: after `commandsHeldAfter`, if they still |
| + /// are, they show disabled. |
| + private func holdCommands() { |
| + guard holdTask == nil, !commandsHeld else { return } |
| + holdTask = Task { @MainActor [weak self] in |
| + try? await Task.sleep(for: Self.commandsHeldAfter) |
| + guard let self, !Task.isCancelled else { return } |
| + self.holdTask = nil |
| + let commands = DocumentCommands(model: self, content: self.surface.content) |
| + if !commands.isEnabled && commands.isAvailable { self.commandsHeld = true } |
| + } |
| + } |
| + /// Commands can run (or never will, for now): stop holding, and run |
| + /// the command clicked meanwhile if they can. |
| + private func releaseCommands(run: Bool) { |
| + holdTask?.cancel(); holdTask = nil |
| + commandsHeld = false |
| + guard let action = readyAction else { return } |
| + readyAction = nil |
| + if run { action() } |
| + } |
| /// A command from the text view's keys. |
| func perform(_ action: String) -> Bool { |
| if action == "jump" { jumpRequests &+= 1; return true } |
diff --git a/native/apple/Sources/DocsKit/EditorToolbar.swift b/native/apple/Sources/DocsKit/EditorToolbar.swift| index f6a11ec..bc7974a 100644 |
| --- a/native/apple/Sources/DocsKit/EditorToolbar.swift |
| +++ b/native/apple/Sources/DocsKit/EditorToolbar.swift |
| @@ -20,9 +20,9 @@ import SwiftUI |
| } |
| } label: { Text(selection.styleLabel).frame(minWidth: 100, alignment: .leading) }.accessibilityLabel(Text("native.style", bundle: DocsResources.bundle)) |
| #if os(macOS) |
| - DocsFontPopUp(selected: selection.font) { actions.setFont($0) }.fixedSize() |
| + DocsFontPopUp(selected: selection.font) { key in ready { $0.setFont(key) } }.fixedSize() |
| #else |
| - DocsFontPickerButton(selected: selection.font) { actions.setFont($0) } |
| + DocsFontPickerButton(selected: selection.font) { key in ready { $0.setFont(key) } } |
| #endif |
| Menu { |
| ForEach([12, 8, 9, 10, 11, 14, 18, 24, 36, 48, 72], id: \.self) { size in |
| @@ -57,12 +57,12 @@ import SwiftUI |
| .accessibilityIdentifier("docs.formatting-toolbar") |
| // Replica work briefly gates commands on every keystroke. Keep that |
| // synchronization gate out of disabled styling so the bar does not |
| - // blink; each command checks it as it runs (DocumentCommands.isEnabled), |
| - // since reading it here re-evaluated the bar on every key. |
| - .disabled(!actions.isAvailable) |
| + // blink (and is not evaluated again every key): a tap then runs once |
| + // the input is drawn. Held for longer, the bar shows disabled. |
| + .disabled(!actions.isAvailable || model.commandsHeld) |
| } |
| private func command(_ key: String, icon: String, op: String, enabled: Bool) -> some View { |
| - Button { actions.perform(op) } label: { Image(systemName: icon) } |
| + Button { ready { $0.perform(op) } } label: { Image(systemName: icon) } |
| .accessibilityLabel(Text(LocalizedStringKey(key), bundle: DocsResources.bundle)).disabled(!enabled) |
| } |
| private func mark(_ key: String, icon: String, name: String, active: Bool) -> some View { |
| @@ -71,9 +71,15 @@ import SwiftUI |
| .accessibilityAddTraits(active ? .isSelected : []) |
| } |
| private var actions: DocumentCommands { DocumentCommands(model: model, content: model.surface.content) } |
| - private func format(_ name: String, exclusive: [String] = []) { actions.format(name, exclusive: exclusive) } |
| - private func block(_ type: String, level: Int = 1) { actions.block(type, level: level) } |
| - private func blockAttribute(_ name: String, value: String) { actions.blockAttribute(name, value: value == "left" ? nil : value) } |
| + private func format(_ name: String, exclusive: [String] = []) { ready { $0.format(name, exclusive: exclusive) } } |
| + private func block(_ type: String, level: Int = 1) { ready { $0.block(type, level: level) } } |
| + private func blockAttribute(_ name: String, value: String) { ready { $0.blockAttribute(name, value: value == "left" ? nil : value) } } |
| + /// Runs a command now, or once the input pending when it was tapped |
| + /// has been drawn (`DocsModel.whenCommandsReady`). |
| + private func ready(_ command: @escaping @MainActor (DocumentCommands) -> Void) { |
| + let model = self.model |
| + model.whenCommandsReady { command(DocumentCommands(model: model, content: model.surface.content)) } |
| + } |
| } |
| extension EditorToolbar { |
diff --git a/native/apple/Tests/DocsKitTests/SurfaceChromeTests.swift b/native/apple/Tests/DocsKitTests/SurfaceChromeTests.swift| index 7b0e9e0..c9accb6 100644 |
| --- a/native/apple/Tests/DocsKitTests/SurfaceChromeTests.swift |
| +++ b/native/apple/Tests/DocsKitTests/SurfaceChromeTests.swift |
| @@ -67,6 +67,36 @@ import XCTest |
| try await until("enabled again") { commands().isEnabled } |
| } |
| + /// A toolbar, inspector or menu command clicked while a key is still |
| + /// pending is not dropped (Fable on #173, note 4): it runs once the key |
| + /// has been drawn. Before, the panel's controls took the click and the |
| + /// command refused it silently. |
| + func testACommandClickedWhileInputIsPendingRunsOnceTheInputIsDrawn() async throws { |
| + typeInTheMiddle("x") |
| + XCTAssertTrue(model.hasPendingInput) |
| + let model = self.model! |
| + model.whenCommandsReady { _ = DocumentCommands(model: model, content: model.surface.content).perform("bold") } |
| + XCTAssertNil(model.typingMarks?["strong"], "not while the key is pending") |
| + try await until("the bold clicked meanwhile") { model.typingMarks?["strong"] != nil } |
| + XCTAssertFalse(model.commandsHeld) |
| + } |
| + |
| + /// Commands held back longer than a glance show disabled; a key's few |
| + /// milliseconds never do (that would blink the panel on every key). |
| + func testCommandsHeldForLongShowDisabledAndAKeyNeverDoes() async throws { |
| + typeInTheMiddle("y") |
| + try await until("the key drawn") { DocumentCommands(model: model, content: model.surface.content).isEnabled } |
| + try await Task.sleep(for: .milliseconds(100)) |
| + XCTAssertFalse(model.commandsHeld, "a key's pending input") |
| + let after = DocsModel.commandsHeldAfter |
| + DocsModel.commandsHeldAfter = .milliseconds(30) |
| + defer { DocsModel.commandsHeldAfter = after } |
| + model.compositionChanged(true) |
| + try await until("held commands show disabled") { model.commandsHeld } |
| + model.compositionChanged(false) |
| + try await until("released") { !model.commandsHeld } |
| + } |
| + |
| /// Undo and redo read the observed history, set with each publication: |
| /// it is current while input is still pending (the toolbar selection |
| /// keeps its last state then), and for a reader, whose toolbar |