mirror of
https://github.com/atom/atom.git
synced 2026-01-23 13:58:08 -05:00
Rename package main to just Bookmarks
This allows the view that displays the bookmarks for browsing to be called just BookmarksView.
This commit is contained in:
@@ -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 +1,77 @@
|
||||
_ = require 'underscore'
|
||||
shell = require 'shell'
|
||||
path = require 'path'
|
||||
|
||||
{$$} = require 'space-pen'
|
||||
|
||||
SelectList = require 'select-list'
|
||||
|
||||
module.exports =
|
||||
class BookmarksView
|
||||
@activate: ->
|
||||
bookmarksList = null
|
||||
class BookmarksView extends SelectList
|
||||
@viewClass: -> "#{super} bookmarks-view overlay from-top"
|
||||
|
||||
rootView.command 'bookmarks:view-all', ->
|
||||
unless bookmarksList?
|
||||
BookmarksListView = require './bookmarks-list-view'
|
||||
bookmarksList = new BookmarksListView()
|
||||
bookmarksList.toggle()
|
||||
filterKey: 'bookmarkFilterText'
|
||||
|
||||
rootView.eachEditor (editor) =>
|
||||
new BookmarksView(editor) if editor.attached and editor.getPane()?
|
||||
initialize: ->
|
||||
super
|
||||
|
||||
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)
|
||||
toggle: ->
|
||||
if @hasParent()
|
||||
@cancel()
|
||||
else
|
||||
shell.beep()
|
||||
@populateBookmarks()
|
||||
@attach()
|
||||
|
||||
getPreviousBookmark: (bufferRow) ->
|
||||
markers = @findBookmarkMarkers()
|
||||
return null unless markers.length
|
||||
return markers[0] if markers.length == 1
|
||||
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(' ')
|
||||
|
||||
bookmarkIndex = _.sortedIndex markers, bufferRow, (marker) ->
|
||||
if marker.getBufferRange then marker.getBufferRange().start.row else marker
|
||||
getLineText: (bookmark) ->
|
||||
bookmark.buffer.lineForRow(bookmark.getStartPosition().row)?.trim()
|
||||
|
||||
bookmarkIndex--
|
||||
bookmarkIndex = markers.length - 1 if bookmarkIndex < 0
|
||||
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)
|
||||
|
||||
markers[bookmarkIndex]
|
||||
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)
|
||||
|
||||
getNextBookmark: (bufferRow) ->
|
||||
markers = @findBookmarkMarkers()
|
||||
return null unless markers.length
|
||||
return markers[0] if markers.length == 1
|
||||
$$ ->
|
||||
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'
|
||||
|
||||
bookmarkIndex = _.sortedIndex markers, bufferRow, (marker) ->
|
||||
if marker.getBufferRange then marker.getBufferRange().start.row else marker
|
||||
getEmptyMessage: (itemCount) ->
|
||||
if itemCount is 0
|
||||
'No bookmarks found'
|
||||
else
|
||||
super
|
||||
|
||||
bookmarkIndex++ if markers[bookmarkIndex] and markers[bookmarkIndex].getBufferRange().start.row == bufferRow
|
||||
bookmarkIndex = 0 if bookmarkIndex >= markers.length
|
||||
confirmed : (bookmark) ->
|
||||
for editor in rootView.getEditors()
|
||||
if editor.getBuffer() is bookmark.buffer
|
||||
editor.activeEditSession.setSelectedBufferRange(bookmark.getRange(), autoscroll: true)
|
||||
|
||||
markers[bookmarkIndex]
|
||||
attach: ->
|
||||
super
|
||||
|
||||
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
|
||||
rootView.append(this)
|
||||
@miniEditor.focus()
|
||||
|
||||
108
src/packages/bookmarks/lib/bookmarks.coffee
Normal file
108
src/packages/bookmarks/lib/bookmarks.coffee
Normal file
@@ -0,0 +1,108 @@
|
||||
_ = 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 +1,2 @@
|
||||
'main': './lib/bookmarks-view'
|
||||
'main': './lib/bookmarks'
|
||||
'description': 'Can mark lines, then jump back to them'
|
||||
|
||||
Reference in New Issue
Block a user