oficina / docs Public

Docs native S2a: the style pop-up shows Heading 4–6 as itself

A selection in Heading 4–6 left the pop-up on the last style it showed
(Fable on #169, finding 5). It now adds that level ("Heading %d", the
catalog's own format, in each language) as the selected entry. Headings
4–6 are still not offered. DocsInspectorStyleTests (red before: the last
entry was Heading 3).
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Paul Campbell pushed by claude agent, operated by paul@keymail.dev a0033286111ce25d70f31ebb98e1a65138a70d3f parent b1272b8
2 files changed, +44 −6
  • native/apple/Sources/DocsKit/DocsFormatInspector.swift +26 −6
  • native/apple/Tests/DocsKitTests/DocsInspectorStyleTests.swift +18 −0
diff --git a/native/apple/Sources/DocsKit/DocsFormatInspector.swift b/native/apple/Sources/DocsKit/DocsFormatInspector.swift
index d8e7059..a2e87b3 100644
--- a/native/apple/Sources/DocsKit/DocsFormatInspector.swift
+++ b/native/apple/Sources/DocsKit/DocsFormatInspector.swift
@@ -113,12 +113,7 @@ import SwiftUI
/// Body text and Heading 1–3, each in its own face.
private func stylePicker(_ selection: DocumentToolbarSelection) -> some View {
let strings = DocsStrings(locale: locale)
- var entries = [DocsPopUp.Entry(id: "paragraph", title: strings("docs.editor.toolbar.block.paragraph"),
- font: DocsFonts.font(marks: [:], size: 13, heading: false))]
- for level in 1...3 {
- entries.append(.init(id: "heading" + String(level), title: strings(EditorToolbar.headingKey(level)),
- font: DocsFonts.font(marks: [:], size: 13, heading: true)))
- }
+ 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") }
@@ -135,6 +130,31 @@ import SwiftUI
.frame(minWidth: 0, maxWidth: .infinity)
}
+ /// Body text and Headings 1–3, each in its own face, and the selection's
+ /// own level when it is in a Heading 4–6.
+ static func styleEntries(selected: String, strings: DocsStrings) -> [DocsPopUp.Entry] {
+ var entries = [DocsPopUp.Entry(id: "paragraph", title: strings("docs.editor.toolbar.block.paragraph"),
+ font: DocsFonts.font(marks: [:], size: 13, heading: false))]
+ for level in 1...3 {
+ entries.append(.init(id: "heading" + String(level), title: strings(EditorToolbar.headingKey(level)),
+ font: DocsFonts.font(marks: [:], size: 13, heading: true)))
+ }
+ // Headings 4–6 still render and edit but are not offered (spec §1,
+ // menus). A selection in one shows its own level, never the style
+ // the pop-up last showed.
+ if selected.hasPrefix("heading"), let level = Int(selected.dropFirst("heading".count)), level > 3 {
+ entries.append(.init(id: selected, title: Self.headingTitle(level, strings: strings),
+ font: DocsFonts.font(marks: [:], size: 13, heading: true)))
+ }
+ return entries
+ }
+
+ /// "Heading 4" and so on, from the catalog's own format ("Heading %d").
+ static func headingTitle(_ level: Int, strings: DocsStrings) -> String {
+ let format = strings.bundle.localizedString(forKey: "Heading %d", value: nil, table: "Mac")
+ return String(format: format, level)
+ }
+
private func sizePicker(_ selection: DocumentToolbarSelection) -> some View {
let strings = DocsStrings(locale: locale)
return DocsPopUp(entries: Self.sizes.map { .init(id: String($0), title: $0.formatted(.number.locale(locale)), font: nil) },
diff --git a/native/apple/Tests/DocsKitTests/DocsInspectorStyleTests.swift b/native/apple/Tests/DocsKitTests/DocsInspectorStyleTests.swift
new file mode 100644
index 0000000..c1bfbef
--- /dev/null
+++ b/native/apple/Tests/DocsKitTests/DocsInspectorStyleTests.swift
@@ -0,0 +1,18 @@
+#if os(macOS)
+import XCTest
+@testable import DocsKit
+
+/// The Format inspector's style pop-up (Fable on #169, finding 5): a
+/// selection in Heading 4–6 shows that level, not the last style shown.
+final class DocsInspectorStyleTests: XCTestCase {
+ @MainActor func testHeadingsFourToSixShowTheirOwnLevel() {
+ let en = DocsStrings(locale: Locale(identifier: "en"))
+ XCTAssertEqual(DocsFormatInspector.styleEntries(selected: "paragraph", strings: en).map(\.id), ["paragraph", "heading1", "heading2", "heading3"])
+ let five = DocsFormatInspector.styleEntries(selected: "heading5", strings: en)
+ XCTAssertEqual(five.last?.id, "heading5", "the pop-up can select it")
+ XCTAssertEqual(five.last?.title, "Heading 5")
+ let ru = DocsFormatInspector.styleEntries(selected: "heading4", strings: DocsStrings(locale: Locale(identifier: "ru")))
+ XCTAssertEqual(ru.last?.title, "Заголовок 4")
+ }
+}
+#endif