From bf5ebc996952ac26c8eeda0b92b511b4b81688f2 Mon Sep 17 00:00:00 2001 From: Corey Johnson Date: Mon, 2 Apr 2012 14:55:40 -0700 Subject: [PATCH] :lipstick: xxwip --- src/atom/composite-cursor.coffee | 6 +- src/atom/composite-selection.coffee | 102 ++++++++++++++-------------- 2 files changed, 54 insertions(+), 54 deletions(-) diff --git a/src/atom/composite-cursor.coffee b/src/atom/composite-cursor.coffee index 63de447b5..6e2ae19dc 100644 --- a/src/atom/composite-cursor.coffee +++ b/src/atom/composite-cursor.coffee @@ -7,6 +7,9 @@ class CompositeCursor @cursors = [] @addCursor() + handleBufferChange: (e) -> + @moveCursors (cursor) -> cursor.handleBufferChange(e) + getCursor: (index) -> index ?= @cursors.length - 1 @cursors[index] @@ -81,9 +84,6 @@ class CompositeCursor moveToFirstCharacterOfLine: -> @moveCursors (cursor) -> cursor.moveToFirstCharacterOfLine() - handleBufferChange: (e) -> - @moveCursors (cursor) -> cursor.handleBufferChange(e) - mergeCursors: -> positions = [] for cursor in new Array(@cursors...) diff --git a/src/atom/composite-selection.coffee b/src/atom/composite-selection.coffee index 9fa9f05ec..d85e03d48 100644 --- a/src/atom/composite-selection.coffee +++ b/src/atom/composite-selection.coffee @@ -6,11 +6,18 @@ class CompositeSeleciton constructor: (@editor) -> @selections = [] + handleBufferChange: (e) -> + selection.handleBufferChange(e) for selection in @getSelections() + getSelection: (index) -> index ?= @selections.length - 1 @selections[index] - getSelections: -> new Array(@selections...) + getSelections: -> + new Array(@selections...) + + getLastSelection: -> + _.last(@selections) getLastSelectionInBuffer: -> _.last(@getSelections().sort (a, b) -> @@ -42,12 +49,31 @@ class CompositeSeleciton selectionForCursor: (cursor) -> _.find @selections, (selection) -> selection.cursor == cursor - handleBufferChange: (e) -> - selection.handleBufferChange(e) for selection in @getSelections() + setBufferRange: (bufferRange, options) -> + @getLastSelection().setBufferRange(bufferRange, options) + + getBufferRange: (bufferRange) -> + @getLastSelection().getBufferRange() + + getText: -> + @getLastSelection().getText() + + moveSelectionsForward: (fn) -> + fn(selection) for selection in @getSelections() + @mergeIntersectingSelections() + + moveSelectionsBackward: (fn) -> + fn(selection) for selection in @getSelections() + @mergeIntersectingSelections(reverse: true) + + modifySelectedText: (fn) -> + selection.retainSelection = true for selection in @getSelections() + for selection in @getSelections() + selection.retainSelection = false + fn(selection) insertText: (text) -> - @modifySelectedText (selection) -> - selection.insertText(text) + @modifySelectedText (selection) -> selection.insertText(text) backspace: -> @modifySelectedText (selection) -> selection.backspace() @@ -64,71 +90,35 @@ class CompositeSeleciton selectToScreenPosition: (position) -> @getLastSelection().selectToScreenPosition(position) - moveSelections: (fn) -> - fn(selection) for selection in @getSelections() - @mergeIntersectingSelections() - - reverseMoveSelections: (fn) -> - fn(selection) for selection in @getSelections() - @mergeIntersectingSelections(reverse: true) - selectRight: -> - @moveSelections (selection) => selection.selectRight() + @moveSelectionsForward (selection) => selection.selectRight() selectLeft: -> - @reverseMoveSelections (selection) => selection.selectLeft() + @moveSelectionsBackward (selection) => selection.selectLeft() selectUp: -> - @reverseMoveSelections (selection) => selection.selectUp() + @moveSelectionsBackward (selection) => selection.selectUp() selectDown: -> - @moveSelections (selection) => selection.selectDown() + @moveSelectionsForward (selection) => selection.selectDown() selectToTop: -> - @reverseMoveSelections (selection) => selection.selectToTop() + @moveSelectionsBackward (selection) => selection.selectToTop() selectToBottom: -> - @moveSelections (selection) => selection.selectToBottom() + @moveSelectionsForward (selection) => selection.selectToBottom() selectToBeginningOfLine: -> - @reverseMoveSelections (selection) => selection.selectToBeginningOfLine() + @moveSelectionsBackward (selection) => selection.selectToBeginningOfLine() selectToEndOfLine: -> - @moveSelections (selection) => selection.selectToEndOfLine() + @moveSelectionsForward (selection) => selection.selectToEndOfLine() selectToBeginningOfWord: -> - @reverseMoveSelections (selection) => selection.selectToBeginningOfWord() + @moveSelectionsBackward (selection) => selection.selectToBeginningOfWord() selectToEndOfWord: -> - @moveSelections (selection) => selection.selectToEndOfWord() - - setBufferRange: (bufferRange, options) -> - @getLastSelection().setBufferRange(bufferRange, options) - - getBufferRange: (bufferRange) -> - @getLastSelection().getBufferRange() - - getText: -> - @getLastSelection().getText() - - getLastSelection: -> - _.last(@selections) - - mergeIntersectingSelections: (options) -> - for selection in @getSelections() - otherSelections = @getSelections() - _.remove(otherSelections, selection) - for otherSelection in otherSelections - if selection.intersectsWith(otherSelection) - selection.merge(otherSelection, options) - @mergeIntersectingSelections(options) - return - - modifySelectedText: (fn) -> - selection.retainSelection = true for selection in @getSelections() - for selection in @getSelections() - selection.retainSelection = false - fn(selection) + @moveSelectionsForward (selection) => selection.selectToEndOfWord() cut: -> maintainPasteboard = false @@ -141,3 +131,13 @@ class CompositeSeleciton for selection in @getSelections() selection.copy(maintainPasteboard) maintainPasteboard = true + + mergeIntersectingSelections: (options) -> + for selection in @getSelections() + otherSelections = @getSelections() + _.remove(otherSelections, selection) + for otherSelection in otherSelections + if selection.intersectsWith(otherSelection) + selection.merge(otherSelection, options) + @mergeIntersectingSelections(options) + return \ No newline at end of file