From ea32608b714866b6a8aac6fa43a910d5a4cc456a Mon Sep 17 00:00:00 2001 From: Oleksandr Glushchenko Date: Thu, 11 Jan 2018 17:03:42 +0200 Subject: [PATCH] #83 --- FSNotes/EditTextView.swift | 1 + FSNotes/NotesTableView.swift | 16 +++++++++++++++- FSNotes/ViewController.swift | 10 ++++++++++ 3 files changed, 26 insertions(+), 1 deletion(-) diff --git a/FSNotes/EditTextView.swift b/FSNotes/EditTextView.swift index 757c3ee56..bc7075d0d 100644 --- a/FSNotes/EditTextView.swift +++ b/FSNotes/EditTextView.swift @@ -148,6 +148,7 @@ class EditTextView: NSTextView { } self.window?.title = note.title + setSelectedRange(NSRange(location: 0, length: 0)) } func removeHighlight() { diff --git a/FSNotes/NotesTableView.swift b/FSNotes/NotesTableView.swift index ff314bdb8..942cd583e 100644 --- a/FSNotes/NotesTableView.swift +++ b/FSNotes/NotesTableView.swift @@ -100,7 +100,7 @@ class NotesTableView: NSTableView, NSTableViewDataSource, override func performKeyEquivalent(with event: NSEvent) -> Bool { if ( - (event.keyCode == 28 || event.keyCode == 46) + [28, 46, 40, 38].contains(event.keyCode) // j, k && event.modifierFlags.contains(NSEvent.ModifierFlags.command)) { return true } @@ -142,4 +142,18 @@ class NotesTableView: NSTableView, NSTableViewDataSource, return nil } + func selectNext() { + selectRow(selectedRow + 1) + } + + func selectPrev() { + selectRow(selectedRow - 1) + } + + func selectRow(_ i: Int) { + if (noteList.indices.contains(i)) { + selectRowIndexes([i], byExtendingSelection: false) + } + } + } diff --git a/FSNotes/ViewController.swift b/FSNotes/ViewController.swift index c87843b37..9fcc08eb8 100644 --- a/FSNotes/ViewController.swift +++ b/FSNotes/ViewController.swift @@ -369,6 +369,16 @@ class ViewController: NSViewController, pin(notesTableView.selectedRowIndexes) } + // Next note (cmd-j) + if (event.keyCode == 38 && event.modifierFlags.contains(NSEvent.ModifierFlags.command)) { + notesTableView.selectNext() + } + + // Prev note (cmd-k) + if (event.keyCode == 40 && event.modifierFlags.contains(NSEvent.ModifierFlags.command)) { + notesTableView.selectPrev() + } + // Open in external editor (cmd-control-e) if ( event.keyCode == 14