store the last selected line and use it as the other end for multiple selection
This commit is contained in:
parent
ff1aad3f03
commit
228afe9a63
|
@ -2,9 +2,11 @@ class Travis.LinesSelector
|
||||||
element: null
|
element: null
|
||||||
scroll: null
|
scroll: null
|
||||||
location: null
|
location: null
|
||||||
|
last_selected_line: null
|
||||||
|
|
||||||
constructor: (@element, @scroll, @location) ->
|
constructor: (@element, @scroll, @location) ->
|
||||||
Ember.run.scheduleOnce 'afterRender', this, ->
|
Ember.run.scheduleOnce 'afterRender', this, ->
|
||||||
|
@last_selected_line = @getSelectedLines()?.first
|
||||||
@highlightLines()
|
@highlightLines()
|
||||||
|
|
||||||
@element.on 'click', 'a', (event) =>
|
@element.on 'click', 'a', (event) =>
|
||||||
|
@ -25,19 +27,19 @@ class Travis.LinesSelector
|
||||||
@removeAllHighlights()
|
@removeAllHighlights()
|
||||||
|
|
||||||
if lines = @getSelectedLines()
|
if lines = @getSelectedLines()
|
||||||
@element.find('p:visible').slice(lines.first, lines.last).addClass('highlight')
|
@element.find('p:visible').slice(lines.first - 1, lines.last).addClass('highlight')
|
||||||
@scroll.tryScroll()
|
@scroll.tryScroll()
|
||||||
|
|
||||||
setHashValueWithLine: (line, multiple) ->
|
setHashValueWithLine: (line, multiple) ->
|
||||||
line_number = @getLineNumberFromElement(line)
|
line_number = @getLineNumberFromElement(line)
|
||||||
|
|
||||||
if !multiple
|
if multiple && @last_selected_line?
|
||||||
hash = "#L#{line_number}"
|
lines = [line_number, @last_selected_line].sort (a,b) -> a - b
|
||||||
else
|
|
||||||
selected_line = @element.find('p:visible.highlight:first')[0]
|
|
||||||
selected_number = @getLineNumberFromElement(selected_line)
|
|
||||||
lines = [line_number, selected_number].sort (a,b) -> a - b
|
|
||||||
hash = "#L#{lines[0]}-L#{lines[1]}"
|
hash = "#L#{lines[0]}-L#{lines[1]}"
|
||||||
|
else
|
||||||
|
hash = "#L#{line_number}"
|
||||||
|
|
||||||
|
@last_selected_line = line_number
|
||||||
@location.hash = hash
|
@location.hash = hash
|
||||||
|
|
||||||
getLineNumberFromElement: (element) ->
|
getLineNumberFromElement: (element) ->
|
||||||
|
@ -48,6 +50,6 @@ class Travis.LinesSelector
|
||||||
|
|
||||||
getSelectedLines: ->
|
getSelectedLines: ->
|
||||||
if match = @location.hash.match(/#L(\d+)(-L(\d+))?$/)
|
if match = @location.hash.match(/#L(\d+)(-L(\d+))?$/)
|
||||||
first = match[1] - 1
|
first = match[1]
|
||||||
last = match[3] || match[1]
|
last = match[3] || match[1]
|
||||||
{first: first, last: last}
|
{first: first, last: last}
|
||||||
|
|
|
@ -57,6 +57,7 @@ test "selects multiple lines", ->
|
||||||
fakeLocation.hash = '#L2'
|
fakeLocation.hash = '#L2'
|
||||||
Ember.run ->
|
Ember.run ->
|
||||||
new Travis.LinesSelector(element, fakeScroll, fakeLocation)
|
new Travis.LinesSelector(element, fakeScroll, fakeLocation)
|
||||||
|
|
||||||
wait().then ->
|
wait().then ->
|
||||||
equal($('#fakeLog p.highlight').length, 1)
|
equal($('#fakeLog p.highlight').length, 1)
|
||||||
|
|
||||||
|
@ -68,3 +69,24 @@ test "selects multiple lines", ->
|
||||||
equal($('#fakeLog p:nth-child(1)').hasClass('highlight'), true)
|
equal($('#fakeLog p:nth-child(1)').hasClass('highlight'), true)
|
||||||
equal($('#fakeLog p:nth-child(2)').hasClass('highlight'), true)
|
equal($('#fakeLog p:nth-child(2)').hasClass('highlight'), true)
|
||||||
equal('#L1-L2', fakeLocation.hash)
|
equal('#L1-L2', fakeLocation.hash)
|
||||||
|
|
||||||
|
test "uses the last selected line as second selection line", ->
|
||||||
|
selector = null
|
||||||
|
Ember.run ->
|
||||||
|
selector = new Travis.LinesSelector(element, fakeScroll, fakeLocation)
|
||||||
|
|
||||||
|
wait().then ->
|
||||||
|
$('#fakeLog p:last a').click()
|
||||||
|
equal($('#fakeLog p.highlight').length, 1)
|
||||||
|
equal(3, selector.last_selected_line)
|
||||||
|
|
||||||
|
event = jQuery.Event('click')
|
||||||
|
event.shiftKey = true
|
||||||
|
$('#fakeLog p:first a').trigger(event)
|
||||||
|
|
||||||
|
equal($('#fakeLog p.highlight').length, 3)
|
||||||
|
equal($('#fakeLog p:nth-child(1)').hasClass('highlight'), true)
|
||||||
|
equal($('#fakeLog p:nth-child(2)').hasClass('highlight'), true)
|
||||||
|
equal($('#fakeLog p:nth-child(3)').hasClass('highlight'), true)
|
||||||
|
equal('#L1-L3', fakeLocation.hash)
|
||||||
|
equal(1, selector.last_selected_line)
|
||||||
|
|
Loading…
Reference in New Issue
Block a user