Support joining editor lines with ctrl-J

This can be used with or without a selection to join one
or more lines with the line below it separated by a space.

Refs #134
This commit is contained in:
Kevin Sawicki
2013-04-04 11:05:11 -07:00
parent 44d78ed30d
commit e442dfff11
5 changed files with 68 additions and 0 deletions

View File

@@ -778,6 +778,9 @@ class EditSession
lowerCase: ->
@replaceSelectedText selectWordIfEmpty:true, (text) => text.toLowerCase()
joinLine: ->
@mutateSelectedText (selection) -> selection.joinLine()
expandLastSelectionOverLine: ->
@getLastSelection().expandOverLine()

View File

@@ -155,6 +155,7 @@ class Editor extends View
'editor:move-line-up': @moveLineUp
'editor:move-line-down': @moveLineDown
'editor:duplicate-line': @duplicateLine
'editor:join-line': @joinLine
'editor:toggle-indent-guide': => config.set('editor.showIndentGuide', !config.get('editor.showIndentGuide'))
'editor:save-debug-snapshot': @saveDebugSnapshot
'editor:toggle-line-numbers': => config.set('editor.showLineNumbers', !config.get('editor.showLineNumbers'))
@@ -183,6 +184,7 @@ class Editor extends View
moveLineDown: -> @activeEditSession.moveLineDown()
setCursorScreenPosition: (position, options) -> @activeEditSession.setCursorScreenPosition(position, options)
duplicateLine: -> @activeEditSession.duplicateLine()
joinLine: -> @activeEditSession.joinLine()
getCursorScreenPosition: -> @activeEditSession.getCursorScreenPosition()
getCursorScreenRow: -> @activeEditSession.getCursorScreenRow()
setCursorBufferPosition: (position, options) -> @activeEditSession.setCursorBufferPosition(position, options)

View File

@@ -24,6 +24,7 @@
'ctrl-meta-up': 'editor:move-line-up'
'ctrl-meta-down': 'editor:move-line-down'
'meta-D': 'editor:duplicate-line'
'ctrl-J': 'editor:join-line'
'.editor.mini':
'enter': 'core:confirm',

View File

@@ -286,6 +286,31 @@ class Selection
end--
@editSession.buffer.deleteRows(start, end)
joinLine: ->
selectedRange = @getBufferRange()
if selectedRange.isEmpty()
return if selectedRange.start.row is @editSession.buffer.getLastRow()
else
joinMarker = @editSession.markBufferRange(selectedRange, invalidationStrategy: 'never')
rowCount = Math.max(1, selectedRange.getRowCount() - 1)
for row in [0...rowCount]
@cursor.setBufferPosition([selectedRange.start.row])
@cursor.moveToEndOfLine()
nextRow = selectedRange.start.row + 1
if nextRow <= @editSession.buffer.getLastRow() and @editSession.buffer.lineLengthForRow(nextRow) > 0
@insertText(' ')
@cursor.moveToEndOfLine()
@modifySelection =>
@cursor.moveRight()
@cursor.moveToFirstCharacterOfLine()
@deleteSelectedText()
if joinMarker?
newSelectedRange = @editSession.getMarkerBufferRange(joinMarker)
@setBufferRange(newSelectedRange)
@editSession.destroyMarker(joinMarker)
outdentSelectedRows: ->
[start, end] = @getBufferRowRange()
buffer = @editSession.buffer