mirror of
https://github.com/atom/atom.git
synced 2026-01-23 13:58:08 -05:00
Jumping to bookmarks works
This commit is contained in:
@@ -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'))
|
||||
|
||||
@@ -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]
|
||||
|
||||
Reference in New Issue
Block a user