mirror of
https://github.com/atom/atom.git
synced 2026-01-23 05:48:10 -05:00
Add select list to browse and open bookmarks from
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
'.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'
|
||||
|
||||
77
src/packages/bookmarks/lib/bookmarks-list-view.coffee
Normal file
77
src/packages/bookmarks/lib/bookmarks-list-view.coffee
Normal file
@@ -0,0 +1,77 @@
|
||||
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()
|
||||
@@ -4,6 +4,14 @@ shell = require 'shell'
|
||||
module.exports =
|
||||
class BookmarksView
|
||||
@activate: ->
|
||||
bookmarksList = null
|
||||
|
||||
rootView.command 'bookmarks:view-all', ->
|
||||
unless bookmarksList?
|
||||
BookmarksListView = require './bookmarks-list-view'
|
||||
bookmarksList = new BookmarksListView()
|
||||
bookmarksList.toggle()
|
||||
|
||||
rootView.eachEditor (editor) =>
|
||||
new BookmarksView(editor) if editor.attached and editor.getPane()?
|
||||
|
||||
|
||||
@@ -133,3 +133,37 @@ describe "Bookmarks package", ->
|
||||
|
||||
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]
|
||||
|
||||
@@ -3,3 +3,11 @@
|
||||
content: '\f07b';
|
||||
visibility: visible;
|
||||
}
|
||||
|
||||
.bookmarks-view {
|
||||
.bookmark {
|
||||
.line-text {
|
||||
font-family: monospace;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user