From 7fe313552636cb657aaad0ddf98c8cb88c6086fc Mon Sep 17 00:00:00 2001 From: Antonio Scandurra Date: Sun, 22 Feb 2015 15:04:37 +0100 Subject: [PATCH] :art: Give code a better structure --- src/text-editor.coffee | 21 +++++++-------------- 1 file changed, 7 insertions(+), 14 deletions(-) diff --git a/src/text-editor.coffee b/src/text-editor.coffee index 19334a813..bd3f76190 100644 --- a/src/text-editor.coffee +++ b/src/text-editor.coffee @@ -2206,26 +2206,19 @@ class TextEditor extends Model result = fn() @suppressSelectionMerging = false - findIntersectingSelection = (elements, selection) -> - return if elements.length == 0 - - otherSelection = _.last(elements) - exclusive = not selection.isEmpty() and not otherSelection.isEmpty() - intersects = otherSelection.intersectsWith(selection, exclusive) - - return otherSelection if intersects - - reducer = (disjointSelections, selection) -> - intersectingSelection = findIntersectingSelection(disjointSelections, selection) + adjacentSelection = _.last(disjointSelections) + exclusive = not selection.isEmpty() and not adjacentSelection.isEmpty() + intersects = adjacentSelection.intersectsWith(selection, exclusive) - if intersectingSelection? - intersectingSelection.merge(selection, options) + if intersects + adjacentSelection.merge(selection, options) disjointSelections else disjointSelections.concat([selection]) - _.reduce(@getSelectionsOrderedByBufferPosition(), reducer, []) + [head, tail...] = @getSelectionsOrderedByBufferPosition() + _.reduce(tail, reducer, [head]) # Add a {Selection} based on the given {Marker}. #