From 3cb29e1d5c5f83aded9028f749c888feaba85729 Mon Sep 17 00:00:00 2001 From: Ben Ogle Date: Fri, 19 Jul 2013 21:48:41 -0700 Subject: [PATCH] visually marks bookmarked lines --- .../bookmarks/lib/bookmarks-view.coffee | 21 +++++++++++++------ .../bookmarks/spec/bookmarks-view-spec.coffee | 13 ++++++++++++ .../bookmarks/stylesheets/bookmarks.less | 5 +++++ 3 files changed, 33 insertions(+), 6 deletions(-) create mode 100644 src/packages/bookmarks/stylesheets/bookmarks.less diff --git a/src/packages/bookmarks/lib/bookmarks-view.coffee b/src/packages/bookmarks/lib/bookmarks-view.coffee index eca541702..ed17b626a 100644 --- a/src/packages/bookmarks/lib/bookmarks-view.coffee +++ b/src/packages/bookmarks/lib/bookmarks-view.coffee @@ -9,7 +9,8 @@ class BookmarksView editor: null constructor: (@editor) -> - @editor.on 'editor:display-updated', @updateBookmarkedLines + @gutter = @editor.gutter + @editor.on 'editor:display-updated', @renderBookmarkMarkers rootView.command 'bookmarks:toggle-bookmark', '.editor', @toggleBookmark rootView.command 'bookmarks:jump-to-next-bookmark', '.editor', @jumpToNextBookmark @@ -19,7 +20,7 @@ class BookmarksView cursors = @editor.getCursors() for cursor in cursors position = cursor.getBufferPosition() - bookmarks = @findBookmarkMarkers(position.row) + bookmarks = @findBookmarkMarkers(startBufferRow: position.row) if bookmarks and bookmarks.length bookmark.destroy() for bookmark in bookmarks @@ -28,8 +29,7 @@ class BookmarksView newmark = @createBookmarkMarker(position.row) console.log('bookmarking', position, newmark) - updateBookmarkedLines: => - console.log('update!', @editor) + @renderBookmarkMarkers() jumpToNextBookmark: => console.log('next bm', @editor) @@ -37,6 +37,15 @@ class BookmarksView jumpToPreviousBookmark: => console.log('prev bm', @editor) + 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 ### @@ -44,8 +53,8 @@ class BookmarksView range = [[bufferRow, 0], [bufferRow, 0]] @displayBuffer().markBufferRange(range, @bookmarkMarkerAttributes(invalidationStrategy: 'never')) - findBookmarkMarkers: (bufferRow) -> - @displayBuffer().findMarkers(@bookmarkMarkerAttributes(startBufferRow: bufferRow)) + findBookmarkMarkers: (attributes={}) -> + @displayBuffer().findMarkers(@bookmarkMarkerAttributes(attributes)) bookmarkMarkerAttributes: (attributes={}) -> _.extend(attributes, class: 'bookmark', displayBufferId: @displayBuffer().id) diff --git a/src/packages/bookmarks/spec/bookmarks-view-spec.coffee b/src/packages/bookmarks/spec/bookmarks-view-spec.coffee index 5e4ad3e5f..fa8f1cb96 100644 --- a/src/packages/bookmarks/spec/bookmarks-view-spec.coffee +++ b/src/packages/bookmarks/spec/bookmarks-view-spec.coffee @@ -37,3 +37,16 @@ fdescribe "Bookmarks package", -> 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 diff --git a/src/packages/bookmarks/stylesheets/bookmarks.less b/src/packages/bookmarks/stylesheets/bookmarks.less new file mode 100644 index 000000000..a0dd1189c --- /dev/null +++ b/src/packages/bookmarks/stylesheets/bookmarks.less @@ -0,0 +1,5 @@ +.editor .line-number.bookmarked, +.editor .line-number.bookmarked.cursor-line { + background: #09C; + color: #fff; +}