dd
Delete current line

Script key: Delete current line

Posted by medopaw

Install

Details

Label dd
Voice Over Delete current line
Script
// Delete current line ('dd' in Vim)

var line_range = getSelectedLineRange();

// Grab last character
var lastchar = getTextInRange( line_range[0] + line_range[1] - 1, 1 );

// The last char of an empty line defaults to empty
if ( line_range[1] == 0 ) {
  lastchar = ''
}

// Normal line: delete entire line including newline char
if ( lastchar === '\n' ) {
  setSelectedRange( line_range[0], line_range[1] );
  setClipboard( getSelectedText() );
  setSelectedText( '' )
}
// Final line in draft: delete line and also newline char from previous line
else if ( line_range[0] > 0 ) {
  setSelectedRange( line_range[0]-1, line_range[1]+1 );
  setClipboard( getSelectedText() );
  setSelectedText( '' )
} else {
  setSelectedRange( line_range[0], line_range[1] );
  setClipboard( getSelectedText() );
  setSelectedText( '' )
}

Advanced

Keyboard shortcut None
Hide key Yes

Discussion

comments powered by Disqus