message: Fix :d[elete] command
  Move the cursor to the start of the line where the deleted range was
  Copy the deleted range into the clipboard register when `useSystemClipboard` is enabled
diff: @@ -5,6 +5,8 @@ import { VimState } from '../../state/vimState';
  import { Register, RegisterMode } from '../../register/register';
  import { TextEditor } from '../../textEditor';
  import * as node from '../node';
  +import { config } from 'process';
  +import { configuration } from '../../configuration/configuration';
  export interface IDeleteRangeCommandArguments extends node.ICommandArgs {
  register?: string;
  @@ -26,33 +28,31 @@ export class DeleteRangeCommand extends node.CommandBase {
  return true;
  }
  + /**
  + * Deletes text between `startLine` and `endLine`, inclusive.
  + * Puts the cursor at the start of the line where the deleted range was.
  + *
  + * @returns The deleted text, excluding leading/trailing newline
  + */
  async deleteRange(startLine: number, endLine: number, vimState: VimState): Promise<string> {
  let start = new Position(startLine, 0);
  let end = new Position(endLine, 0).getLineEndIncludingEOL();
  - const isOnLastLine = end.line === TextEditor.getLineCount() - 1;
  -
  - if (end.character === TextEditor.getLineAt(end).text.length + 1) {
  - end = end.getDownWithDesiredColumn(0);
  - }
  -
  - if (isOnLastLine && start.line !== 0) {
  - start = start.getPreviousLineBegin().getLineEnd();
  + if (endLine < vimState.editor.document.lineCount - 1) {
  + end = end.getRightThroughLineBreaks();
  + } else if (startLine > 0) {
  + start = start.getLeftThroughLineBreaks();
  }
  - let text = vimState.editor.document.getText(new vscode.Range(start, end));
  - text = text.endsWith('\r\n') ? text.slice(0, -2) : text.slice(0, -1);
  - await TextEditor.delete(new vscode.Range(start, end));
  -
  - let resultPosition = earlierOf(start, end);
  - if (start.character > TextEditor.getLineAt(start).text.length) {
  - resultPosition = start.getLeft();
  - } else {
  - resultPosition = start;
  - }
  + const range = new vscode.Range(start, end);
  + const text = vimState.editor.document
  + .getText(range)
  + // Remove leading or trailing newline
  + .replace(/^\r?\n/, '')
  + .replace(/\r?\n$/, '');
  + await TextEditor.delete(range);
  - resultPosition = resultPosition.getLineBegin();
  - vimState.editor.selection = new vscode.Selection(resultPosition, resultPosition);
  + vimState.cursorStopPosition = start.getLineBegin();
  return text;
  }
  @@ -61,15 +61,17 @@ export class DeleteRangeCommand extends node.CommandBase {
  return;
  }
  - let cursorPosition = Position.FromVSCodePosition(vimState.editor.selection.active);
  - let text = await this.deleteRange(cursorPosition.line, cursorPosition.line, vimState);
  - Register.putByKey(text, this._arguments.register, RegisterMode.LineWise);
  + const line = vimState.cursorStopPosition.line;
  + const text = await this.deleteRange(line, line, vimState);
  + const register = this._arguments.register ?? (configuration.useSystemClipboard ? '*' : '"');
  + Register.putByKey(text, register, RegisterMode.LineWise);
  }
  async executeWithRange(vimState: VimState, range: node.LineRange): Promise<void> {
  const [start, end] = range.resolve(vimState);
  let text = await this.deleteRange(start, end, vimState);
  - Register.putByKey(text, this._arguments.register, RegisterMode.LineWise);
  + const register = this._arguments.register ?? (configuration.useSystemClipboard ? '*' : '"');
  + Register.putByKey(text, register, RegisterMode.LineWise);
  }
  }
  