Commit 801a9ee3 authored by Robert Knight's avatar Robert Knight

Fix "New annotation"/"New page note" label

The button label should be "New annotation" if text is selected or "New
page note otherwise", but it was the wrong way round.

Fixes a regression introduced in #2102
parent ff015542
...@@ -425,7 +425,7 @@ module.exports = class Guest extends Delegator ...@@ -425,7 +425,7 @@ module.exports = class Guest extends Delegator
return return
@selectedRanges = [range] @selectedRanges = [range]
@toolbar?.newAnnotationType = 'note' @toolbar?.newAnnotationType = 'annotation'
{left, top, arrowDirection} = this.adderCtrl.target(focusRect, isBackwards) {left, top, arrowDirection} = this.adderCtrl.target(focusRect, isBackwards)
this.adderCtrl.annotationsForSelection = annotationsForSelection() this.adderCtrl.annotationsForSelection = annotationsForSelection()
...@@ -434,7 +434,7 @@ module.exports = class Guest extends Delegator ...@@ -434,7 +434,7 @@ module.exports = class Guest extends Delegator
_onClearSelection: () -> _onClearSelection: () ->
this.adderCtrl.hide() this.adderCtrl.hide()
@selectedRanges = [] @selectedRanges = []
@toolbar?.newAnnotationType = 'annotation' @toolbar?.newAnnotationType = 'note'
selectAnnotations: (annotations, toggle) -> selectAnnotations: (annotations, toggle) ->
if toggle if toggle
......
...@@ -348,35 +348,38 @@ describe 'Guest', -> ...@@ -348,35 +348,38 @@ describe 'Guest', ->
afterEach -> afterEach ->
container.remove() container.remove()
it 'shows the adder if the selection contains text', -> simulateSelectionWithText = ->
guest = createGuest()
rangeUtil.selectionFocusRect.returns({left: 0, top: 0, width: 5, height: 5}) rangeUtil.selectionFocusRect.returns({left: 0, top: 0, width: 5, height: 5})
FakeAdder::instance.target.returns({ FakeAdder::instance.target.returns({
left: 0, top: 0, arrowDirection: adder.ARROW_POINTING_UP left: 0, top: 0, arrowDirection: adder.ARROW_POINTING_UP
}) })
selections.next({}) selections.next({})
simulateSelectionWithoutText = ->
rangeUtil.selectionFocusRect.returns(null)
selections.next({})
it 'shows the adder if the selection contains text', ->
guest = createGuest()
simulateSelectionWithText()
assert.called FakeAdder::instance.showAt assert.called FakeAdder::instance.showAt
it 'sets the annotations associated with the selection', -> it 'sets the annotations associated with the selection', ->
guest = createGuest() guest = createGuest()
ann = {} ann = {}
$(container).data('annotation', ann) $(container).data('annotation', ann)
rangeUtil.selectionFocusRect.returns({left: 0, top: 0, width: 5, height: 5})
FakeAdder::instance.target.returns({
left: 0, top: 0, arrowDirection: adder.ARROW_POINTING_UP
})
rangeUtil.itemsForRange.callsFake((range, callback) -> rangeUtil.itemsForRange.callsFake((range, callback) ->
[callback(range.startContainer)] [callback(range.startContainer)]
) )
simulateSelectionWithText()
selections.next({})
assert.deepEqual FakeAdder::instance.annotationsForSelection, [ann] assert.deepEqual FakeAdder::instance.annotationsForSelection, [ann]
it 'hides the adder if the selection does not contain text', -> it 'hides the adder if the selection does not contain text', ->
guest = createGuest() guest = createGuest()
rangeUtil.selectionFocusRect.returns(null)
selections.next({}) simulateSelectionWithoutText()
assert.called FakeAdder::instance.hide assert.called FakeAdder::instance.hide
assert.notCalled FakeAdder::instance.showAt assert.notCalled FakeAdder::instance.showAt
...@@ -385,6 +388,22 @@ describe 'Guest', -> ...@@ -385,6 +388,22 @@ describe 'Guest', ->
selections.next(null) selections.next(null)
assert.called FakeAdder::instance.hide assert.called FakeAdder::instance.hide
it "sets the toolbar's `newAnnotationType` to 'annotation' if there is a selection", ->
guest = createGuest()
guest.toolbar = {}
simulateSelectionWithText()
assert.equal guest.toolbar.newAnnotationType, 'annotation'
it "sets the toolbar's `newAnnotationType` to 'note' if the selection is empty", ->
guest = createGuest()
guest.toolbar = {}
simulateSelectionWithoutText()
assert.equal guest.toolbar.newAnnotationType, 'note'
describe 'when adder toolbar buttons are clicked', -> describe 'when adder toolbar buttons are clicked', ->
# TODO - Add tests for "Annotate" and "Highlight" buttons. # TODO - Add tests for "Annotate" and "Highlight" buttons.
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment