diff --git a/Sources/ParcelConfig/ConfigCommand.swift b/Sources/ParcelConfig/ConfigCommand.swift index 5755fd91..b50f04c8 100644 --- a/Sources/ParcelConfig/ConfigCommand.swift +++ b/Sources/ParcelConfig/ConfigCommand.swift @@ -96,6 +96,16 @@ public enum ConfigCommand: Hashable, RawRepresentable, CaseIterable, Sendable { } + (1...16).map { .spaceFocus($0) } + public static let bindableCases = allCases.filter(\.isBindable) + + public var isBindable: Bool { + switch self { + case .alwaysFloat, .toggleFocus, .toggleNoPeek, .toggleCleanSpace, .toggleBorders, .toggleHoverFocus, .undo: + false + default: true + } + } + public init?(rawValue: String) { guard let command = Self.allCases.first(where: { $0.rawValue == rawValue }) else { return nil } self = command diff --git a/Sources/ParcelConfig/ConfigJSONSchema.swift b/Sources/ParcelConfig/ConfigJSONSchema.swift index 004291f3..10834bae 100644 --- a/Sources/ParcelConfig/ConfigJSONSchema.swift +++ b/Sources/ParcelConfig/ConfigJSONSchema.swift @@ -24,7 +24,8 @@ public enum ConfigJSONSchema { let bindingValue = binding() let namePattern = "(?![dD][eE][fF][aA][uU][lL][tT]$)[A-Za-z0-9_-]+$(?![\\s\\S])" let entryPattern = "^enter-mode \(namePattern)" - var modeBindings = Dictionary(uniqueKeysWithValues: ConfigCommand.allCases.map { ($0.rawValue, binding($0)) }) + var modeBindings = Dictionary( + uniqueKeysWithValues: ConfigCommand.bindableCases.map { ($0.rawValue, binding($0)) }) modeBindings["exit-mode"] = binding(defaultChord: DefaultKeybindings.modeExit) let modeTable: SchemaValue = .object([ "type": .string("object"), "properties": .object(modeBindings), @@ -35,7 +36,7 @@ public enum ConfigJSONSchema { ), ]) var keybindings: [String: SchemaValue] = [:] - for command in ConfigCommand.allCases { + for command in ConfigCommand.bindableCases { keybindings[command.rawValue] = binding(command, defaultChord: bindings[command]) } var layout = layoutProperties(defaults.layout.global, includeDefaults: true) @@ -217,8 +218,6 @@ public enum ConfigJSONSchema { case .setWindowCap: "Set the active display's tiled window limit to 1–5." case .close: "Ask the focused window to close, preserving the app's confirmation dialogs." case .toggleFullscreen: "Toggle native full screen for the focused window." - case .alwaysFloat, .toggleFocus, .toggleNoPeek, .toggleCleanSpace, .toggleBorders, .toggleHoverFocus, .undo: - "Reserved for a future implementation; configurable but unbound by default." case .layoutTree: "Select the editable tree layout." case .layoutBSP: "Select the balanced binary partition layout." case .layoutAccordion: "Select the accordion layout." @@ -252,7 +251,7 @@ public enum ConfigJSONSchema { "default": choice( ConfigLayout.allCases.map(\.rawValue), defaultValue: includeDefaults ? values.defaultLayout.rawValue : nil), - "when_full": choice( + "when-full": choice( ConfigWhenFull.allCases.map(\.rawValue), defaultValue: includeDefaults ? values.whenFull.rawValue : nil), "ratio": number(ConfigLimits.ratio, defaultValue: includeDefaults ? values.ratio : nil), "gaps": object([ diff --git a/Sources/ParcelConfig/ConfigValidator.swift b/Sources/ParcelConfig/ConfigValidator.swift index 9e5ef033..ef17c702 100644 --- a/Sources/ParcelConfig/ConfigValidator.swift +++ b/Sources/ParcelConfig/ConfigValidator.swift @@ -124,12 +124,12 @@ private struct Validation { mutating func layoutValues( _ values: [String: TOMLNode], path: String, inherited: LayoutValues, allowsDisplays: Bool = false ) -> LayoutValues { - var allowed = ["default", "ratio", "gaps", "reserved", "window-cap", "when_full"] + var allowed = ["default", "ratio", "gaps", "reserved", "window-cap", "when-full"] if allowsDisplays { allowed.append("displays") } unknownKeys(values, allowed: allowed, path: path) var result = inherited result.defaultLayout = choice(values["default"], path: "\(path).default", fallback: result.defaultLayout) - result.whenFull = choice(values["when_full"], path: "\(path).when_full", fallback: result.whenFull) + result.whenFull = choice(values["when-full"], path: "\(path).when-full", fallback: result.whenFull) result.ratio = number( values["ratio"], path: "\(path).ratio", fallback: result.ratio, bounds: ConfigLimits.ratio) result.windowCap = integer( @@ -475,7 +475,13 @@ extension Validation { fileprivate mutating func bindingAction( _ key: String, node: TOMLNode, names: Set, inDefault: Bool ) -> BindingAction? { - if let command = ConfigCommand(rawValue: key), !inDefault { return .command(command) } + if let command = ConfigCommand(rawValue: key), !inDefault { + guard command.isBindable else { + keyFailure(node, BindingModeRules.unavailableCommandMessage(command)) + return nil + } + return .command(command) + } if key == "exit-mode", !inDefault { return .exitMode } if key.hasPrefix("enter-mode ") { let target = String(key.dropFirst("enter-mode ".count)) @@ -584,6 +590,10 @@ extension Validation { result.removeValue(forKey: command) continue } + guard command.isBindable else { + keyFailure(entry, BindingModeRules.unavailableCommandMessage(command)) + continue + } let assignment = examples[command].map { "\(command.tomlKey) = \"\($0.description)\"" } ?? "\(command.tomlKey) = false" @@ -914,6 +924,12 @@ private enum BindingModeRules { table: "Schema", bundle: .module) } + static func unavailableCommandMessage(_ command: ConfigCommand) -> String { + String( + localized: "“\(command.rawValue)” is not available yet and cannot be assigned a shortcut.", + table: "Schema", bundle: .module) + } + static func invalidActionMessage(_ key: String) -> String { String( localized: @@ -946,6 +962,9 @@ private enum BindingModeRules { static func validateAction(_ action: BindingAction, names: Set) throws { switch action { case .command(let command): + guard command.isBindable else { + throw ConfigDiagnostic(message: unavailableCommandMessage(command)) + } guard ConfigCommand(rawValue: command.rawValue) == command else { throw ConfigDiagnostic(message: invalidActionMessage(command.rawValue)) } diff --git a/Sources/ParcelConfig/Resources/Schema.xcstrings b/Sources/ParcelConfig/Resources/Schema.xcstrings index 7242e534..b43b5a05 100644 --- a/Sources/ParcelConfig/Resources/Schema.xcstrings +++ b/Sources/ParcelConfig/Resources/Schema.xcstrings @@ -1,6 +1,7 @@ { "sourceLanguage" : "en", "strings" : { + "“%@” is not available yet and cannot be assigned a shortcut." : { "extractionState" : "manual", "localizations" : { "en" : { "stringUnit" : { "state" : "translated", "value" : "“%@” is not available yet and cannot be assigned a shortcut." } } } }, " (an inherited default)" : { "extractionState" : "manual", "localizations" : { "en" : { "stringUnit" : { "state" : "translated", "value" : " (an inherited default)" } } } }, "Invalid mode name “%@”. Use ASCII letters, digits, underscores, or hyphens; default is reserved." : { "extractionState" : "manual", "localizations" : { "en" : { "stringUnit" : { "state" : "translated", "value" : "Invalid mode name “%@”. Use ASCII letters, digits, underscores, or hyphens; default is reserved." } } } }, "Invalid target in “%@”. Use a valid named mode after enter-mode." : { "extractionState" : "manual", "localizations" : { "en" : { "stringUnit" : { "state" : "translated", "value" : "Invalid target in “%@”. Use a valid named mode after enter-mode." } } } }, diff --git a/Sources/ParcelUI/Settings/SettingsModel.swift b/Sources/ParcelUI/Settings/SettingsModel.swift index d1487ee6..53e6bb0e 100644 --- a/Sources/ParcelUI/Settings/SettingsModel.swift +++ b/Sources/ParcelUI/Settings/SettingsModel.swift @@ -12,7 +12,7 @@ public enum SettingsLayoutField: String, CaseIterable, Sendable { case reservedBottom = "reserved.bottom" case reservedLeft = "reserved.left" case windowCap = "window-cap" - case whenFull = "when_full" + case whenFull = "when-full" } public enum SettingsMotionField: String, CaseIterable, Sendable { diff --git a/Sources/ParcelUI/Settings/SettingsView.swift b/Sources/ParcelUI/Settings/SettingsView.swift index 22bb43ea..03397982 100644 --- a/Sources/ParcelUI/Settings/SettingsView.swift +++ b/Sources/ParcelUI/Settings/SettingsView.swift @@ -311,7 +311,7 @@ public struct SettingsView: View { ForEach(model.shortcutCheckLimitations, id: \.self) { Text($0).font(.caption) } ForEach(model.modeShortcutNotices, id: \.self) { Text($0).textSelection(.enabled) } Button(SettingsText.string("Check shortcut conflicts")) { model.refreshShortcutWarnings() } - ForEach(ConfigCommand.allCases, id: \.self) { command in + ForEach(ConfigCommand.bindableCases, id: \.self) { command in LabeledContent(command.settingsTitle) { Text(model.configuration.keybindings[command]?.description ?? SettingsText.string("Not assigned")) .monospaced() diff --git a/Tests/ParcelConfigTests/BindingModeTests.swift b/Tests/ParcelConfigTests/BindingModeTests.swift index ef1b268e..52a2c3f4 100644 --- a/Tests/ParcelConfigTests/BindingModeTests.swift +++ b/Tests/ParcelConfigTests/BindingModeTests.swift @@ -263,7 +263,7 @@ struct BindingModeTests { #expect(properties["keybindings"]?.patternProperties?[pattern] != nil) } - @Test(arguments: ConfigCommand.allCases) + @Test(arguments: ConfigCommand.bindableCases) func everyCommandWorksInNamedModes(command: ConfigCommand) throws { let value = try configuration("[mode.actions]\n\"\(command.rawValue)\" = \"cmd-f20\"") #expect(value.modes["actions"]?[.command(command)] == KeyChord(modifiers: .cmd, key: .f20)) diff --git a/Tests/ParcelConfigTests/CommandReviewRegressionTests.swift b/Tests/ParcelConfigTests/CommandReviewRegressionTests.swift new file mode 100644 index 00000000..0b88ec80 --- /dev/null +++ b/Tests/ParcelConfigTests/CommandReviewRegressionTests.swift @@ -0,0 +1,51 @@ +import Foundation +import Testing + +@testable import ParcelConfig + +struct ConfigCommandReviewRegressionTests { + private static let reserved: [ConfigCommand] = [ + .alwaysFloat, .toggleFocus, .toggleNoPeek, .toggleCleanSpace, .toggleBorders, .toggleHoverFocus, .undo, + ] + + @Test(arguments: reserved) + func reservedCommandsAreRejectedInNamedModes(command: ConfigCommand) throws { + let document = try TOMLDocument(parsing: "[mode.actions]\n \"\(command.rawValue)\" = \"cmd-f20\"") + let result = ConfigValidator.validate(document) + #expect(result.configuration == nil) + let diagnostic = try #require(result.diagnostics.first) + #expect(diagnostic.severity == .error) + #expect(diagnostic.location.line == 2) + #expect(diagnostic.location.column == 3) + #expect(diagnostic.message == "“\(command.rawValue)” is not available yet and cannot be assigned a shortcut.") + } + + @Test(arguments: reserved, [false, true]) + func directConfigurationCannotRegisterReservedChords(command: ConfigCommand, namedMode: Bool) { + let chord = KeyChord(modifiers: .cmd, key: .f20) + var configuration = ParcelConfiguration.defaults + if namedMode { + configuration.modes = ["actions": [.command(command): chord]] + } else { + configuration.keybindings[command] = chord + } + #expect(throws: ConfigDiagnostic.self) { try configuration.validateBindingModes() } + } + + @Test func bindableInventoryMatchesAvailabilityAndEveryDefault() { + #expect(Set(ConfigCommand.bindableCases) == Set(ConfigCommand.allCases).subtracting(Self.reserved)) + #expect(DefaultKeybindings.bindings().keys.allSatisfy { $0.isBindable }) + } + + @Test func overflowKeyUsesHyphensAndOldSpellingIsNotAnAlias() throws { + let current = ConfigValidator.validate(try TOMLDocument(parsing: "[layout]\nwhen-full='float'")) + #expect(current.configuration?.layout.global.whenFull == .float) + #expect(current.diagnostics.isEmpty) + let old = ConfigValidator.validate(try TOMLDocument(parsing: "[layout]\nwhen_full='float'")) + #expect(old.configuration?.layout.global.whenFull == .stack) + let warning = try #require(old.diagnostics.first) + #expect(warning.severity == .warning) + #expect(warning.location.line == 2) + #expect(warning.message.contains("when-full")) + } +} diff --git a/Tests/ParcelConfigTests/ConfigJSONSchemaTests.swift b/Tests/ParcelConfigTests/ConfigJSONSchemaTests.swift index 75ef611f..d578a747 100644 --- a/Tests/ParcelConfigTests/ConfigJSONSchemaTests.swift +++ b/Tests/ParcelConfigTests/ConfigJSONSchemaTests.swift @@ -159,11 +159,11 @@ struct ConfigJSONSchemaTests { @Test func schemaOverflowBehaviorMatchesModelAndDisplayInheritance() throws { let layout = try schema()["properties"]?["layout"]?["properties"] - let behavior = try #require(layout?["when_full"]) + let behavior = try #require(layout?["when-full"]) #expect(behavior["type"] == .string("string")) #expect(behavior["enum"] == .array(ConfigWhenFull.allCases.map { .string($0.rawValue) })) #expect(behavior["default"] == .string("stack")) - let override = try #require(layout?["displays"]?["additionalProperties"]?["properties"]?["when_full"]) + let override = try #require(layout?["displays"]?["additionalProperties"]?["properties"]?["when-full"]) #expect(override["type"] == behavior["type"]) #expect(override["enum"] == behavior["enum"]) #expect(override["default"] == nil) @@ -179,16 +179,16 @@ struct ConfigJSONSchemaTests { ] let root = try schema() let bindings = root["properties"]?["keybindings"] - for command in commands + reserved { + for command in commands { let property = try #require(bindings?["properties"]?[command.rawValue]) #expect(property["description"]?.string?.isEmpty == false) let mode = root["properties"]?["mode"]?["additionalProperties"]?["properties"]?[command.rawValue] #expect(mode?["description"] == property["description"]) } for command in reserved { - #expect(bindings?["properties"]?[command.rawValue]?["default"] == nil) + #expect(bindings?["properties"]?[command.rawValue] == nil) #expect(bindings?["default"]?[command.rawValue] == nil) - #expect(bindings?["properties"]?[command.rawValue]?["description"]?.string?.contains("Reserved") == true) + #expect(root["properties"]?["mode"]?["additionalProperties"]?["properties"]?[command.rawValue] == nil) } } @@ -220,10 +220,10 @@ struct ConfigJSONSchemaTests { @Test func schemaHasEveryCommand() throws { let bindings = try #require(schema()["properties"]?["keybindings"]?["properties"]?.object) - #expect(Set(bindings.keys) == Set(ConfigCommand.allCases.map(\.rawValue))) + #expect(Set(bindings.keys) == Set(ConfigCommand.bindableCases.map(\.rawValue))) } - @Test(arguments: ConfigCommand.allCases) + @Test(arguments: ConfigCommand.bindableCases) func schemaBindingDefaultsComeFromDefaultTable(_ command: ConfigCommand) throws { let binding = try schema()["properties"]?["keybindings"]?["properties"]?[command.rawValue] let chord = DefaultKeybindings.bindings()[command] @@ -236,10 +236,10 @@ struct ConfigJSONSchemaTests { @Test func schemaNamedModesHaveAllCommandsWithoutInheritedDefaults() throws { let named = try #require(schema()["properties"]?["mode"]?["additionalProperties"]) let properties = try #require(named["properties"]?.object) - #expect(Set(properties.keys) == Set(ConfigCommand.allCases.map(\.rawValue) + ["exit-mode"])) + #expect(Set(properties.keys) == Set(ConfigCommand.bindableCases.map(\.rawValue) + ["exit-mode"])) #expect(named["additionalProperties"] == .bool(false)) #expect(properties["exit-mode"]?["default"] == .string(DefaultKeybindings.modeExit.description)) - for command in ConfigCommand.allCases { + for command in ConfigCommand.bindableCases { #expect(properties[command.rawValue]?["default"] == nil) } let keybindings = try #require(schema()["properties"]?["keybindings"]) @@ -285,7 +285,7 @@ struct ConfigJSONSchemaTests { [ .layoutTree, .layoutBSP, .layoutAccordion, .splitHorizontal, .splitVertical, .joinLeft, .joinRight, .joinUp, .joinDown, .balance, .rotate, .mirrorHorizontal, .mirrorVertical, - ] + ConfigCommand.allCases.filter(\.isSpaceCommand) + ] + ConfigCommand.bindableCases.filter(\.isSpaceCommand) let root = try schema() for command in commands { let property = try #require(root["properties"]?["keybindings"]?["properties"]?[command.rawValue]) diff --git a/Tests/ParcelConfigTests/ConfigValidationTests.swift b/Tests/ParcelConfigTests/ConfigValidationTests.swift index 3faf2e8b..9e3530ae 100644 --- a/Tests/ParcelConfigTests/ConfigValidationTests.swift +++ b/Tests/ParcelConfigTests/ConfigValidationTests.swift @@ -180,10 +180,10 @@ struct ConfigValidationTests { @Test(arguments: ConfigWhenFull.allCases) func overflowBehaviorAcceptsGlobalAndDisplayValues(behavior: ConfigWhenFull) throws { - let global = try configuration("[layout]\nwhen_full = \"\(behavior.rawValue)\"") + let global = try configuration("[layout]\nwhen-full = \"\(behavior.rawValue)\"") #expect(global.layout.global.whenFull == behavior) let id = try #require(UUID(uuidString: displayID)) - let display = try configuration("[layout.displays.\"\(displayID)\"]\nwhen_full = \"\(behavior.rawValue)\"") + let display = try configuration("[layout.displays.\"\(displayID)\"]\nwhen-full = \"\(behavior.rawValue)\"") #expect(display.layout.displays[id]?.whenFull == behavior) #expect(display.layout.global.whenFull == .stack) } @@ -191,14 +191,14 @@ struct ConfigValidationTests { @Test(arguments: ["\"Stack\"", "\"FLOAT\"", "\"unknown\"", "\"\"", "true", "false", "1", "[]", "{}"]) func invalidOverflowBehaviorReportsGlobalAndDisplayValueLocations(value: String) throws { for path in ["layout", "layout.displays.\"\(displayID)\""] { - let document = try TOMLDocument(parsing: "[\(path)]\n when_full = \(value)") + let document = try TOMLDocument(parsing: "[\(path)]\n when-full = \(value)") let result = ConfigValidator.validate(document) #expect(result.configuration == nil) let error = try #require(result.diagnostics.first) #expect(error.severity == .error) #expect(error.location.line == 2) #expect(error.location.column == 15) - #expect(error.message.contains("\(path).when_full")) + #expect(error.message.contains("\(path).when-full")) #expect(error.message.contains("For example:")) #expect(result.diagnostics.count == 1) } @@ -210,12 +210,12 @@ struct ConfigValidationTests { let value = try configuration( """ [layout] - when_full = "float" + when-full = "float" window-cap = 0 [layout.displays."\(displayID)"] ratio = 0.7 [layout.displays."\(otherID.uuidString)"] - when_full = "stack" + when-full = "stack" window-cap = 2 """ ) @@ -227,7 +227,7 @@ struct ConfigValidationTests { @Test func overflowBehaviorSupportsInlineAndDottedKeys() throws { for source in [ - "layout = { when_full = 'float', window-cap = 0 }", "layout.when_full = 'float'\nlayout.window-cap = 0", + "layout = { when-full = 'float', window-cap = 0 }", "layout.when-full = 'float'\nlayout.window-cap = 0", ] { #expect(try configuration(source).layout.global == LayoutValues(windowCap: 0, whenFull: .float)) } @@ -235,16 +235,16 @@ struct ConfigValidationTests { @Test func overflowBehaviorRoundTripPreservesFormattingAndInheritance() throws { let source = - "# café\r\n[layout]\r\nwhen_full = 'stack' # overflow\r\nwindow-cap = 0 # unlimited\r\n[layout.displays.'\(displayID)']\r\nratio = 0.7\r\n" + "# café\r\n[layout]\r\nwhen-full = 'stack' # overflow\r\nwindow-cap = 0 # unlimited\r\n[layout.displays.'\(displayID)']\r\nratio = 0.7\r\n" var document = try TOMLDocument(parsing: source) - try document.setValue(.string("float"), forKey: ["layout", "when_full"]) + try document.setValue(.string("float"), forKey: ["layout", "when-full"]) #expect(document.render() == source.replacingOccurrences(of: "'stack'", with: "\"float\"")) let value = try configuration(document.render()) let id = try #require(UUID(uuidString: displayID)) #expect(value.layout.global.whenFull == .float) #expect(value.layout.global.windowCap == 0) #expect(value.layout.values(for: id).whenFull == .float) - try document.setValue(.string("stack"), forKey: ["layout", "displays", displayID, "when_full"]) + try document.setValue(.string("stack"), forKey: ["layout", "displays", displayID, "when-full"]) #expect(try configuration(document.render()).layout.values(for: id).whenFull == .stack) #expect(try configuration(document.render()).layout.global.whenFull == .float) } @@ -812,7 +812,7 @@ extension ConfigValidationTests { #expect(try configuration("[keybindings]\n\"\(command.rawValue)\" = false").keybindings[command] == nil) } - @Test(arguments: ConfigCommand.allCases) + @Test(arguments: ConfigCommand.bindableCases) func everyCommandCanBeOverridden(_ command: ConfigCommand) throws { #expect( try configuration("[keybindings]\n\"\(command.rawValue)\" = \"cmd-f20\"").keybindings[command] diff --git a/Tests/ParcelConfigTests/KeyChordTests.swift b/Tests/ParcelConfigTests/KeyChordTests.swift index 5c77865a..641c55b8 100644 --- a/Tests/ParcelConfigTests/KeyChordTests.swift +++ b/Tests/ParcelConfigTests/KeyChordTests.swift @@ -287,17 +287,22 @@ struct DefaultKeybindingsTests { #expect(ConfigCommand(rawValue: rawValue) == nil) } - @Test func reservedCommandsAreConfigurableButHaveNoDefaultShortcut() throws { + @Test func reservedCommandsCannotBeBoundAndHaveNoDefaultShortcut() throws { let commands: [ConfigCommand] = [ .alwaysFloat, .toggleFocus, .toggleNoPeek, .toggleCleanSpace, .toggleBorders, .toggleHoverFocus, .undo, ] for command in commands { #expect(ConfigCommand.allCases.contains(command)) + #expect(!ConfigCommand.bindableCases.contains(command)) #expect(DefaultKeybindings.bindings()[command] == nil) let source = "[keybindings]\n\"\(command.rawValue)\" = \"cmd-f20\"" let result = ConfigValidator.validate(try TOMLDocument(parsing: source)) - #expect(result.diagnostics.isEmpty) - #expect(result.configuration?.keybindings[command] == KeyChord(modifiers: .cmd, key: .f20)) + #expect(result.configuration == nil) + let diagnostic = try #require(result.diagnostics.first) + #expect(diagnostic.severity == .error) + #expect(diagnostic.location.line == 2) + #expect(diagnostic.location.column == 1) + #expect(diagnostic.message.contains("not available yet")) } } diff --git a/Tests/ParcelUITests/ConfigLayoutSettingsTests.swift b/Tests/ParcelUITests/ConfigLayoutSettingsTests.swift index cd52e1f5..e9c78219 100644 --- a/Tests/ParcelUITests/ConfigLayoutSettingsTests.swift +++ b/Tests/ParcelUITests/ConfigLayoutSettingsTests.swift @@ -29,7 +29,7 @@ struct ConfigLayoutSettingsTests { let key = "a1b2c3d4-1234-5678-9abc-0123456789ab" let id = try #require(UUID(uuidString: key)) let source = - "# café\r\n[layout]\r\nwhen_full = 'stack' # overflow\r\nwindow-cap = 0 # unlimited\r\n[layout.displays.'\(key)'] # screen\r\nratio = 0.7\r\n" + "# café\r\n[layout]\r\nwhen-full = 'stack' # overflow\r\nwindow-cap = 0 # unlimited\r\n[layout.displays.'\(key)'] # screen\r\nratio = 0.7\r\n" var document = try TOMLDocument(parsing: source) try SettingsDocumentEditor.apply(.value(.layout(.whenFull), .string("float")), to: &document) #expect(document.render() == source.replacingOccurrences(of: "'stack'", with: "\"float\"")) @@ -44,14 +44,14 @@ struct ConfigLayoutSettingsTests { let key = "a1b2c3d4-1234-5678-9abc-0123456789ab" let id = try #require(UUID(uuidString: key)) var document = try TOMLDocument( - parsing: "[layout]\nwhen_full='float'\nwindow-cap=0\n[layout.displays.'\(key)'] # screen\nratio=0.7\n") + parsing: "[layout]\nwhen-full='float'\nwindow-cap=0\n[layout.displays.'\(key)'] # screen\nratio=0.7\n") try SettingsDocumentEditor.apply(.value(.layout(.whenFull, display: id), .string("stack")), to: &document) let configuration = try SettingsDocumentEditor.validate(document) #expect(configuration.layout.global == LayoutValues(windowCap: 0, whenFull: .float)) #expect(configuration.layout.values(for: id) == LayoutValues(ratio: 0.7, windowCap: 0, whenFull: .stack)) #expect(document.source.contains("[layout.displays.'\(key)'] # screen")) #expect(document.node(forKey: ["layout", "displays", id.uuidString]) == nil) - #expect(document.node(forKey: ["layout", "displays", key, "when_full"])?.value == .string("stack")) + #expect(document.node(forKey: ["layout", "displays", key, "when-full"])?.value == .string("stack")) } @Test func firstOverflowEditCreatesOnlyTheRequestedDisplayOverride() throws { @@ -66,7 +66,7 @@ struct ConfigLayoutSettingsTests { Issue.record("The display override must be a table.") return } - #expect(Set(fields.keys) == ["when_full"]) + #expect(Set(fields.keys) == ["when-full"]) #expect(document.source.contains("# defaults")) } @@ -115,7 +115,7 @@ struct ConfigLayoutSettingsTests { do { try FileManager.default.removeItem(at: directory) } catch { Issue.record(error) } } let file = directory.appendingPathComponent("parcel.toml") - let source = "# unchanged\n[layout]\nwhen_full='stack'\n" + let source = "# unchanged\n[layout]\nwhen-full='stack'\n" try Data(source.utf8).write(to: file) #expect(throws: SettingsFailure.self) { try SettingsFileEditor.commit(.value(.layout(.whenFull), value), fileURL: file, expectedSource: source) diff --git a/Tests/ParcelUITests/SettingsTests.swift b/Tests/ParcelUITests/SettingsTests.swift index 0cb9de2e..963e693a 100644 --- a/Tests/ParcelUITests/SettingsTests.swift +++ b/Tests/ParcelUITests/SettingsTests.swift @@ -175,7 +175,19 @@ struct SettingsTests { } } - @Test(arguments: ConfigCommand.allCases) + @Test(arguments: ConfigCommand.allCases.filter { !$0.isBindable }) + func unavailableCommandsCannotBeRecorded(command: ConfigCommand) async throws { + try await withSettings(source: "") { model, file in + let chord = KeyChord(modifiers: [.cmd, .fn], key: .keypad9) + await #expect(throws: SettingsFailure.self) { try await model.setShortcut(chord, for: command) } + #expect(model.configuration.keybindings[command] == nil) + #expect(model.error?.message.contains("not available yet") == true) + let saved = try file.read() + #expect(saved.isEmpty) + } + } + + @Test(arguments: ConfigCommand.bindableCases) func everyCommandSupportsRecordingAndClearing(command: ConfigCommand) async throws { try await withSettings(source: "") { model, file in let chord = KeyChord(modifiers: [.cmd, .fn], key: .keypad9) diff --git a/docs/parcel.schema.json b/docs/parcel.schema.json index 71295d9e..55c8fa90 100644 --- a/docs/parcel.schema.json +++ b/docs/parcel.schema.json @@ -170,19 +170,6 @@ } }, "properties" : { - "always-float" : { - "description" : "Reserved for a future implementation; configurable but unbound by default.", - "oneOf" : [ - { - "format" : "parcel-key-chord", - "minLength" : 1, - "type" : "string" - }, - { - "const" : false - } - ] - }, "balance" : { "default" : "ctrl-alt-f9", "description" : "Balance split proportions without changing the tree topology.", @@ -197,32 +184,6 @@ } ] }, - "borders-toggle" : { - "description" : "Reserved for a future implementation; configurable but unbound by default.", - "oneOf" : [ - { - "format" : "parcel-key-chord", - "minLength" : 1, - "type" : "string" - }, - { - "const" : false - } - ] - }, - "clean-space-toggle" : { - "description" : "Reserved for a future implementation; configurable but unbound by default.", - "oneOf" : [ - { - "format" : "parcel-key-chord", - "minLength" : 1, - "type" : "string" - }, - { - "const" : false - } - ] - }, "close" : { "default" : "ctrl-alt-delete", "description" : "Ask the focused window to close, preserving the app's confirmation dialogs.", @@ -341,19 +302,6 @@ } ] }, - "focus-toggle" : { - "description" : "Reserved for a future implementation; configurable but unbound by default.", - "oneOf" : [ - { - "format" : "parcel-key-chord", - "minLength" : 1, - "type" : "string" - }, - { - "const" : false - } - ] - }, "focus-up" : { "default" : "ctrl-alt-up", "oneOf" : [ @@ -367,19 +315,6 @@ } ] }, - "hover-focus-toggle" : { - "description" : "Reserved for a future implementation; configurable but unbound by default.", - "oneOf" : [ - { - "format" : "parcel-key-chord", - "minLength" : 1, - "type" : "string" - }, - { - "const" : false - } - ] - }, "join-down" : { "default" : "ctrl-alt-f8", "description" : "Reinsert the focused stack beside its neighbor in this direction.", @@ -624,19 +559,6 @@ } ] }, - "no-peek-toggle" : { - "description" : "Reserved for a future implementation; configurable but unbound by default.", - "oneOf" : [ - { - "format" : "parcel-key-chord", - "minLength" : 1, - "type" : "string" - }, - { - "const" : false - } - ] - }, "open-settings" : { "default" : "ctrl-alt-,", "oneOf" : [ @@ -1449,19 +1371,6 @@ } ] }, - "undo" : { - "description" : "Reserved for a future implementation; configurable but unbound by default.", - "oneOf" : [ - { - "format" : "parcel-key-chord", - "minLength" : 1, - "type" : "string" - }, - { - "const" : false - } - ] - }, "unstack" : { "default" : "ctrl-alt-;", "description" : "Separate the focused window from its stack.", @@ -2064,7 +1973,7 @@ }, "type" : "object" }, - "when_full" : { + "when-full" : { "enum" : [ "stack", "float" @@ -2143,7 +2052,7 @@ }, "type" : "object" }, - "when_full" : { + "when-full" : { "default" : "stack", "enum" : [ "stack", @@ -2180,19 +2089,6 @@ } }, "properties" : { - "always-float" : { - "description" : "Reserved for a future implementation; configurable but unbound by default.", - "oneOf" : [ - { - "format" : "parcel-key-chord", - "minLength" : 1, - "type" : "string" - }, - { - "const" : false - } - ] - }, "balance" : { "description" : "Balance split proportions without changing the tree topology.", "oneOf" : [ @@ -2206,32 +2102,6 @@ } ] }, - "borders-toggle" : { - "description" : "Reserved for a future implementation; configurable but unbound by default.", - "oneOf" : [ - { - "format" : "parcel-key-chord", - "minLength" : 1, - "type" : "string" - }, - { - "const" : false - } - ] - }, - "clean-space-toggle" : { - "description" : "Reserved for a future implementation; configurable but unbound by default.", - "oneOf" : [ - { - "format" : "parcel-key-chord", - "minLength" : 1, - "type" : "string" - }, - { - "const" : false - } - ] - }, "close" : { "description" : "Ask the focused window to close, preserving the app's confirmation dialogs.", "oneOf" : [ @@ -2354,19 +2224,6 @@ } ] }, - "focus-toggle" : { - "description" : "Reserved for a future implementation; configurable but unbound by default.", - "oneOf" : [ - { - "format" : "parcel-key-chord", - "minLength" : 1, - "type" : "string" - }, - { - "const" : false - } - ] - }, "focus-up" : { "oneOf" : [ { @@ -2379,19 +2236,6 @@ } ] }, - "hover-focus-toggle" : { - "description" : "Reserved for a future implementation; configurable but unbound by default.", - "oneOf" : [ - { - "format" : "parcel-key-chord", - "minLength" : 1, - "type" : "string" - }, - { - "const" : false - } - ] - }, "join-down" : { "description" : "Reinsert the focused stack beside its neighbor in this direction.", "oneOf" : [ @@ -2618,19 +2462,6 @@ } ] }, - "no-peek-toggle" : { - "description" : "Reserved for a future implementation; configurable but unbound by default.", - "oneOf" : [ - { - "format" : "parcel-key-chord", - "minLength" : 1, - "type" : "string" - }, - { - "const" : false - } - ] - }, "open-settings" : { "oneOf" : [ { @@ -3416,19 +3247,6 @@ } ] }, - "undo" : { - "description" : "Reserved for a future implementation; configurable but unbound by default.", - "oneOf" : [ - { - "format" : "parcel-key-chord", - "minLength" : 1, - "type" : "string" - }, - { - "const" : false - } - ] - }, "unstack" : { "description" : "Separate the focused window from its stack.", "oneOf" : [