Skip to content

Commit

Permalink
Fix toggling Outline and Edit modes using the ESC key for iOS SDK 17
Browse files Browse the repository at this point in the history
  • Loading branch information
vincode-io committed Aug 10, 2024
1 parent 473e65e commit 26e4fd6
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions Zavala/Editor/EditorViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,11 @@ class EditorViewController: UIViewController, DocumentsActivityItemsConfiguratio
commandReturn.wantsPriorityOverSystemBehavior = true
keyCommands.append(commandReturn)
}

let esc = UIKeyCommand(action: #selector(toggleMode), input: UIKeyCommand.inputEscape)

// Beginning with SDK iOS 17, this no longer gets called when in Outline Mode and are trying to enter Edit mode.
// We handle that in pressesBegan. However, when in Edit mode and you hit ESC, pressesBegan doesn't get called
// for some strange reason. So we have to handle that scenario here.
let esc = UIKeyCommand(action: #selector(enterOutlineMode), input: UIKeyCommand.inputEscape)
esc.wantsPriorityOverSystemBehavior = true
keyCommands.append(esc)

Expand Down Expand Up @@ -1158,10 +1161,9 @@ class EditorViewController: UIViewController, DocumentsActivityItemsConfiguratio
CursorCoordinates.clearLastKnownCoordinates()
}

@objc func toggleMode() {
@objc func enterOutlineMode() {
guard let topicView = currentTextView as? EditorRowTopicTextView,
let shadowTableIndex = topicView.row?.shadowTableIndex else {
moveCursorToCurrentRowTopic()
return
}

Expand Down Expand Up @@ -2334,7 +2336,8 @@ private extension EditorViewController {
cell.moveToTopicStart()
}
}
case (.keyboardRightArrow, key.modifierFlags.subtracting([.alphaShift, .numericPad]).isEmpty):
case (.keyboardEscape, key.modifierFlags.subtracting([.alphaShift, .numericPad]).isEmpty),
(.keyboardRightArrow, key.modifierFlags.subtracting([.alphaShift, .numericPad]).isEmpty):
if let last = collectionView.indexPathsForSelectedItems?.sorted().last {
if let cell = collectionView.cellForItem(at: last) as? EditorRowViewCell {
cell.moveToTopicEnd()
Expand Down

0 comments on commit 26e4fd6

Please sign in to comment.