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