From 5f848f568aa77334e49ad5624049c071a6d66b0e Mon Sep 17 00:00:00 2001 From: Brent Simmons Date: Sun, 29 Oct 2017 11:28:45 -0700 Subject: [PATCH] Begin support for clearing undo commands on sidebar selection change. --- .../Timeline/TimelineViewController.swift | 22 ++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/Evergreen/MainWindow/Timeline/TimelineViewController.swift b/Evergreen/MainWindow/Timeline/TimelineViewController.swift index fed7d89f3..454a14161 100644 --- a/Evergreen/MainWindow/Timeline/TimelineViewController.swift +++ b/Evergreen/MainWindow/Timeline/TimelineViewController.swift @@ -16,6 +16,7 @@ import Account class TimelineViewController: NSViewController, NSTableViewDelegate, NSTableViewDataSource, KeyboardDelegate { @IBOutlet var tableView: TimelineTableView! + private var undoableCommands = [UndoableCommand]() var didRegisterForNotifications = false var fontSize: FontSize = AppDefaults.shared.timelineFontSize { didSet { @@ -126,7 +127,26 @@ class TimelineViewController: NSViewController, NSTableViewDelegate, NSTableView } // MARK: - Actions - + + private func pushUndoableCommand(_ undoableCommand: UndoableCommand) { + + undoableCommands += [undoableCommand] + } + + private func clearUndoableCommands() { + + // When the timeline is reloaded based on a different sidebar selection, + // undoable commands should be dropped — otherwise things like + // Redo Mark All as Read are ambiguous. (Do they apply to the previous articles + // or to the current articles?) + + guard let undoManager = undoManager else { + return + } + undoableCommands.forEach { undoManager.removeAllActions(withTarget: $0) } + undoableCommands = [UndoableCommand]() + } + @objc func openArticleInBrowser(_ sender: AnyObject) { if let link = oneSelectedArticle?.preferredLink {