diff --git a/assets/scripts/app/views/log.coffee b/assets/scripts/app/views/log.coffee index 631765b3..87bf913b 100644 --- a/assets/scripts/app/views/log.coffee +++ b/assets/scripts/app/views/log.coffee @@ -47,7 +47,7 @@ Travis.reopen console.log 'log view: create engine' if Log.DEBUG @scroll = new Log.Scroll @engine = Log.create(limit: Log.LIMIT, listeners: [@scroll]) - @lineSelector = new Travis.LinesSelector(@$().find('#log'), @scroll, window.location) + @lineSelector = new Travis.LinesSelector(@$().find('#log'), @scroll) @observeParts() observeParts: -> diff --git a/assets/scripts/lib/travis/lines_selector.coffee b/assets/scripts/lib/travis/lines_selector.coffee index e49a456e..ba4242cb 100644 --- a/assets/scripts/lib/travis/lines_selector.coffee +++ b/assets/scripts/lib/travis/lines_selector.coffee @@ -1,10 +1,19 @@ class Travis.LinesSelector + Location: + getHash: -> + window.location.hash + + setHash: (hash) -> + path = "#{window.location.pathname}#{hash}" + window.history.pushState({ path: path }, null, path); + element: null scroll: null location: null last_selected_line: null - constructor: (@element, @scroll, @location) -> + constructor: (@element, @scroll, location) -> + @location = location || @Location Ember.run.scheduleOnce 'afterRender', this, -> @last_selected_line = @getSelectedLines()?.first @highlightLines() @@ -17,7 +26,7 @@ class Travis.LinesSelector false willDestroy: -> - @location.hash = '' + @location.setHash('') loadLineNumbers: (element, multiple) -> @setHashValueWithLine(element, multiple) @@ -40,7 +49,7 @@ class Travis.LinesSelector hash = "#L#{line_number}" @last_selected_line = line_number - @location.hash = hash + @location.setHash(hash) getLineNumberFromElement: (element) -> @element.find('p:visible').index(element) + 1 @@ -49,7 +58,7 @@ class Travis.LinesSelector @element.find('p.highlight').removeClass('highlight') getSelectedLines: -> - if match = @location.hash.match(/#L(\d+)(-L(\d+))?$/) + if match = @location.getHash().match(/#L(\d+)(-L(\d+))?$/) first = match[1] last = match[3] || match[1] {first: first, last: last} diff --git a/assets/scripts/spec/unit/line_selector_spec.coffee b/assets/scripts/spec/unit/line_selector_spec.coffee index cbd4f12b..04e882cf 100644 --- a/assets/scripts/spec/unit/line_selector_spec.coffee +++ b/assets/scripts/spec/unit/line_selector_spec.coffee @@ -1,4 +1,10 @@ -fakeLocation = {} +fakeLocation = { + getHash: -> + @hash || '' + setHash: (hash) -> + @hash = hash +} + fakeScroll = tryScroll: sinon.spy()