diff --git a/src/packages/bookmarks/lib/bookmarks-view.coffee b/src/packages/bookmarks/lib/bookmarks-view.coffee index 1c18a4a02..a7a8c52c4 100644 --- a/src/packages/bookmarks/lib/bookmarks-view.coffee +++ b/src/packages/bookmarks/lib/bookmarks-view.coffee @@ -1,4 +1,5 @@ _ = require 'underscore' +shell = require 'shell' module.exports = class BookmarksView @@ -51,10 +52,16 @@ class BookmarksView cursor = @editor.getCursor() position = cursor.getBufferPosition() bookmarkMarker = @[getBookmarkFunction](position.row) - @editor.activeEditSession.setSelectedBufferRange(bookmarkMarker.getBufferRange(), autoscroll: true) + + if bookmarkMarker + @editor.activeEditSession.setSelectedBufferRange(bookmarkMarker.getBufferRange(), autoscroll: true) + else + shell.beep() getPreviousBookmark: (bufferRow) -> markers = @findBookmarkMarkers() + return null unless markers.length + bookmarkIndex = _.sortedIndex markers, bufferRow, (marker) -> if marker.getBufferRange then marker.getBufferRange().start.row else marker @@ -65,6 +72,8 @@ class BookmarksView getNextBookmark: (bufferRow) -> markers = @findBookmarkMarkers() + return null unless markers.length + bookmarkIndex = _.sortedIndex markers, bufferRow, (marker) -> if marker.getBufferRange then marker.getBufferRange().start.row else marker diff --git a/src/packages/bookmarks/spec/bookmarks-view-spec.coffee b/src/packages/bookmarks/spec/bookmarks-view-spec.coffee index 6ee525b2a..4af7b9b11 100644 --- a/src/packages/bookmarks/spec/bookmarks-view-spec.coffee +++ b/src/packages/bookmarks/spec/bookmarks-view-spec.coffee @@ -51,16 +51,26 @@ describe "Bookmarks package", -> editor.trigger 'bookmarks:toggle-bookmark' expect(editor.find('.bookmarked').length).toEqual 0 - describe "moving between bookmarks", -> - beforeEach -> - editSession.setCursorBufferPosition([2, 0]) - editor.trigger 'bookmarks:toggle-bookmark' + describe "jumping between bookmarks", -> - editSession.setCursorBufferPosition([10, 0]) - editor.trigger 'bookmarks:toggle-bookmark' + it "doesnt die when no bookmarks", -> + editSession.setCursorBufferPosition([5, 10]) - describe "jump-to-next-bookmark", -> - it "finds next bookmark", -> + editor.trigger 'bookmarks:jump-to-next-bookmark' + expect(editSession.getCursor().getBufferPosition()).toEqual [5, 10] + + editor.trigger 'bookmarks:jump-to-previous-bookmark' + expect(editSession.getCursor().getBufferPosition()).toEqual [5, 10] + + describe "with bookmarks", -> + beforeEach -> + editSession.setCursorBufferPosition([2, 0]) + editor.trigger 'bookmarks:toggle-bookmark' + + editSession.setCursorBufferPosition([10, 0]) + editor.trigger 'bookmarks:toggle-bookmark' + + it "jump-to-next-bookmark finds next bookmark", -> editSession.setCursorBufferPosition([0, 0]) editor.trigger 'bookmarks:jump-to-next-bookmark' @@ -72,9 +82,7 @@ describe "Bookmarks package", -> editor.trigger 'bookmarks:jump-to-next-bookmark' expect(editSession.getCursor().getBufferPosition()).toEqual [2, 0] - - describe "jump-to-previous-bookmark", -> - it "finds previous bookmark", -> + it "jump-to-previous-bookmark finds previous bookmark", -> editSession.setCursorBufferPosition([0, 0]) editor.trigger 'bookmarks:jump-to-previous-bookmark'