mirror of
https://github.com/atom/atom.git
synced 2026-01-23 13:58:08 -05:00
add initial bookmark plugin
This commit is contained in:
4
src/packages/bookmarks/keymaps/bookmarks.cson
Normal file
4
src/packages/bookmarks/keymaps/bookmarks.cson
Normal file
@@ -0,0 +1,4 @@
|
||||
'.editor':
|
||||
'meta-f2': 'bookmarks:toggle-bookmark'
|
||||
'f2': 'bookmarks:jump-to-next-bookmark'
|
||||
'shift-f2': 'bookmarks:jump-to-previous-bookmark'
|
||||
54
src/packages/bookmarks/lib/bookmarks-view.coffee
Normal file
54
src/packages/bookmarks/lib/bookmarks-view.coffee
Normal file
@@ -0,0 +1,54 @@
|
||||
_ = require 'underscore'
|
||||
|
||||
module.exports =
|
||||
class BookmarksView
|
||||
@activate: ->
|
||||
rootView.eachEditor (editor) =>
|
||||
new BookmarksView(editor) if editor.attached and editor.getPane()?
|
||||
|
||||
editor: null
|
||||
|
||||
constructor: (@editor) ->
|
||||
@editor.on 'editor:display-updated', @updateBookmarkedLines
|
||||
|
||||
rootView.command 'bookmarks:toggle-bookmark', '.editor', @toggleBookmark
|
||||
rootView.command 'bookmarks:jump-to-next-bookmark', '.editor', @jumpToNextBookmark
|
||||
rootView.command 'bookmarks:jump-to-previous-bookmark', '.editor', @jumpToPreviousBookmark
|
||||
|
||||
toggleBookmark: =>
|
||||
cursors = @editor.getCursors()
|
||||
for cursor in cursors
|
||||
position = cursor.getBufferPosition()
|
||||
bookmarks = @findBookmarkMarkers(position.row)
|
||||
|
||||
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)
|
||||
|
||||
updateBookmarkedLines: =>
|
||||
console.log('update!', @editor)
|
||||
|
||||
jumpToNextBookmark: =>
|
||||
console.log('next bm', @editor)
|
||||
|
||||
jumpToPreviousBookmark: =>
|
||||
console.log('prev bm', @editor)
|
||||
|
||||
|
||||
### Internal ###
|
||||
|
||||
createBookmarkMarker: (bufferRow) ->
|
||||
range = [[bufferRow, 0], [bufferRow, 0]]
|
||||
@displayBuffer().markBufferRange(range, @bookmarkMarkerAttributes(invalidationStrategy: 'never'))
|
||||
|
||||
findBookmarkMarkers: (bufferRow) ->
|
||||
@displayBuffer().findMarkers(@bookmarkMarkerAttributes(startBufferRow: bufferRow))
|
||||
|
||||
bookmarkMarkerAttributes: (attributes={}) ->
|
||||
_.extend(attributes, class: 'bookmark', displayBufferId: @displayBuffer().id)
|
||||
|
||||
displayBuffer: ->
|
||||
@editor.activeEditSession.displayBuffer
|
||||
2
src/packages/bookmarks/package.cson
Normal file
2
src/packages/bookmarks/package.cson
Normal file
@@ -0,0 +1,2 @@
|
||||
'main': './lib/bookmarks-view'
|
||||
'description': 'Can mark lines, then jump back to them'
|
||||
39
src/packages/bookmarks/spec/bookmarks-view-spec.coffee
Normal file
39
src/packages/bookmarks/spec/bookmarks-view-spec.coffee
Normal file
@@ -0,0 +1,39 @@
|
||||
RootView = require 'root-view'
|
||||
_ = require 'underscore'
|
||||
|
||||
fdescribe "Bookmarks package", ->
|
||||
editor = null
|
||||
editSession = null
|
||||
displayBuffer = null
|
||||
|
||||
beforeEach ->
|
||||
window.rootView = new RootView
|
||||
rootView.open('sample.js')
|
||||
rootView.enableKeymap()
|
||||
atom.activatePackage('bookmarks', immediate: true)
|
||||
rootView.attachToDom()
|
||||
editor = rootView.getActiveView()
|
||||
editSession = editor.activeEditSession
|
||||
displayBuffer = editSession.displayBuffer
|
||||
|
||||
|
||||
describe "toggling bookmarks", ->
|
||||
it "creates a marker when toggled", ->
|
||||
editSession.setCursorBufferPosition([3, 10])
|
||||
expect(displayBuffer.findMarkers(class: 'bookmark').length).toEqual 0
|
||||
|
||||
editor.trigger 'bookmarks:toggle-bookmark'
|
||||
|
||||
markers = displayBuffer.findMarkers(class: 'bookmark')
|
||||
expect(markers.length).toEqual 1
|
||||
expect(markers[0].getBufferRange()).toEqual [[3, 0], [3, 0]]
|
||||
|
||||
it "removes marker when toggled", ->
|
||||
editSession.setCursorBufferPosition([3, 10])
|
||||
expect(displayBuffer.findMarkers(class: 'bookmark').length).toEqual 0
|
||||
|
||||
editor.trigger 'bookmarks:toggle-bookmark'
|
||||
expect(displayBuffer.findMarkers(class: 'bookmark').length).toEqual 1
|
||||
|
||||
editor.trigger 'bookmarks:toggle-bookmark'
|
||||
expect(displayBuffer.findMarkers(class: 'bookmark').length).toEqual 0
|
||||
Reference in New Issue
Block a user