Commit b48cd8c1 authored by Sean Hammond's avatar Sean Hammond

Clear selection before creating new annotation

Clear any selection that exists in the sidebar before creating a new
annotation. Otherwise the new annotation with its form open for the user
to type in won't be visible because it's not part of the selection.
parent 9274bf1a
......@@ -125,6 +125,12 @@ module.exports = class AppController
$scope.search.query = ''
annotationUI.clearSelectedAnnotations()
$rootScope.$on('beforeAnnotationCreated', (event, data) ->
if data.$highlight
return
$scope.clearSelection()
)
$scope.search =
query: $location.search()['q']
......
......@@ -168,6 +168,30 @@ describe 'AppController', ->
$scope.$broadcast(events.USER_CHANGED, {initialLoad: false})
assert.calledOnce(fakeRoute.reload)
describe 'on "beforeAnnotationCreated"', ->
###*
# It should clear any selection that exists in the sidebar before
# creating a new annotation. Otherwise the new annotation with its
# form open for the user to type in won't be visible because it's
# not part of the selection.
###
it 'calls $scope.clearSelection()', ->
createController()
sandbox.spy($scope, 'clearSelection')
$rootScope.$emit('beforeAnnotationCreated', {})
assert.called($scope.clearSelection)
it 'doesn\'t call $scope.clearSelection() when a highlight is created', ->
createController()
sandbox.spy($scope, 'clearSelection')
$rootScope.$emit('beforeAnnotationCreated', {$highlight: true})
assert.notCalled($scope.clearSelection)
describe 'logout()', ->
it 'prompts the user if there are drafts', ->
fakeDrafts.count.returns(1)
......
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