Commit 2a5ce832 authored by Robert Knight's avatar Robert Knight

Respond to PR feedback

 - Fold `highlightsAt` into `annotationsAt` as it is only used in one
   place

 - Rename `xor` variable to a more obvious name
parent d56bf99e
...@@ -26,8 +26,9 @@ annotationsForSelection = () -> ...@@ -26,8 +26,9 @@ annotationsForSelection = () ->
range = selection.getRangeAt(0) range = selection.getRangeAt(0)
return rangeUtil.itemsForRange(range, (node) -> $(node).data('annotation')) return rangeUtil.itemsForRange(range, (node) -> $(node).data('annotation'))
# Return a list of `<hypothesis-highlight>` elements that contain the given node. # Return the annotations associated with any highlights that contain a given
highlightsAt = (node) -> # DOM node.
annotationsAt = (node) ->
if node.nodeType != Node.ELEMENT_NODE if node.nodeType != Node.ELEMENT_NODE
node = node.parentElement node = node.parentElement
...@@ -38,12 +39,7 @@ highlightsAt = (node) -> ...@@ -38,12 +39,7 @@ highlightsAt = (node) ->
highlights.push(node) highlights.push(node)
node = node.parentElement node = node.parentElement
return highlights return highlights.map((h) => $(h).data('annotation'))
# Return the annotations associated with any highlights that contain a given
# DOM node.
annotationsAt = (node) ->
highlightsAt(event.target).map((h) => $(h).data('annotation'))
# A selector which matches elements added to the DOM by Hypothesis (eg. for # A selector which matches elements added to the DOM by Hypothesis (eg. for
# highlights and annotation UI). # highlights and annotation UI).
...@@ -151,8 +147,8 @@ module.exports = class Guest extends Delegator ...@@ -151,8 +147,8 @@ module.exports = class Guest extends Delegator
addListener 'click', (event) => addListener 'click', (event) =>
annotations = annotationsAt(event.target) annotations = annotationsAt(event.target)
if annotations.length and @visibleHighlights if annotations.length and @visibleHighlights
xor = event.metaKey or event.ctrlKey toggle = event.metaKey or event.ctrlKey
this.selectAnnotations(annotations, xor) this.selectAnnotations(annotations, toggle)
else maybeHideSidebar(event) else maybeHideSidebar(event)
# Allow taps on the document to hide the sidebar as well as clicks, because # Allow taps on the document to hide the sidebar as well as clicks, because
......
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