Skip to content

Commit

Permalink
Merge pull request #566 from wordpress-mobile/issue/add_keyboard_shor…
Browse files Browse the repository at this point in the history
…tcuts

Add keyboard shortcuts.
  • Loading branch information
SergioEstevao authored Jun 26, 2017
2 parents b03da22 + 6703286 commit c484c4e
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 1 deletion.
4 changes: 4 additions & 0 deletions Aztec/Classes/GUI/FormatBar/FormatBar.swift
Original file line number Diff line number Diff line change
Expand Up @@ -311,6 +311,10 @@ open class FormatBar: UIView {
@IBAction func handleToggleButtonAction(_ sender: FormatBarItem) {
let shouldExpand = overflowItemsHidden

overflowToolbar(expand: shouldExpand)
}

open func overflowToolbar(expand shouldExpand: Bool) {
setOverflowItemsVisible(shouldExpand)

let direction: OverflowToggleAnimationDirection = shouldExpand ? .vertical : .horizontal
Expand Down
30 changes: 29 additions & 1 deletion Example/Example/EditorDemoController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -346,6 +346,7 @@ class EditorDemoController: UIViewController {
// MARK: - Helpers

@IBAction func toggleEditingMode() {
formatBar.overflowToolbar(expand: true)
editingMode.toggle()
}

Expand Down Expand Up @@ -411,6 +412,26 @@ class EditorDemoController: UIViewController {
toolbar.selectItemsMatchingIdentifiers(identifiers)
}

override var keyCommands: [UIKeyCommand] {
if richTextView.isFirstResponder {
return [ UIKeyCommand(input:"B", modifierFlags: .command, action:#selector(toggleBold), discoverabilityTitle:NSLocalizedString("Bold", comment: "Discoverability title for bold formatting keyboard shortcut.")),
UIKeyCommand(input:"I", modifierFlags: .command, action:#selector(toggleItalic), discoverabilityTitle:NSLocalizedString("Italic", comment: "Discoverability title for italic formatting keyboard shortcut.")),
UIKeyCommand(input:"S", modifierFlags: [.command], action:#selector(toggleStrikethrough), discoverabilityTitle: NSLocalizedString("Strikethrough", comment:"Discoverability title for strikethrough formatting keyboard shortcut.")),
UIKeyCommand(input:"U", modifierFlags: .command, action:#selector(EditorDemoController.toggleUnderline(_:)), discoverabilityTitle: NSLocalizedString("Underline", comment:"Discoverability title for underline formatting keyboard shortcut.")),
UIKeyCommand(input:"Q", modifierFlags:[.command,.alternate], action: #selector(toggleBlockquote), discoverabilityTitle: NSLocalizedString("Block Quote", comment: "Discoverability title for block quote keyboard shortcut.")),
UIKeyCommand(input:"K", modifierFlags:.command, action:#selector(toggleLink), discoverabilityTitle: NSLocalizedString("Insert Link", comment: "Discoverability title for insert link keyboard shortcut.")),
UIKeyCommand(input:"M", modifierFlags:[.command,.alternate], action:#selector(showImagePicker), discoverabilityTitle: NSLocalizedString("Insert Media", comment: "Discoverability title for insert media keyboard shortcut.")),
UIKeyCommand(input:"U", modifierFlags:[.command, .alternate], action:#selector(toggleUnorderedList), discoverabilityTitle:NSLocalizedString("Bullet List", comment: "Discoverability title for bullet list keyboard shortcut.")),
UIKeyCommand(input:"O", modifierFlags:[.command, .alternate], action:#selector(toggleOrderedList), discoverabilityTitle:NSLocalizedString("Numbered List", comment:"Discoverability title for numbered list keyboard shortcut.")),
UIKeyCommand(input:"H", modifierFlags:[.command, .shift], action:#selector(toggleEditingMode), discoverabilityTitle:NSLocalizedString("Toggle HTML Source ", comment: "Discoverability title for HTML keyboard shortcut."))
]
} else if htmlTextView.isFirstResponder {
return [UIKeyCommand(input:"H", modifierFlags:[.command, .shift], action:#selector(toggleEditingMode), discoverabilityTitle:NSLocalizedString("Toggle HTML Source ", comment: "Discoverability title for HTML keyboard shortcut."))
]
}
return []
}


// MARK: - Sample Content

Expand Down Expand Up @@ -636,6 +657,14 @@ extension EditorDemoController : Aztec.FormatBarDelegate {
})
}

func toggleUnorderedList() {
richTextView.toggleUnorderedList(range: richTextView.selectedRange)
}

func toggleOrderedList() {
richTextView.toggleOrderedList(range: richTextView.selectedRange)
}

func showOptionsTableViewControllerWithOptions(_ options: [OptionsTableViewOption],
fromBarItem barItem: FormatBarItem,
selectedRowIndex index: Int?,
Expand Down Expand Up @@ -1169,7 +1198,6 @@ extension EditorDemoController: UIPopoverPresentationControllerDelegate {
}
}


// MARK: - Misc
//
private extension EditorDemoController
Expand Down

0 comments on commit c484c4e

Please sign in to comment.