Display line numbers of operations

Group operations by path and place path
above operations
This commit is contained in:
Kevin Sawicki
2013-01-03 12:25:57 -08:00
parent 3e8913f518
commit 2d5fed9243
3 changed files with 27 additions and 21 deletions

View File

@@ -298,8 +298,8 @@ describe "CommandPanel", ->
expect(commandPanel.previewList).toMatchSelector ':focus'
previewItem = commandPanel.previewList.find("li:contains(dir/a):first")
expect(previewItem.find('.path').text()).toBe "dir/a"
expect(previewItem.find('.preview').text()).toBe "aaa bbb"
expect(previewItem.find('.preview > .match').text()).toBe "aaa"
expect(previewItem.next().find('.preview').text()).toBe "aaa bbb"
expect(previewItem.next().find('.preview > .match').text()).toBe "aaa"
rootView.trigger 'command-panel:toggle-preview' # ensure we can close panel without problems
expect(commandPanel).toBeHidden()
@@ -380,28 +380,28 @@ describe "CommandPanel", ->
describe "when move-down and move-up are triggered on the preview list", ->
it "selects the next/previous operation (if there is one), and scrolls the list if needed", ->
rootView.attachToDom()
expect(previewList.find('li:eq(0)')).toHaveClass 'selected'
expect(previewList.find('li.operation:eq(0)')).toHaveClass 'selected'
expect(previewList.getSelectedOperation()).toBe previewList.getOperations()[0]
previewList.trigger 'core:move-up'
expect(previewList.find('li:eq(0)')).toHaveClass 'selected'
expect(previewList.find('li.operation:eq(0)')).toHaveClass 'selected'
expect(previewList.getSelectedOperation()).toBe previewList.getOperations()[0]
previewList.trigger 'core:move-down'
expect(previewList.find('li:eq(1)')).toHaveClass 'selected'
expect(previewList.find('li.operation:eq(1)')).toHaveClass 'selected'
expect(previewList.getSelectedOperation()).toBe previewList.getOperations()[1]
previewList.trigger 'core:move-down'
expect(previewList.find('li:eq(2)')).toHaveClass 'selected'
expect(previewList.find('li.operation:eq(2)')).toHaveClass 'selected'
expect(previewList.getSelectedOperation()).toBe previewList.getOperations()[2]
previewList.trigger 'core:move-up'
expect(previewList.find('li:eq(1)')).toHaveClass 'selected'
expect(previewList.find('li.operation:eq(1)')).toHaveClass 'selected'
expect(previewList.getSelectedOperation()).toBe previewList.getOperations()[1]
_.times previewList.getOperations().length, -> previewList.trigger 'core:move-down'
expect(previewList.find('li:last')).toHaveClass 'selected'
expect(previewList.find("li.operation:last")).toHaveClass 'selected'
expect(previewList.getSelectedOperation()).toBe _.last(previewList.getOperations())
expect(previewList.scrollBottom()).toBeCloseTo previewList.prop('scrollHeight'), -1
@@ -413,10 +413,10 @@ describe "CommandPanel", ->
commandPanel.miniEditor.setText "command"
previewList.focus()
previewList.trigger 'core:move-up'
expect(previewList.find('li:eq(0)')).toHaveClass 'selected'
expect(previewList.find('li.operation:eq(0)')).toHaveClass 'selected'
expect(commandPanel.miniEditor.getText()).toBe 'command'
previewList.trigger 'core:move-down'
expect(previewList.find('li:eq(1)')).toHaveClass 'selected'
expect(previewList.find('li.operation:eq(1)')).toHaveClass 'selected'
expect(commandPanel.miniEditor.getText()).toBe 'command'
describe "when core:confirm is triggered on the preview list", ->
@@ -449,7 +449,7 @@ describe "CommandPanel", ->
spyOn(rootView, 'focus')
operation = previewList.getOperations()[4]
previewList.find('li:eq(4) span').mousedown()
previewList.find('li.operation:eq(4) span').mousedown()
expect(previewList.getSelectedOperation()).toBe operation
editSession = rootView.getActiveEditSession()

View File

@@ -23,7 +23,7 @@ class Operation
match = line[range.start.column...range.end.column]
suffix = line[range.end.column..]
{prefix, suffix, match}
{prefix, suffix, match, range}
destroy: ->
@buffer.release()

View File

@@ -1,6 +1,7 @@
$ = require 'jquery'
{$$$} = require 'space-pen'
ScrollView = require 'scroll-view'
_ = require 'underscore'
module.exports =
class PreviewList extends ScrollView
@@ -30,14 +31,19 @@ class PreviewList extends ScrollView
@operations = operations
@empty()
@html $$$ ->
for operation, index in operations
{prefix, suffix, match} = operation.preview()
@li 'data-index': index, =>
@span operation.getPath(), outlet: "path", class: "path"
@span outlet: "preview", class: "preview", =>
@span prefix
@span match, class: 'match'
@span suffix
operation.index = index for operation, index in operations
operationsByPath = _.groupBy(operations, (operation) -> operation.getPath())
for path, ops of operationsByPath
@li =>
@span path, outlet: "path", class: "path"
for operation in ops
{prefix, suffix, match, range} = operation.preview()
@li 'data-index': operation.index, class: 'operation', =>
@span "#{range.start.row}:", class: "path"
@span outlet: "preview", class: "preview", =>
@span prefix
@span match, class: 'match'
@span suffix
@setSelectedOperationIndex(0)
@show()
@@ -52,7 +58,7 @@ class PreviewList extends ScrollView
index = Math.max(0, index)
index = Math.min(@operations.length - 1, index)
@children(".selected").removeClass('selected')
element = @children("li:eq(#{index})")
element = @children("li.operation:eq(#{index})")
element.addClass('selected')
@scrollToElement(element)
@selectedOperationIndex = index