native: a refused rename says why; no dead container storage; circles scale
Fable on #180 (6). - The rename alert ignored a `commitRename()` refusal: the alert went and the title stayed. Refused, the alert now comes back (once the answered one has gone: one presented during its dismissal is dropped) with the title as typed and why: "That title is too long." over the server's 1,024 bytes (new key `native.rename.tooLong`, all 12 catalogues, drafted), else the model's error, else "Something went wrong.". - `DocsPageTextContainer.storage` was dead (the iPhone's TextKit 2 view has no such container): removed; DocsPaging.swift is main's again. - The share panel's 28pt avatar and icon circles held letters and symbols that now scale with Dynamic Type: the circles scale with them (@ScaledMetric; the Mac keeps 28pt). Test: the writer XCUITest renames to 257 "📄" (1,050 bytes with the title) and sees the alert back with the refusal and the title as typed, then Cancel. (An alert's controls reach UIKit without their identifiers: the test finds them by role and title.) DocsSubtitleTests checks the new key in every language.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
17 files changed,
+58
−9
native/apple/Sources/DocsKit/DocsPaging.swift+1 −4native/apple/Sources/DocsKit/DocsSharePanel.swift+5 −2native/apple/Sources/DocsKit/DocsWorkspace.swift+24 −2native/apple/Sources/DocsKit/Resources/ar.lproj/Localizable.strings+1 −0native/apple/Sources/DocsKit/Resources/bn.lproj/Localizable.strings+1 −0native/apple/Sources/DocsKit/Resources/en.lproj/Localizable.strings+1 −0native/apple/Sources/DocsKit/Resources/es.lproj/Localizable.strings+1 −0native/apple/Sources/DocsKit/Resources/ga.lproj/Localizable.strings+1 −0native/apple/Sources/DocsKit/Resources/hi.lproj/Localizable.strings+1 −0native/apple/Sources/DocsKit/Resources/ja.lproj/Localizable.strings+1 −0native/apple/Sources/DocsKit/Resources/pt.lproj/Localizable.strings+1 −0native/apple/Sources/DocsKit/Resources/ru.lproj/Localizable.strings+1 −0native/apple/Sources/DocsKit/Resources/vi.lproj/Localizable.strings+1 −0native/apple/Sources/DocsKit/Resources/yue.lproj/Localizable.strings+1 −0native/apple/Sources/DocsKit/Resources/zh-Hans.lproj/Localizable.strings+1 −0native/apple/Tests/DocsKitTests/DocsSubtitleTests.swift+1 −1native/ios/UITests/NativeUITests.swift+15 −0
diff --git a/native/apple/Sources/DocsKit/DocsPaging.swift b/native/apple/Sources/DocsKit/DocsPaging.swift| index a876f33..a20c929 100644 |
| --- a/native/apple/Sources/DocsKit/DocsPaging.swift |
| +++ b/native/apple/Sources/DocsKit/DocsPaging.swift |
| @@ -72,9 +72,6 @@ final class DocsPageTextContainer: NSTextContainer { |
| } |
| /// A layout stack that measures and never draws (probe counts only). |
| var isMeasurement = false |
| - /// The text, when no TextKit 1 layout manager holds it (the iPhone's |
| - /// TextKit 2 view, S3). |
| - weak var storage: NSTextStorage? |
| override var isSimpleRectangularTextContainer: Bool { false } |
| override func lineFragmentRect( |
| forProposedRect proposedRect: CGRect, at characterIndex: Int, |
| @@ -89,7 +86,7 @@ final class DocsPageTextContainer: NSTextContainer { |
| #if os(macOS) |
| if let top = tops?.top(at: characterIndex) { rect.origin.y = max(rect.minY, top) } |
| #endif |
| - if let storage = layoutManager?.textStorage ?? storage, characterIndex < storage.length { |
| + if let storage = layoutManager?.textStorage, characterIndex < storage.length { |
| if characterIndex == 0, let margin = storage.attribute(.docsFirstMargin, at: 0, effectiveRange: nil) as? CGFloat { |
| rect.origin.y = max(rect.minY, DocsPageGeometry.verticalMargin + margin) |
| } |
diff --git a/native/apple/Sources/DocsKit/DocsSharePanel.swift b/native/apple/Sources/DocsKit/DocsSharePanel.swift| index 2280673..df3e435 100644 |
| --- a/native/apple/Sources/DocsKit/DocsSharePanel.swift |
| +++ b/native/apple/Sources/DocsKit/DocsSharePanel.swift |
| @@ -19,6 +19,9 @@ import UIKit |
| var focusOnAppear = true |
| let close: () -> Void |
| @Environment(\.locale) private var locale |
| + /// The avatars' and icons' circles: 28pt, growing with their letters |
| + /// and symbols under Dynamic Type (iPhone and iPad; the Mac keeps 28). |
| + @ScaledMetric(relativeTo: .footnote) private var circle: CGFloat = 28 |
| @FocusState private var focus: Field? |
| @AccessibilityFocusState private var headFocused: Bool |
| enum Field: Hashable { case email } |
| @@ -207,7 +210,7 @@ import UIKit |
| HStack(spacing: DocsSpacing.sp2) { |
| Text(verbatim: initial) |
| .font(DocsType.font(12, .semibold, ios: .footnote)) |
| - .frame(width: 28, height: 28) |
| + .frame(width: circle, height: circle) |
| .foregroundStyle(mine ? OficinaPalette.onAccent : OficinaPalette.accent(.docs)) |
| .background(Circle().fill(mine ? OficinaPalette.accent(.docs) : OficinaPalette.accentSoft(.docs))) |
| .accessibilityHidden(true) |
| @@ -257,7 +260,7 @@ import UIKit |
| HStack(spacing: DocsSpacing.sp3) { |
| Image(systemName: icon) |
| .font(DocsType.font(14, .medium, ios: .callout)) |
| - .frame(width: 28, height: 28) |
| + .frame(width: circle, height: circle) |
| .foregroundStyle(OficinaPalette.textMuted) |
| .background(Circle().fill(OficinaPalette.sunk)) |
| .accessibilityHidden(true) |
diff --git a/native/apple/Sources/DocsKit/DocsWorkspace.swift b/native/apple/Sources/DocsKit/DocsWorkspace.swift| index e56f57b..154edb5 100644 |
| --- a/native/apple/Sources/DocsKit/DocsWorkspace.swift |
| +++ b/native/apple/Sources/DocsKit/DocsWorkspace.swift |
| @@ -40,6 +40,8 @@ import SwiftUI |
| /// up at once: the second would be dropped). |
| @State private var afterFormatting: (() -> Void)? |
| @State private var renamingAlert = false |
| + /// Why the last rename was refused, shown in the alert brought back. |
| + @State private var renameRefusal: String? |
| @State private var renameText = "" |
| #endif |
| private let updateRecents: (([(String, String)]) -> Void)? |
| @@ -734,9 +736,12 @@ extension DocsWorkspace { |
| .alert(Text("docs.document.rename", bundle: DocsResources.bundle), isPresented: $renamingAlert) { |
| TextField(text: $renameText) { Text("docs.list.create.placeholder", bundle: DocsResources.bundle) } |
| .accessibilityIdentifier("docs.rename.field") |
| - Button { model.renameInput = renameText; _ = model.commitRename() } label: { Text("docs.document.rename", bundle: DocsResources.bundle) } |
| + Button { commitPhoneRename() } label: { Text("docs.document.rename", bundle: DocsResources.bundle) } |
| .accessibilityIdentifier("docs.rename.confirm") |
| - Button(role: .cancel) {} label: { Text("native.close.pending.cancel", bundle: DocsResources.bundle) } |
| + Button(role: .cancel) { renameRefusal = nil; model.renameInput = nil } label: { Text("native.close.pending.cancel", bundle: DocsResources.bundle) } |
| + } message: { |
| + // An alert's message is one Text, there or not: empty unless refused. |
| + Text(verbatim: renameRefusal.map { String(localized: String.LocalizationValue($0), bundle: DocsResources.bundle) } ?? "") |
| } |
| .background { |
| if let detail = model.detail, !model.isDraft { |
| @@ -749,6 +754,22 @@ extension DocsWorkspace { |
| .sheet(isPresented: $showingColophon) { DocsColophonView { showingColophon = false } } |
| } |
| + /// Rename from the alert. Refused (a title too long, the right to write |
| + /// gone, the device unable to save), the alert comes back with the |
| + /// title as typed and why (Fable on #180), as the Mac's field stays. |
| + func commitPhoneRename() { |
| + model.renameInput = renameText |
| + if model.commitRename() { renameRefusal = nil; return } |
| + let typed = renameText.trimmingCharacters(in: .whitespacesAndNewlines) |
| + renameRefusal = typed.utf8.count > 1024 ? "native.rename.tooLong" : (model.errorKey ?? "docs.error.generic") |
| + // Once the alert that was answered has gone: one presented during |
| + // its dismissal is dropped. |
| + Task { @MainActor in |
| + try? await Task.sleep(for: .milliseconds(500)) |
| + if renameRefusal != nil { renamingAlert = true } |
| + } |
| + } |
| + |
| /// The Format sheet closed, and what it changed undone at once: a view |
| /// that has gone runs no `onChange`, and a text view attached later |
| /// takes the surface's state (Fable on #180). |
| @@ -770,6 +791,7 @@ extension DocsWorkspace { |
| actions.rename = run { |
| guard model.documentAccess == .writable else { return } |
| renameText = model.detail?.title ?? "" |
| + renameRefusal = nil |
| renamingAlert = true |
| } |
| actions.export = { kind in run { exportRequest = kind }() } |
diff --git a/native/apple/Sources/DocsKit/Resources/ar.lproj/Localizable.strings b/native/apple/Sources/DocsKit/Resources/ar.lproj/Localizable.strings| index 33b9290..e60967e 100644 |
| --- a/native/apple/Sources/DocsKit/Resources/ar.lproj/Localizable.strings |
| +++ b/native/apple/Sources/DocsKit/Resources/ar.lproj/Localizable.strings |
| @@ -269,3 +269,4 @@ |
| "native.format.size.larger" = "أكبر"; |
| "native.back" = "رجوع"; |
| "docs.editor.menu.help" = "المساعدة"; |
| +"native.rename.tooLong" = "هذا العنوان طويل جدًا."; |
diff --git a/native/apple/Sources/DocsKit/Resources/bn.lproj/Localizable.strings b/native/apple/Sources/DocsKit/Resources/bn.lproj/Localizable.strings| index add421c..4a52d77 100644 |
| --- a/native/apple/Sources/DocsKit/Resources/bn.lproj/Localizable.strings |
| +++ b/native/apple/Sources/DocsKit/Resources/bn.lproj/Localizable.strings |
| @@ -269,3 +269,4 @@ |
| "native.format.size.larger" = "বড়"; |
| "native.back" = "ফিরে যান"; |
| "docs.editor.menu.help" = "সহায়তা"; |
| +"native.rename.tooLong" = "শিরোনামটি অনেক বড়।"; |
diff --git a/native/apple/Sources/DocsKit/Resources/en.lproj/Localizable.strings b/native/apple/Sources/DocsKit/Resources/en.lproj/Localizable.strings| index 53c01e6..48ccb39 100644 |
| --- a/native/apple/Sources/DocsKit/Resources/en.lproj/Localizable.strings |
| +++ b/native/apple/Sources/DocsKit/Resources/en.lproj/Localizable.strings |
| @@ -274,3 +274,4 @@ |
| "native.format.size.larger" = "Larger"; |
| "native.back" = "Back"; |
| "docs.editor.menu.help" = "Help"; |
| +"native.rename.tooLong" = "That title is too long."; |
diff --git a/native/apple/Sources/DocsKit/Resources/es.lproj/Localizable.strings b/native/apple/Sources/DocsKit/Resources/es.lproj/Localizable.strings| index e0aa6c6..70cbb2e 100644 |
| --- a/native/apple/Sources/DocsKit/Resources/es.lproj/Localizable.strings |
| +++ b/native/apple/Sources/DocsKit/Resources/es.lproj/Localizable.strings |
| @@ -269,3 +269,4 @@ |
| "native.format.size.larger" = "Más grande"; |
| "native.back" = "Atrás"; |
| "docs.editor.menu.help" = "Ayuda"; |
| +"native.rename.tooLong" = "Ese título es demasiado largo."; |
diff --git a/native/apple/Sources/DocsKit/Resources/ga.lproj/Localizable.strings b/native/apple/Sources/DocsKit/Resources/ga.lproj/Localizable.strings| index ee30b0a..5b8e7c5 100644 |
| --- a/native/apple/Sources/DocsKit/Resources/ga.lproj/Localizable.strings |
| +++ b/native/apple/Sources/DocsKit/Resources/ga.lproj/Localizable.strings |
| @@ -269,3 +269,4 @@ |
| "native.format.size.larger" = "Níos mó"; |
| "native.back" = "Siar"; |
| "docs.editor.menu.help" = "Cabhair"; |
| +"native.rename.tooLong" = "Tá an teideal sin rófhada."; |
diff --git a/native/apple/Sources/DocsKit/Resources/hi.lproj/Localizable.strings b/native/apple/Sources/DocsKit/Resources/hi.lproj/Localizable.strings| index cf2009e..8151477 100644 |
| --- a/native/apple/Sources/DocsKit/Resources/hi.lproj/Localizable.strings |
| +++ b/native/apple/Sources/DocsKit/Resources/hi.lproj/Localizable.strings |
| @@ -269,3 +269,4 @@ |
| "native.format.size.larger" = "बड़ा"; |
| "native.back" = "वापस"; |
| "docs.editor.menu.help" = "सहायता"; |
| +"native.rename.tooLong" = "यह शीर्षक बहुत लंबा है।"; |
diff --git a/native/apple/Sources/DocsKit/Resources/ja.lproj/Localizable.strings b/native/apple/Sources/DocsKit/Resources/ja.lproj/Localizable.strings| index dc624d1..7cc8e83 100644 |
| --- a/native/apple/Sources/DocsKit/Resources/ja.lproj/Localizable.strings |
| +++ b/native/apple/Sources/DocsKit/Resources/ja.lproj/Localizable.strings |
| @@ -269,3 +269,4 @@ |
| "native.format.size.larger" = "大きく"; |
| "native.back" = "戻る"; |
| "docs.editor.menu.help" = "ヘルプ"; |
| +"native.rename.tooLong" = "タイトルが長すぎます。"; |
diff --git a/native/apple/Sources/DocsKit/Resources/pt.lproj/Localizable.strings b/native/apple/Sources/DocsKit/Resources/pt.lproj/Localizable.strings| index 5dcf49b..ab54bc4 100644 |
| --- a/native/apple/Sources/DocsKit/Resources/pt.lproj/Localizable.strings |
| +++ b/native/apple/Sources/DocsKit/Resources/pt.lproj/Localizable.strings |
| @@ -269,3 +269,4 @@ |
| "native.format.size.larger" = "Maior"; |
| "native.back" = "Voltar"; |
| "docs.editor.menu.help" = "Ajuda"; |
| +"native.rename.tooLong" = "Esse título é longo demais."; |
diff --git a/native/apple/Sources/DocsKit/Resources/ru.lproj/Localizable.strings b/native/apple/Sources/DocsKit/Resources/ru.lproj/Localizable.strings| index c9b4392..7c95f46 100644 |
| --- a/native/apple/Sources/DocsKit/Resources/ru.lproj/Localizable.strings |
| +++ b/native/apple/Sources/DocsKit/Resources/ru.lproj/Localizable.strings |
| @@ -269,3 +269,4 @@ |
| "native.format.size.larger" = "Больше"; |
| "native.back" = "Назад"; |
| "docs.editor.menu.help" = "Справка"; |
| +"native.rename.tooLong" = "Это название слишком длинное."; |
diff --git a/native/apple/Sources/DocsKit/Resources/vi.lproj/Localizable.strings b/native/apple/Sources/DocsKit/Resources/vi.lproj/Localizable.strings| index 047d605..45424f0 100644 |
| --- a/native/apple/Sources/DocsKit/Resources/vi.lproj/Localizable.strings |
| +++ b/native/apple/Sources/DocsKit/Resources/vi.lproj/Localizable.strings |
| @@ -269,3 +269,4 @@ |
| "native.format.size.larger" = "Lớn hơn"; |
| "native.back" = "Quay lại"; |
| "docs.editor.menu.help" = "Trợ giúp"; |
| +"native.rename.tooLong" = "Tiêu đề đó quá dài."; |
diff --git a/native/apple/Sources/DocsKit/Resources/yue.lproj/Localizable.strings b/native/apple/Sources/DocsKit/Resources/yue.lproj/Localizable.strings| index 4a0f732..8d1db7f 100644 |
| --- a/native/apple/Sources/DocsKit/Resources/yue.lproj/Localizable.strings |
| +++ b/native/apple/Sources/DocsKit/Resources/yue.lproj/Localizable.strings |
| @@ -269,3 +269,4 @@ |
| "native.format.size.larger" = "大啲"; |
| "native.back" = "返回"; |
| "docs.editor.menu.help" = "說明"; |
| +"native.rename.tooLong" = "呢個標題太長。"; |
diff --git a/native/apple/Sources/DocsKit/Resources/zh-Hans.lproj/Localizable.strings b/native/apple/Sources/DocsKit/Resources/zh-Hans.lproj/Localizable.strings| index 3495588..dee28d1 100644 |
| --- a/native/apple/Sources/DocsKit/Resources/zh-Hans.lproj/Localizable.strings |
| +++ b/native/apple/Sources/DocsKit/Resources/zh-Hans.lproj/Localizable.strings |
| @@ -269,3 +269,4 @@ |
| "native.format.size.larger" = "更大"; |
| "native.back" = "返回"; |
| "docs.editor.menu.help" = "帮助"; |
| +"native.rename.tooLong" = "该标题太长。"; |
diff --git a/native/apple/Tests/DocsKitTests/DocsSubtitleTests.swift b/native/apple/Tests/DocsKitTests/DocsSubtitleTests.swift| index 6042259..d0eab5f 100644 |
| --- a/native/apple/Tests/DocsKitTests/DocsSubtitleTests.swift |
| +++ b/native/apple/Tests/DocsKitTests/DocsSubtitleTests.swift |
| @@ -116,7 +116,7 @@ final class DocsSubtitleTests: XCTestCase { |
| /// S3's keys (the iPhone document, spec §8): every one resolves in all |
| /// twelve tables, and no value is its own key. |
| func testEveryIPhoneDocumentKeyResolvesInEveryLanguage() { |
| - let keys = ["native.more", "native.keyboard.hide", "native.format.size.smaller", "native.format.size.larger", "native.back", |
| + let keys = ["native.more", "native.keyboard.hide", "native.format.size.smaller", "native.format.size.larger", "native.back", "native.rename.tooLong", |
| "docs.editor.menu.help", "native.colophon", "docs.editor.menu.tools.wordcount", "docs.editor.menu.tools.shortcuts", |
| "docs.editor.menu.file.open", "docs.editor.menu.view.paged", "docs.editor.menu.view.infinite", "native.export", |
| "docs.export.pdf.label", "docs.export.markdown.label", "docs.editor.menu.file.print", "docs.document.rename", |
diff --git a/native/ios/UITests/NativeUITests.swift b/native/ios/UITests/NativeUITests.swift| index 5e223d3..62dc427 100644 |
| --- a/native/ios/UITests/NativeUITests.swift |
| +++ b/native/ios/UITests/NativeUITests.swift |
| @@ -346,6 +346,21 @@ final class NativeUITests: XCTestCase { |
| editor.swipeUp() |
| XCTAssertTrue(inline.waitForExistence(timeout: 5), "scrolling past the title folds it") |
| + // A refused rename (a title over the server's 1,024 bytes) brings |
| + // the alert back with the title as typed and why. |
| + app.buttons["docs.more"].tap() |
| + app.buttons["Rename document"].tap() |
| + // An alert's controls reach UIKit without their identifiers. |
| + let field = app.alerts.textFields.firstMatch |
| + XCTAssertTrue(field.waitForExistence(timeout: 5), "Rename opens its alert") |
| + field.typeText(String(repeating: "📄", count: 257)) |
| + app.alerts.buttons["Rename document"].firstMatch.tap() |
| + XCTAssertTrue(app.alerts.staticTexts["That title is too long."].waitForExistence(timeout: 5), "the refusal is shown") |
| + XCTAssertTrue((field.value as? String)?.hasSuffix("📄📄📄") == true, "with the title as typed") |
| + app.alerts.buttons["Cancel"].tap() |
| + XCTAssertTrue(app.alerts.firstMatch.waitForNonExistence(timeout: 5)) |
| + XCTAssertTrue(app.staticTexts["docs.document.title"].exists || inline.exists, "the document is still there") |
| + |
| // Back with the Format sheet up: nothing of it is left behind. |
| app.buttons["docs.format.toggle"].tap() |
| XCTAssertTrue(anything(app, "docs.format.sheet").waitForExistence(timeout: 5)) |