TextRange (@NotNull Editor editor, @NotNull String text, boolean trimIfMiddleLine) { int selectionStart = editor.getSelectionModel().getSelectionStart(); if (trimIfMiddleLine) { int selectionEnd = editor.getSelectionModel().getSelectionEnd(); if (!DocumentUtil.isAtLineStart(selectionEnd, editor.getDocument())) { text = text.trim(); } } int newOffset = EditorModificationUtilEx.insertStringAtCaret(editor, text, false, true); return new TextRange(selectionStart, newOffset); }