Skip to content

Commit

Permalink
Merge pull request #218 from mtgto/customized-keybindings
Browse files Browse the repository at this point in the history
キーバインド設定でカスタマイズされたものを太字で表示する
  • Loading branch information
mtgto authored Sep 29, 2024
2 parents 70096a1 + e7cd064 commit ea8d40a
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 1 deletion.
5 changes: 5 additions & 0 deletions macSKK/KeyBinding.swift
Original file line number Diff line number Diff line change
Expand Up @@ -354,4 +354,9 @@ struct KeyBinding: Identifiable, Hashable {
}
}
}

// デフォルトのキーバインディングと同じキー入力かどうかを返す
var isDefault: Bool {
inputs == Self.defaultKeyBindingSettings.first(where: { $0.action == action })?.inputs
}
}
4 changes: 3 additions & 1 deletion macSKK/Settings/KeyBinding/KeyBindingView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,9 @@ struct KeyBindingView: View {
}
Form {
Table(settingsViewModel.selectedKeyBindingSet.values, selection: $selectingKeyBindingAction) {
TableColumn("Action", value: \.action.localizedAction)
TableColumn("Action") { keyBinding in
Text(keyBinding.action.localizedAction).fontWeight(keyBinding.isDefault ? nil : .bold)
}
TableColumn("Key", value: \.localizedInputs)
}
.contextMenu(forSelectionType: KeyBinding.ID.self) { keyBindingActions in
Expand Down
7 changes: 7 additions & 0 deletions macSKKTests/KeyBindingTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -90,4 +90,11 @@ final class KeyBindingTests: XCTestCase {
XCTAssertTrue(inputEnter.accepts(event: eventOptionEnter))
XCTAssertFalse(inputEnter.accepts(event: eventLeft))
}

func testIsDefault() {
XCTAssertFalse(KeyBinding(.toggleKana, []).isDefault)
XCTAssertTrue(KeyBinding(.toggleKana, [KeyBinding.Input(key: .character("q"), modifierFlags: [])]).isDefault)
XCTAssertFalse(KeyBinding(.toggleKana, [KeyBinding.Input(key: .character("q"), modifierFlags: [.shift])]).isDefault)
XCTAssertFalse(KeyBinding(.toggleKana, [KeyBinding.Input(key: .character("l"), modifierFlags: [])]).isDefault)
}
}

0 comments on commit ea8d40a

Please sign in to comment.