Skip to content

Commit

Permalink
Make duplicate row use the responder chain
Browse files Browse the repository at this point in the history
  • Loading branch information
vincode-io committed Aug 8, 2024
1 parent 452fecc commit 8b52dab
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 27 deletions.
10 changes: 1 addition & 9 deletions Zavala/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
modifierFlags: [.shift, .command])

let duplicateRowsCommand = UIKeyCommand(title: .duplicateRowControlLabel,
action: #selector(duplicateRowsCommand(_:)),
action: .duplicateCurrentRows,
input: "r",
modifierFlags: [.command, .control])

Expand Down Expand Up @@ -404,10 +404,6 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
}
}

@objc func duplicateRowsCommand(_ sender: Any?) {
mainCoordinator?.duplicateRows()
}

@objc func rowNotesCommand(_ sender: Any?) {
if mainCoordinator?.isCreateRowNotesUnavailable ?? true {
if mainCoordinator?.isEditingTopic ?? false {
Expand Down Expand Up @@ -538,10 +534,6 @@ class AppDelegate: UIResponder, UIApplicationDelegate {

override func validate(_ command: UICommand) {
switch command.action {
case #selector(duplicateRowsCommand(_:)):
if mainCoordinator?.isDuplicateRowsUnavailable ?? true {
command.attributes = .disabled
}
case #selector(rowNotesCommand(_:)):
if mainCoordinator?.isCreateRowNotesUnavailable ?? true {
if mainCoordinator?.isEditingTopic ?? false {
Expand Down
17 changes: 7 additions & 10 deletions Zavala/Editor/EditorViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ extension Selector {
static let addRowBelow = #selector(EditorViewController.addRowBelow(_:))
static let createRowInside = #selector(EditorViewController.createRowInside(_:))
static let createRowOutside = #selector(EditorViewController.createRowOutside(_:))
static let duplicateCurrentRows = #selector(EditorViewController.duplicateCurrentRows(_:))
static let deleteCurrentRows = #selector(EditorViewController.deleteCurrentRows(_:))
static let moveCurrentRowsLeft = #selector(EditorViewController.moveCurrentRowsLeft(_:))
static let moveCurrentRowsRight = #selector(EditorViewController.moveCurrentRowsRight(_:))
Expand Down Expand Up @@ -117,10 +118,6 @@ class EditorViewController: UIViewController, DocumentsActivityItemsConfiguratio
return true
}

var isDuplicateRowsUnavailable: Bool {
return currentRows == nil
}

var isGoBackwardUnavailable: Bool {
return delegate?.editorViewControllerIsGoBackUnavailable ?? true
}
Expand Down Expand Up @@ -616,7 +613,7 @@ class EditorViewController: UIViewController, DocumentsActivityItemsConfiguratio
} else {
return super.canPerformAction(action, withSender: sender)
}
case .addRowAbove, .addRowBelow, .createRowInside, .deleteCurrentRows:
case .addRowAbove, .addRowBelow, .createRowInside, .duplicateCurrentRows, .deleteCurrentRows:
return currentRows != nil
case .createRowOutside:
if let outline, let currentRows, !outline.isCreateRowOutsideUnavailable(rows: currentRows) {
Expand Down Expand Up @@ -1064,11 +1061,6 @@ class EditorViewController: UIViewController, DocumentsActivityItemsConfiguratio

}

func duplicateCurrentRows() {
guard let rows = currentRows else { return }
duplicateRows(rows)
}

func moveCursorToCurrentRowTopic() {
guard let rowShadowTableIndex = currentRows?.last?.shadowTableIndex,
let currentRowViewCell = collectionView.cellForItem(at: IndexPath(row: rowShadowTableIndex, section: adjustedRowsSection)) as? EditorRowViewCell else { return }
Expand Down Expand Up @@ -1273,6 +1265,11 @@ class EditorViewController: UIViewController, DocumentsActivityItemsConfiguratio
createRowOutside(afterRows: rows)
}

@objc func duplicateCurrentRows(_ sender: Any?) {
guard let rows = currentRows else { return }
duplicateRows(rows)
}

@objc func deleteCurrentRows(_ sender: Any?) {
guard let rows = currentRows else { return }
deleteRows(rows)
Expand Down
8 changes: 0 additions & 8 deletions Zavala/MainCoordinator.swift
Original file line number Diff line number Diff line change
Expand Up @@ -59,10 +59,6 @@ extension MainCoordinator {
return editorViewController?.isNotesFiltered ?? false
}

var isDuplicateRowsUnavailable: Bool {
return editorViewController?.isDuplicateRowsUnavailable ?? true
}

var isCreateRowNotesUnavailable: Bool {
return editorViewController?.isCreateRowNotesUnavailable ?? true
}
Expand Down Expand Up @@ -123,10 +119,6 @@ extension MainCoordinator {
return editorViewController?.isEditingNote ?? false
}

func duplicateRows() {
editorViewController?.duplicateCurrentRows()
}

func focusIn() {
editorViewController?.focusIn()
}
Expand Down

0 comments on commit 8b52dab

Please sign in to comment.