Skip to content

Commit

Permalink
#83
Browse files Browse the repository at this point in the history
  • Loading branch information
glushchenko committed Jan 11, 2018
1 parent afe9f63 commit ea32608
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 1 deletion.
1 change: 1 addition & 0 deletions FSNotes/EditTextView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,7 @@ class EditTextView: NSTextView {
}

self.window?.title = note.title
setSelectedRange(NSRange(location: 0, length: 0))
}

func removeHighlight() {
Expand Down
16 changes: 15 additions & 1 deletion FSNotes/NotesTableView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down Expand Up @@ -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)
}
}

}
10 changes: 10 additions & 0 deletions FSNotes/ViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit ea32608

Please sign in to comment.