Handle jumping case when no bookmarks

This commit is contained in:
Ben Ogle
2013-07-22 12:24:21 -07:00
parent 4254efd49e
commit 8881847c61
2 changed files with 29 additions and 12 deletions

View File

@@ -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

View File

@@ -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'