Skip to content
This repository has been archived by the owner on Dec 15, 2022. It is now read-only.

Commit

Permalink
Add select commands
Browse files Browse the repository at this point in the history
  • Loading branch information
alefragnani committed Oct 12, 2017
1 parent a41ea24 commit e312792
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 0 deletions.
24 changes: 24 additions & 0 deletions lib/bookmarks.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ export default class Bookmarks {
"bookmarks:toggle-bookmark": this.toggleBookmark.bind(this),
"bookmarks:jump-to-next-bookmark": this.jumpToNextBookmark.bind(this),
"bookmarks:jump-to-previous-bookmark": this.jumpToPreviousBookmark.bind(this),
"bookmarks:select-to-next-bookmark": this.selectToNextBookmark.bind(this),
"bookmarks:select-to-previous-bookmark": this.selectToPreviousBookmark.bind(this),
"bookmarks:clear-bookmarks": this.clearBookmarks.bind(this)
}))
this.disposables.add(this.editor.onDidDestroy(this.destroy.bind(this)))
Expand Down Expand Up @@ -82,4 +84,26 @@ export default class Bookmarks {
atom.beep()
}
}

selectToNextBookmark () {
if (this.markerLayer.getMarkerCount() > 0) {
const bufferRow = this.editor.getLastCursor().getMarker().getStartBufferPosition().row
const markers = this.markerLayer.getMarkers().sort((a, b) => a.compare(b))
const bookmarkMarker = markers.find((marker) => marker.getBufferRange().start.row > bufferRow) || markers[0]
this.editor.setSelectedBufferRange([bookmarkMarker.getHeadBufferPosition(), this.editor.getCursorBufferPosition()], {autoscroll: false})
} else {
atom.beep()
}
}

selectToPreviousBookmark () {
if (this.markerLayer.getMarkerCount() > 0) {
const bufferRow = this.editor.getLastCursor().getMarker().getStartBufferPosition().row
const markers = this.markerLayer.getMarkers().sort((a, b) => b.compare(a))
const bookmarkMarker = markers.find((marker) => marker.getBufferRange().start.row < bufferRow) || markers[0]
this.editor.setSelectedBufferRange([this.editor.getCursorBufferPosition(), bookmarkMarker.getHeadBufferPosition()], {autoscroll: false})
} else {
atom.beep()
}
}
}
2 changes: 2 additions & 0 deletions menus/bookmarks.cson
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
{ 'label': 'Toggle Bookmark', 'command': 'bookmarks:toggle-bookmark' }
{ 'label': 'Jump to Next Bookmark', 'command': 'bookmarks:jump-to-next-bookmark' }
{ 'label': 'Jump to Previous Bookmark', 'command': 'bookmarks:jump-to-previous-bookmark' }
{ 'label': 'Select to Next Bookmark', 'command': 'bookmarks:select-to-next-bookmark' }
{ 'label': 'Select to Previous Bookmark', 'command': 'bookmarks:select-to-previous-bookmark' }
]
}
]
Expand Down

0 comments on commit e312792

Please sign in to comment.