mirror of
https://github.com/atom/atom.git
synced 2026-02-14 08:35:11 -05:00
@@ -334,6 +334,39 @@ class EditSession
|
||||
toggleLineCommentsForBufferRows: (start, end) ->
|
||||
@languageMode.toggleLineCommentsForBufferRows(start, end)
|
||||
|
||||
moveLineUp: ->
|
||||
selection = @getSelectedBufferRange()
|
||||
return if selection.start.row is 0
|
||||
lastRow = @buffer.getLastRow()
|
||||
return if selection.isEmpty() and selection.start.row is lastRow and @buffer.getLastLine() is ''
|
||||
|
||||
@transact =>
|
||||
for row in [selection.start.row..selection.end.row]
|
||||
screenPosition = @screenPositionForBufferPosition([row, 0])
|
||||
isRowFolded = @isFoldedAtScreenRow(screenPosition.row)
|
||||
if isRowFolded
|
||||
bufferRange = @bufferRangeForScreenRange([[screenPosition.row, 0], [screenPosition.row + 1, 0]])
|
||||
startRow = bufferRange.start.row
|
||||
endRow = bufferRange.end.row - 1
|
||||
else
|
||||
startRow = row
|
||||
endRow = row
|
||||
|
||||
endPosition = Point.min([endRow + 1, 0], @buffer.getEofPosition())
|
||||
lines = @buffer.getTextInRange([[startRow, 0], endPosition])
|
||||
if endPosition.row is lastRow and endPosition.column > 0 and not @buffer.lineEndingForRow(endPosition.row)
|
||||
lines = "#{lines}\n"
|
||||
@buffer.deleteRows(startRow, endRow)
|
||||
@buffer.insert([startRow - 1, 0], lines)
|
||||
@foldBufferRow(startRow - 1) if isRowFolded
|
||||
|
||||
newStartPosition = [selection.start.row - 1, selection.start.column]
|
||||
if selection.isEmpty()
|
||||
@setCursorBufferPosition(newStartPosition)
|
||||
else
|
||||
newEndPosition = [selection.end.row - 1, selection.end.column]
|
||||
@setSelectedBufferRange([newStartPosition, newEndPosition], preserveFolds: true)
|
||||
|
||||
mutateSelectedText: (fn) ->
|
||||
@transact => fn(selection) for selection in @getSelections()
|
||||
|
||||
|
||||
@@ -183,6 +183,7 @@ class Editor extends View
|
||||
'editor:close-all-edit-sessions': @destroyAllEditSessions
|
||||
'editor:select-grammar': @selectGrammar
|
||||
'editor:copy-path': @copyPathToPasteboard
|
||||
'editor:move-line-up': @moveLineUp
|
||||
|
||||
documentation = {}
|
||||
for name, method of editorBindings
|
||||
@@ -204,6 +205,7 @@ class Editor extends View
|
||||
moveCursorToBeginningOfLine: -> @activeEditSession.moveCursorToBeginningOfLine()
|
||||
moveCursorToFirstCharacterOfLine: -> @activeEditSession.moveCursorToFirstCharacterOfLine()
|
||||
moveCursorToEndOfLine: -> @activeEditSession.moveCursorToEndOfLine()
|
||||
moveLineUp: -> @activeEditSession.moveLineUp()
|
||||
setCursorScreenPosition: (position) -> @activeEditSession.setCursorScreenPosition(position)
|
||||
getCursorScreenPosition: -> @activeEditSession.getCursorScreenPosition()
|
||||
getCursorScreenRow: -> @activeEditSession.getCursorScreenRow()
|
||||
|
||||
@@ -38,3 +38,4 @@
|
||||
'meta-P': 'editor:close-all-edit-sessions'
|
||||
'meta-L': 'editor:select-grammar'
|
||||
'ctrl-C': 'editor:copy-path'
|
||||
'ctrl-meta-up': 'editor:move-line-up'
|
||||
|
||||
@@ -133,6 +133,7 @@ class LineMap
|
||||
new Range(start, end)
|
||||
|
||||
bufferRangeForScreenRange: (screenRange) ->
|
||||
screenRange = Range.fromObject(screenRange)
|
||||
start = @bufferPositionForScreenPosition(screenRange.start)
|
||||
end = @bufferPositionForScreenPosition(screenRange.end)
|
||||
new Range(start, end)
|
||||
@@ -141,4 +142,3 @@ class LineMap
|
||||
for row in [start..end]
|
||||
line = @lineForScreenRow(row).text
|
||||
console.log row, line, line.length
|
||||
|
||||
|
||||
@@ -11,6 +11,12 @@ class Point
|
||||
|
||||
new Point(row, column)
|
||||
|
||||
@min: (point1, point2) ->
|
||||
if @fromObject(point1).isLessThanOrEqual(@fromObject(point2))
|
||||
point1
|
||||
else
|
||||
point2
|
||||
|
||||
constructor: (@row=0, @column=0) ->
|
||||
|
||||
copy: ->
|
||||
|
||||
Reference in New Issue
Block a user