mirror of
https://github.com/atom/atom.git
synced 2026-04-28 03:01:47 -04:00
@@ -411,6 +411,28 @@ class EditSession
|
||||
|
||||
@setSelectedBufferRange(selection.translate([1]), preserveFolds: true)
|
||||
|
||||
duplicateLine: ->
|
||||
return unless @getSelection().isEmpty()
|
||||
|
||||
@transact =>
|
||||
cursorPosition = @getCursorBufferPosition()
|
||||
cursorRowFolded = @isFoldedAtCursorRow()
|
||||
if cursorRowFolded
|
||||
screenRow = @screenPositionForBufferPosition(cursorPosition).row
|
||||
bufferRange = @bufferRangeForScreenRange([[screenRow], [screenRow + 1]])
|
||||
else
|
||||
bufferRange = new Range([cursorPosition.row], [cursorPosition.row + 1])
|
||||
|
||||
insertPosition = new Point(bufferRange.end.row)
|
||||
if insertPosition.row >= @buffer.getLastRow()
|
||||
@unfoldCurrentRow() if cursorRowFolded
|
||||
@buffer.append("\n#{@getTextInBufferRange(bufferRange)}")
|
||||
@foldCurrentRow() if cursorRowFolded
|
||||
else
|
||||
@buffer.insert(insertPosition, @getTextInBufferRange(bufferRange))
|
||||
|
||||
@setCursorScreenPosition(@getCursorScreenPosition().translate([1]))
|
||||
@foldCurrentRow() if cursorRowFolded
|
||||
|
||||
mutateSelectedText: (fn) ->
|
||||
@transact => fn(selection) for selection in @getSelections()
|
||||
|
||||
@@ -186,6 +186,7 @@ class Editor extends View
|
||||
'editor:copy-path': @copyPathToPasteboard
|
||||
'editor:move-line-up': @moveLineUp
|
||||
'editor:move-line-down': @moveLineDown
|
||||
'editor:duplicate-line': @duplicateLine
|
||||
|
||||
documentation = {}
|
||||
for name, method of editorBindings
|
||||
@@ -209,6 +210,7 @@ class Editor extends View
|
||||
moveCursorToEndOfLine: -> @activeEditSession.moveCursorToEndOfLine()
|
||||
moveLineUp: -> @activeEditSession.moveLineUp()
|
||||
moveLineDown: -> @activeEditSession.moveLineDown()
|
||||
duplicateLine: -> @activeEditSession.duplicateLine()
|
||||
setCursorScreenPosition: (position) -> @activeEditSession.setCursorScreenPosition(position)
|
||||
getCursorScreenPosition: -> @activeEditSession.getCursorScreenPosition()
|
||||
getCursorScreenRow: -> @activeEditSession.getCursorScreenRow()
|
||||
|
||||
@@ -40,3 +40,4 @@
|
||||
'ctrl-C': 'editor:copy-path'
|
||||
'ctrl-meta-up': 'editor:move-line-up'
|
||||
'ctrl-meta-down': 'editor:move-line-down'
|
||||
'meta-D': 'editor:duplicate-line'
|
||||
|
||||
Reference in New Issue
Block a user