void (@NotNull Editor editor, @NotNull Caret caret, DataContext dataContext) { if (caret.hasSelection()) { delete(editor, caret, caret.getSelectionStart(), caret.getSelectionEnd()); return; } final Document doc = editor.getDocument(); int caretOffset = caret.getOffset(); if ((myToLineStart && (caretOffset == 0)) || (!myToLineStart && (caretOffset >= doc.getTextLength()))) { return; } final int lineNumber = doc.getLineNumber(caretOffset); int lineEndOffset = doc.getLineEndOffset(lineNumber); int lineStartOffset = doc.getLineStartOffset(lineNumber); int start; int end; if (myToLineStart) { start = caret.getLogicalPosition().column == 0 ? lineStartOffset - 1 : lineStartOffset; end = caretOffset; } else { if (caretOffset >= lineEndOffset) { start = lineEndOffset; end = lineEndOffset + 1; } else { start = caretOffset; end = lineEndOffset; if (lineEndOffset < doc.getTextLength() && CharArrayUtil.isEmptyOrSpaces(doc.getCharsSequence(), caretOffset, lineEndOffset)) { end++; } } } delete(editor, caret, start, end); }