highlighter: dont select when selection started outside of article
This commit is contained in:
parent
87d353a795
commit
04794fd905
1 changed files with 21 additions and 10 deletions
|
@ -895,7 +895,7 @@ class TicketZoomRef extends App.ControllerContent
|
||||||
# don't go into highlight mode
|
# don't go into highlight mode
|
||||||
# just toggle the selected
|
# just toggle the selected
|
||||||
if !selection.isCollapsed
|
if !selection.isCollapsed
|
||||||
@toggleHighlightAtSelection $(selection.anchorNode).closest @articles.selector
|
@toggleHighlightAtSelection selection, $(selection.anchorNode).closest @articles.selector
|
||||||
else
|
else
|
||||||
# show color
|
# show color
|
||||||
@highlightIcon.css('fill', @colors[@activeColorIndex].color)
|
@highlightIcon.css('fill', @colors[@activeColorIndex].color)
|
||||||
|
@ -919,7 +919,9 @@ class TicketZoomRef extends App.ControllerContent
|
||||||
@setColor()
|
@setColor()
|
||||||
|
|
||||||
onMouseUp: (e) =>
|
onMouseUp: (e) =>
|
||||||
@toggleHighlightAtSelection $(e.currentTarget).closest @articles.selector
|
selection = rangy.getSelection()
|
||||||
|
|
||||||
|
@toggleHighlightAtSelection selection, $(e.currentTarget).closest @articles.selector
|
||||||
|
|
||||||
#
|
#
|
||||||
# toggle Highlight
|
# toggle Highlight
|
||||||
|
@ -930,18 +932,27 @@ class TicketZoomRef extends App.ControllerContent
|
||||||
# - or highlights the selection
|
# - or highlights the selection
|
||||||
# - clears the selection
|
# - clears the selection
|
||||||
|
|
||||||
toggleHighlightAtSelection: (article) ->
|
toggleHighlightAtSelection: (selection, article) ->
|
||||||
selection = rangy.getSelection()
|
|
||||||
|
|
||||||
if @highlighter.selectionOverlapsHighlight selection
|
if @highlighter.selectionOverlapsHighlight selection
|
||||||
@highlighter.unhighlightSelection()
|
@highlighter.unhighlightSelection()
|
||||||
else
|
return @storeHighlights()
|
||||||
@highlighter.highlightSelection @highlightClass,
|
|
||||||
selection: selection
|
|
||||||
containerElementId: article.get(0).id
|
|
||||||
|
|
||||||
# remove selection
|
# selection.anchorNode = element in which the selection started
|
||||||
selection.removeAllRanges()
|
# selection.focusNode = element in which the selection ended
|
||||||
|
#
|
||||||
|
# check if the start node is inside of the article or the article itself
|
||||||
|
startNode = @$(selection.anchorNode)
|
||||||
|
|
||||||
|
if !(article.is(startNode) or article.contents().is(startNode))
|
||||||
|
return selection.removeAllRanges()
|
||||||
|
|
||||||
|
@highlighter.highlightSelection @highlightClass,
|
||||||
|
selection: selection
|
||||||
|
containerElementId: article.get(0).id
|
||||||
|
|
||||||
|
# remove selection
|
||||||
|
selection.removeAllRanges()
|
||||||
|
|
||||||
@storeHighlights()
|
@storeHighlights()
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue