@@ -24,6 +24,7 @@ @interface WPEditorViewController () <HRColorPickerViewControllerDelegate, WPEdi
2424#pragma mark - Properties: Editing
2525@property (nonatomic , assign , readwrite , getter =isEditingEnabled) BOOL editingEnabled;
2626@property (nonatomic , assign , readwrite , getter =isEditing) BOOL editing;
27+ @property (nonatomic , assign , readwrite , getter =isEditingTitle) BOOL editingTitle;
2728@property (nonatomic , assign , readwrite ) BOOL wasEditing;
2829
2930#pragma mark - Properties: Editor View
@@ -174,6 +175,73 @@ - (void)willTransitionToTraitCollection:(UITraitCollection *)newCollection withT
174175 [self .toolbarView setNeedsLayout ];
175176}
176177
178+ #pragma mark - Keyboard shortcuts
179+
180+ - (BOOL )canBecomeFirstResponder
181+ {
182+ return YES ;
183+ }
184+
185+ - (NSArray <UIKeyCommand *> *)keyCommands
186+ {
187+ if (self.isEditingTitle ) {
188+ return @[];
189+ }
190+
191+ // Note that due to an iOS 9 bug, the custom methods for bold and italic
192+ // don't actually get called: http://www.openradar.me/25463955
193+ return @[
194+ [UIKeyCommand keyCommandWithInput: @" B"
195+ modifierFlags: UIKeyModifierCommand
196+ action: @selector (setBold )
197+ discoverabilityTitle: NSLocalizedString(@" Bold" , @" Discoverability title for bold formatting keyboard shortcut." )],
198+ [UIKeyCommand keyCommandWithInput: @" I"
199+ modifierFlags: UIKeyModifierCommand
200+ action: @selector (setItalic )
201+ discoverabilityTitle: NSLocalizedString(@" Italic" , @" Discoverability title for italic formatting keyboard shortcut." )],
202+ [UIKeyCommand keyCommandWithInput: @" D"
203+ modifierFlags: UIKeyModifierCommand|UIKeyModifierAlternate
204+ action: @selector (handleKeyCommandStrikethrough )
205+ discoverabilityTitle: NSLocalizedString(@" Strikethrough" , @" Discoverability title for strikethrough formatting keyboard shortcut." )],
206+ [UIKeyCommand keyCommandWithInput: @" U"
207+ modifierFlags: UIKeyModifierCommand
208+ action: @selector (setUnderline )
209+ discoverabilityTitle: NSLocalizedString(@" Underline" , @" Discoverability title for underline formatting keyboard shortcut." )],
210+ [UIKeyCommand keyCommandWithInput: @" Q"
211+ modifierFlags: UIKeyModifierCommand|UIKeyModifierAlternate
212+ action: @selector (setBlockQuote )
213+ discoverabilityTitle: NSLocalizedString(@" Block Quote" , @" Discoverability title for block quote keyboard shortcut." )],
214+ [UIKeyCommand keyCommandWithInput: @" K"
215+ modifierFlags: UIKeyModifierCommand
216+ action: @selector (linkBarButtonTapped )
217+ discoverabilityTitle: NSLocalizedString(@" Insert Link" , @" Discoverability title for insert link keyboard shortcut." )],
218+ [UIKeyCommand keyCommandWithInput: @" M"
219+ modifierFlags: UIKeyModifierCommand|UIKeyModifierAlternate
220+ action: @selector (didTouchMediaOptions )
221+ discoverabilityTitle: NSLocalizedString(@" Insert Media" , @" Discoverability title for insert media keyboard shortcut." )],
222+ [UIKeyCommand keyCommandWithInput: @" U"
223+ modifierFlags: UIKeyModifierCommand|UIKeyModifierAlternate
224+ action: @selector (setUnorderedList )
225+ discoverabilityTitle: NSLocalizedString(@" Bullet List" , @" Discoverability title for bullet list keyboard shortcut." )],
226+ [UIKeyCommand keyCommandWithInput: @" O"
227+ modifierFlags: UIKeyModifierCommand|UIKeyModifierAlternate
228+ action: @selector (setOrderedList )
229+ discoverabilityTitle: NSLocalizedString(@" Numbered List" , @" Discoverability title for numbered list keyboard shortcut." )],
230+ [UIKeyCommand keyCommandWithInput: @" H"
231+ modifierFlags: UIKeyModifierCommand|UIKeyModifierShift
232+ action: @selector (showHTMLSource: )
233+ discoverabilityTitle: NSLocalizedString(@" Toggle HTML Source " , @" Discoverability title for HTML keyboard shortcut." )]
234+ ];
235+ }
236+
237+ - (void )handleKeyCommandStrikethrough
238+ {
239+ [self setStrikethrough ];
240+
241+ // Ensure that the toolbar button is appropriately selected / deselected
242+ [self .toolbarView toggleSelectionForToolBarItemWithTag: kWPEditorViewControllerElementStrikeThroughBarButton ];
243+ }
244+
177245#pragma mark - Toolbar: helper methods
178246
179247- (void )clearToolbar
@@ -428,24 +496,27 @@ - (void)editorToolbarView:(WPEditorFormatbarView*)editorToolbarView
428496- (void )editorToolbarView : (WPEditorFormatbarView*)editorToolbarView
429497 insertLink : (UIBarButtonItem *)barButtonItem
430498{
431- [self linkBarButtonTapped: (WPEditorToolbarButton *)barButtonItem ];
499+ [self linkBarButtonTapped ];
432500}
433501
434502#pragma mark - Editor Interaction
435503
436504- (void )showHTMLSource : (UIBarButtonItem *)barButtonItem
437- {
505+ {
438506 if ([self .editorView isInVisualMode ]) {
439507 if ([self askOurDelegateShouldDisplaySourceView ]) {
440508 [self .editorView showHTMLSource ];
441- barButtonItem.tintColor = [self barButtonItemSelectedDefaultColor ];
509+ [self .toolbarView toolBarItemWithTag: kWPEditorViewControllerElementShowSourceBarButton
510+ setSelected: YES ];
442511 } else {
443512 // Deselect the HTML button so it is in the proper state
444- [(UIButton *)barButtonItem setSelected: NO ];
513+ [self .toolbarView toolBarItemWithTag: kWPEditorViewControllerElementShowSourceBarButton
514+ setSelected: NO ];
445515 }
446516 } else {
447517 [self .editorView showVisualEditor ];
448- barButtonItem.tintColor = [self .toolbarView itemTintColor ];
518+ [self .toolbarView toolBarItemWithTag: kWPEditorViewControllerElementShowSourceBarButton
519+ setSelected: NO ];
449520 }
450521
451522 [WPAnalytics track: WPAnalyticsStatEditorTappedHTML];
@@ -621,7 +692,7 @@ - (void)redo:(ZSSBarButtonItem *)barButtonItem
621692 [self .editorView redo ];
622693}
623694
624- - (void )linkBarButtonTapped : (WPEditorToolbarButton*) button
695+ - (void )linkBarButtonTapped
625696{
626697 if ([self .editorView isSelectionALink ]) {
627698 [self removeLink ];
@@ -901,9 +972,11 @@ - (void)editorView:(WPEditorView*)editorView
901972{
902973 [self .toolbarView enableToolbarItems: NO shouldShowSourceButton: YES ];
903974 if (field == self.editorView .titleField ) {
975+ self.editingTitle = YES ;
904976 [self .toolbarView enableToolbarItems: NO shouldShowSourceButton: YES ];
905977 [self tellOurDelegateFormatBarStatusHasChanged: NO ];
906978 } else {
979+ self.editingTitle = NO ;
907980 [self .toolbarView enableToolbarItems: YES shouldShowSourceButton: YES ];
908981 [self tellOurDelegateFormatBarStatusHasChanged: YES ];
909982 }
@@ -912,8 +985,10 @@ - (void)editorView:(WPEditorView*)editorView
912985- (void )editorView : (WPEditorView*)editorView sourceFieldFocused : (UIView*)view
913986{
914987 if (view == self.editorView .sourceViewTitleField ) {
988+ self.editingTitle = YES ;
915989 [self .toolbarView enableToolbarItems: NO shouldShowSourceButton: YES ];
916990 } else {
991+ self.editingTitle = NO ;
917992 [self .toolbarView enableToolbarItems: YES shouldShowSourceButton: YES ];
918993 }
919994}
0 commit comments