mirror of
https://github.com/atom/atom.git
synced 2026-01-23 22:08:08 -05:00
Pull out bookmarks package into a separate repo
This commit is contained in:
@@ -67,6 +67,7 @@
|
||||
"yaml-tmbundle": "1.0.0",
|
||||
"archive-view": "0.1.0",
|
||||
"autoflow": "0.1.0",
|
||||
"bookmarks": "0.1.0",
|
||||
"bracket-matcher": "0.1.0",
|
||||
"command-logger": "0.1.0",
|
||||
"editor-stats": "0.1.0",
|
||||
|
||||
@@ -1,5 +0,0 @@
|
||||
'.editor':
|
||||
'meta-shift-f2': 'bookmarks:view-all'
|
||||
'meta-f2': 'bookmarks:toggle-bookmark'
|
||||
'f2': 'bookmarks:jump-to-next-bookmark'
|
||||
'shift-f2': 'bookmarks:jump-to-previous-bookmark'
|
||||
@@ -1,77 +0,0 @@
|
||||
path = require 'path'
|
||||
|
||||
{$$} = require 'space-pen'
|
||||
|
||||
SelectList = require 'select-list'
|
||||
|
||||
module.exports =
|
||||
class BookmarksView extends SelectList
|
||||
@viewClass: -> "#{super} bookmarks-view overlay from-top"
|
||||
|
||||
filterKey: 'bookmarkFilterText'
|
||||
|
||||
initialize: ->
|
||||
super
|
||||
|
||||
toggle: ->
|
||||
if @hasParent()
|
||||
@cancel()
|
||||
else
|
||||
@populateBookmarks()
|
||||
@attach()
|
||||
|
||||
getFilterText: (bookmark) ->
|
||||
segments = []
|
||||
bookmarkRow = bookmark.getStartPosition().row
|
||||
segments.push(bookmarkRow)
|
||||
if bufferPath = bookmark.buffer.getPath()
|
||||
segments.push(bufferPath)
|
||||
if lineText = @getLineText(bookmark)
|
||||
segments.push(lineText)
|
||||
segments.join(' ')
|
||||
|
||||
getLineText: (bookmark) ->
|
||||
bookmark.buffer.lineForRow(bookmark.getStartPosition().row)?.trim()
|
||||
|
||||
populateBookmarks: ->
|
||||
markers = []
|
||||
attributes = class: 'bookmark'
|
||||
for buffer in project.getBuffers()
|
||||
for marker in buffer.findMarkers(attributes)
|
||||
marker.bookmarkFilterText = @getFilterText(marker)
|
||||
markers.push(marker)
|
||||
@setArray(markers)
|
||||
|
||||
itemForElement: (bookmark) ->
|
||||
bookmarkRow = bookmark.getStartPosition().row
|
||||
if filePath = bookmark.buffer.getPath()
|
||||
bookmarkLocation = "#{path.basename(filePath)}:#{bookmarkRow + 1}"
|
||||
else
|
||||
bookmarkLocation = "untitled:#{bookmarkRow + 1}"
|
||||
lineText = @getLineText(bookmark)
|
||||
|
||||
$$ ->
|
||||
if lineText
|
||||
@li class: 'bookmark two-lines', =>
|
||||
@div bookmarkLocation, class: 'primary-line'
|
||||
@div lineText, class: 'secondary-line line-text'
|
||||
else
|
||||
@li class: 'bookmark', =>
|
||||
@div bookmarkLocation, class: 'primary-line'
|
||||
|
||||
getEmptyMessage: (itemCount) ->
|
||||
if itemCount is 0
|
||||
'No bookmarks found'
|
||||
else
|
||||
super
|
||||
|
||||
confirmed : (bookmark) ->
|
||||
for editor in rootView.getEditors()
|
||||
if editor.getBuffer() is bookmark.buffer
|
||||
editor.activeEditSession.setSelectedBufferRange(bookmark.getRange(), autoscroll: true)
|
||||
|
||||
attach: ->
|
||||
super
|
||||
|
||||
rootView.append(this)
|
||||
@miniEditor.focus()
|
||||
@@ -1,108 +0,0 @@
|
||||
_ = require 'underscore'
|
||||
shell = require 'shell'
|
||||
|
||||
module.exports =
|
||||
class Bookmarks
|
||||
@activate: ->
|
||||
bookmarksList = null
|
||||
|
||||
rootView.command 'bookmarks:view-all', ->
|
||||
unless bookmarksList?
|
||||
BookmarksListView = require './bookmarks-view'
|
||||
bookmarksList = new BookmarksListView()
|
||||
bookmarksList.toggle()
|
||||
|
||||
rootView.eachEditor (editor) ->
|
||||
new Bookmarks(editor) if editor.attached and editor.getPane()?
|
||||
|
||||
editor: null
|
||||
|
||||
constructor: (@editor) ->
|
||||
@gutter = @editor.gutter
|
||||
@editor.on 'editor:display-updated', @renderBookmarkMarkers
|
||||
|
||||
@editor.command 'bookmarks:toggle-bookmark', @toggleBookmark
|
||||
@editor.command 'bookmarks:jump-to-next-bookmark', @jumpToNextBookmark
|
||||
@editor.command 'bookmarks:jump-to-previous-bookmark', @jumpToPreviousBookmark
|
||||
|
||||
toggleBookmark: =>
|
||||
cursors = @editor.getCursors()
|
||||
for cursor in cursors
|
||||
position = cursor.getBufferPosition()
|
||||
bookmarks = @findBookmarkMarkers(startBufferRow: position.row)
|
||||
|
||||
if bookmarks and bookmarks.length
|
||||
bookmark.destroy() for bookmark in bookmarks
|
||||
else
|
||||
newmark = @createBookmarkMarker(position.row)
|
||||
|
||||
@renderBookmarkMarkers()
|
||||
|
||||
jumpToNextBookmark: =>
|
||||
@jumpToBookmark('getNextBookmark')
|
||||
|
||||
jumpToPreviousBookmark: =>
|
||||
@jumpToBookmark('getPreviousBookmark')
|
||||
|
||||
renderBookmarkMarkers: =>
|
||||
return unless @gutter.isVisible()
|
||||
|
||||
@gutter.find(".line-number.bookmarked").removeClass('bookmarked')
|
||||
|
||||
markers = @findBookmarkMarkers()
|
||||
for marker in markers
|
||||
row = marker.getBufferRange().start.row
|
||||
@gutter.find(".line-number[lineNumber=#{row}]").addClass('bookmarked')
|
||||
|
||||
### Internal ###
|
||||
|
||||
jumpToBookmark: (getBookmarkFunction) =>
|
||||
cursor = @editor.getCursor()
|
||||
position = cursor.getBufferPosition()
|
||||
bookmarkMarker = @[getBookmarkFunction](position.row)
|
||||
|
||||
if bookmarkMarker
|
||||
@editor.activeEditSession.setSelectedBufferRange(bookmarkMarker.getBufferRange(), autoscroll: true)
|
||||
else
|
||||
shell.beep()
|
||||
|
||||
getPreviousBookmark: (bufferRow) ->
|
||||
markers = @findBookmarkMarkers()
|
||||
return null unless markers.length
|
||||
return markers[0] if markers.length == 1
|
||||
|
||||
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()
|
||||
return null unless markers.length
|
||||
return markers[0] if markers.length == 1
|
||||
|
||||
bookmarkIndex = _.sortedIndex markers, bufferRow, (marker) ->
|
||||
if marker.getBufferRange then marker.getBufferRange().start.row else marker
|
||||
|
||||
bookmarkIndex++ if markers[bookmarkIndex] and markers[bookmarkIndex].getBufferRange().start.row == bufferRow
|
||||
bookmarkIndex = 0 if bookmarkIndex >= markers.length
|
||||
|
||||
markers[bookmarkIndex]
|
||||
|
||||
createBookmarkMarker: (bufferRow) ->
|
||||
range = [[bufferRow, 0], [bufferRow, 0]]
|
||||
|
||||
# TODO: use the 'surround' strategy when collaboration is merged in
|
||||
@displayBuffer().markBufferRange(range, @bookmarkMarkerAttributes(invalidationStrategy: 'never'))
|
||||
|
||||
findBookmarkMarkers: (attributes={}) ->
|
||||
@displayBuffer().findMarkers(@bookmarkMarkerAttributes(attributes))
|
||||
|
||||
bookmarkMarkerAttributes: (attributes={}) ->
|
||||
_.extend(attributes, class: 'bookmark', displayBufferId: @displayBuffer().id)
|
||||
|
||||
displayBuffer: ->
|
||||
@editor.activeEditSession.displayBuffer
|
||||
@@ -1,2 +0,0 @@
|
||||
'main': './lib/bookmarks'
|
||||
'description': 'Can mark lines, then jump back to them'
|
||||
@@ -1,173 +0,0 @@
|
||||
RootView = require 'root-view'
|
||||
_ = require 'underscore'
|
||||
shell = require 'shell'
|
||||
|
||||
describe "Bookmarks package", ->
|
||||
[editor, editSession, displayBuffer] = []
|
||||
|
||||
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
|
||||
spyOn(shell, 'beep')
|
||||
|
||||
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
|
||||
|
||||
it "toggles proper classes on proper gutter row", ->
|
||||
editSession.setCursorBufferPosition([3, 10])
|
||||
expect(editor.find('.bookmarked').length).toEqual 0
|
||||
|
||||
editor.trigger 'bookmarks:toggle-bookmark'
|
||||
|
||||
lines = editor.find('.bookmarked')
|
||||
expect(lines.length).toEqual 1
|
||||
expect(lines.attr('linenumber')).toEqual '3'
|
||||
|
||||
editor.trigger 'bookmarks:toggle-bookmark'
|
||||
expect(editor.find('.bookmarked').length).toEqual 0
|
||||
|
||||
describe "jumping between bookmarks", ->
|
||||
|
||||
it "doesnt die when no bookmarks", ->
|
||||
editSession.setCursorBufferPosition([5, 10])
|
||||
|
||||
editor.trigger 'bookmarks:jump-to-next-bookmark'
|
||||
expect(editSession.getCursor().getBufferPosition()).toEqual [5, 10]
|
||||
expect(shell.beep.callCount).toBe 1
|
||||
|
||||
editor.trigger 'bookmarks:jump-to-previous-bookmark'
|
||||
expect(editSession.getCursor().getBufferPosition()).toEqual [5, 10]
|
||||
expect(shell.beep.callCount).toBe 2
|
||||
|
||||
describe "with one bookmark", ->
|
||||
beforeEach ->
|
||||
editSession.setCursorBufferPosition([2, 0])
|
||||
editor.trigger 'bookmarks:toggle-bookmark'
|
||||
|
||||
it "jump-to-next-bookmark jumps to the right place", ->
|
||||
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 [2, 0]
|
||||
|
||||
editSession.setCursorBufferPosition([5, 0])
|
||||
|
||||
editor.trigger 'bookmarks:jump-to-next-bookmark'
|
||||
expect(editSession.getCursor().getBufferPosition()).toEqual [2, 0]
|
||||
|
||||
it "jump-to-previous-bookmark jumps to the right place", ->
|
||||
editSession.setCursorBufferPosition([0, 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 [2, 0]
|
||||
|
||||
editSession.setCursorBufferPosition([5, 0])
|
||||
|
||||
editor.trigger 'bookmarks:jump-to-previous-bookmark'
|
||||
expect(editSession.getCursor().getBufferPosition()).toEqual [2, 0]
|
||||
|
||||
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'
|
||||
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]
|
||||
|
||||
editSession.setCursorBufferPosition([11, 0])
|
||||
|
||||
editor.trigger 'bookmarks:jump-to-next-bookmark'
|
||||
expect(editSession.getCursor().getBufferPosition()).toEqual [2, 0]
|
||||
|
||||
it "jump-to-previous-bookmark 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]
|
||||
|
||||
editSession.setCursorBufferPosition([11, 0])
|
||||
|
||||
editor.trigger 'bookmarks:jump-to-previous-bookmark'
|
||||
expect(editSession.getCursor().getBufferPosition()).toEqual [10, 0]
|
||||
|
||||
describe "browsing bookmarks", ->
|
||||
it "displays a select list of all bookmarks", ->
|
||||
editSession.setCursorBufferPosition([0])
|
||||
editor.trigger 'bookmarks:toggle-bookmark'
|
||||
editSession.setCursorBufferPosition([2])
|
||||
editor.trigger 'bookmarks:toggle-bookmark'
|
||||
editSession.setCursorBufferPosition([4])
|
||||
editor.trigger 'bookmarks:toggle-bookmark'
|
||||
|
||||
rootView.trigger 'bookmarks:view-all'
|
||||
|
||||
bookmarks = rootView.find('.bookmarks-view')
|
||||
expect(bookmarks).toExist()
|
||||
expect(bookmarks.find('.bookmark').length).toBe 3
|
||||
expect(bookmarks.find('.bookmark:eq(0)').find('.primary-line').text()).toBe 'sample.js:1'
|
||||
expect(bookmarks.find('.bookmark:eq(0)').find('.secondary-line').text()).toBe 'var quicksort = function () {'
|
||||
expect(bookmarks.find('.bookmark:eq(1)').find('.primary-line').text()).toBe 'sample.js:3'
|
||||
expect(bookmarks.find('.bookmark:eq(1)').find('.secondary-line').text()).toBe 'if (items.length <= 1) return items;'
|
||||
expect(bookmarks.find('.bookmark:eq(2)').find('.primary-line').text()).toBe 'sample.js:5'
|
||||
expect(bookmarks.find('.bookmark:eq(2)').find('.secondary-line').text()).toBe 'while(items.length > 0) {'
|
||||
|
||||
describe "when a bookmark is selected", ->
|
||||
it "sets the cursor to the location the bookmark", ->
|
||||
editSession.setCursorBufferPosition([8])
|
||||
editor.trigger 'bookmarks:toggle-bookmark'
|
||||
editSession.setCursorBufferPosition([0])
|
||||
|
||||
rootView.trigger 'bookmarks:view-all'
|
||||
|
||||
bookmarks = rootView.find('.bookmarks-view')
|
||||
expect(bookmarks).toExist()
|
||||
bookmarks.find('.bookmark').mousedown().mouseup()
|
||||
expect(editSession.getCursorBufferPosition()).toEqual [8, 0]
|
||||
@@ -1,15 +0,0 @@
|
||||
@import "octicon-utf-codes.less";
|
||||
|
||||
.editor .gutter .line-number.bookmarked:after {
|
||||
color: #09C;
|
||||
content: @bookmark;
|
||||
visibility: visible;
|
||||
}
|
||||
|
||||
.bookmarks-view {
|
||||
.bookmark {
|
||||
.line-text {
|
||||
font-family: monospace;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user