Jumping to bookmarks works

This commit is contained in:
Ben Ogle
2013-07-22 12:03:22 -07:00
parent 3cb29e1d5c
commit 6968075d38
2 changed files with 63 additions and 4 deletions

View File

@@ -24,18 +24,16 @@ class BookmarksView
if bookmarks and bookmarks.length
bookmark.destroy() for bookmark in bookmarks
console.log('removing mark', position, bookmark)
else
newmark = @createBookmarkMarker(position.row)
console.log('bookmarking', position, newmark)
@renderBookmarkMarkers()
jumpToNextBookmark: =>
console.log('next bm', @editor)
@jumpToBookmark('getNextBookmark')
jumpToPreviousBookmark: =>
console.log('prev bm', @editor)
@jumpToBookmark('getPreviousBookmark')
renderBookmarkMarkers: =>
return unless @gutter.isVisible()
@@ -49,6 +47,32 @@ class BookmarksView
### Internal ###
jumpToBookmark: (getBookmarkFunction) =>
cursor = @editor.getCursor()
position = cursor.getBufferPosition()
bookmarkMarker = @[getBookmarkFunction](position.row)
@editor.activeEditSession.setSelectedBufferRange(bookmarkMarker.getBufferRange(), autoscroll: true)
getPreviousBookmark: (bufferRow) ->
markers = @findBookmarkMarkers()
bookmarkIndex = _.sortedIndex markers, bufferRow, (marker) ->
if marker.getBufferRange then marker.getBufferRange().start.row else marker
bookmarkIndex--
bookmarkIndex = markers.length - 1 if bookmarkIndex < 0
markers[bookmarkIndex]
getNextBookmark: (bufferRow) ->
markers = @findBookmarkMarkers()
bookmarkIndex = _.sortedIndex markers, bufferRow, (marker) ->
if marker.getBufferRange then marker.getBufferRange().start.row else marker
bookmarkIndex++ if markers[bookmarkIndex].getBufferRange().start.row == bufferRow
bookmarkIndex = 0 if bookmarkIndex >= markers.length
markers[bookmarkIndex]
createBookmarkMarker: (bufferRow) ->
range = [[bufferRow, 0], [bufferRow, 0]]
@displayBuffer().markBufferRange(range, @bookmarkMarkerAttributes(invalidationStrategy: 'never'))

View File

@@ -50,3 +50,38 @@ fdescribe "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'
editSession.setCursorBufferPosition([10, 0])
editor.trigger 'bookmarks:toggle-bookmark'
describe "jump-to-next-bookmark", ->
it "finds next bookmark", ->
editSession.setCursorBufferPosition([0, 0])
editor.trigger 'bookmarks:jump-to-next-bookmark'
expect(editSession.getCursor().getBufferPosition()).toEqual [2, 0]
editor.trigger 'bookmarks:jump-to-next-bookmark'
expect(editSession.getCursor().getBufferPosition()).toEqual [10, 0]
editor.trigger 'bookmarks:jump-to-next-bookmark'
expect(editSession.getCursor().getBufferPosition()).toEqual [2, 0]
describe "jump-to-previous-bookmark", ->
it "finds previous bookmark", ->
editSession.setCursorBufferPosition([0, 0])
editor.trigger 'bookmarks:jump-to-previous-bookmark'
expect(editSession.getCursor().getBufferPosition()).toEqual [10, 0]
editor.trigger 'bookmarks:jump-to-previous-bookmark'
expect(editSession.getCursor().getBufferPosition()).toEqual [2, 0]
editor.trigger 'bookmarks:jump-to-previous-bookmark'
expect(editSession.getCursor().getBufferPosition()).toEqual [10, 0]