Thank you @AbeEstrada.
I took your code and extended it to behave more like Sublime does.
It’s my first atom code, I hope it isn’t that bad:
init.coffee
:
atom.workspaceView.command 'custom:copyline', ->
editor = atom.workspace.getActiveEditor()
if not editor.getSelectedText()
cursor = editor.getCursor()
originalPosition = cursor.getScreenPosition()
editor.selectLine()
editor.copySelectedText()
cursor.setScreenPosition(originalPosition)
else
editor.copySelectedText()
atom.workspaceView.command 'custom:cutline', ->
editor = atom.workspace.getActiveEditor()
if not editor.getSelectedText()
cursor = editor.getCursor()
originalPosition = cursor.getScreenPosition()
editor.selectLine()
editor.cutSelectedText()
cursor.setScreenPosition(originalPosition)
else
editor.cutSelectedText()
atom.workspaceView.command 'custom:pasteline', ->
editor = atom.workspace.getActiveEditor()
clipboardText = atom.clipboard.read()
if clipboardText.indexOf('\n') == clipboardText.length - 1 and not editor.getSelectedText()
cursor = editor.getCursor()
originalPosition = cursor.getScreenPosition()
cursor.moveToBeginningOfLine()
editor.pasteText()
originalPosition.row += 1
cursor.setScreenPosition(originalPosition)
else
editor.pasteText()
keymap.cson
:
'body':
'ctrl-c': 'custom:copyline'
'ctrl-x': 'custom:cutline'
'ctrl-v': 'custom:pasteline'