int (CharSequence text, Editor editor, Document document) { TextRange selection = EditorUtil.getSelectionInAnyMode(editor); int start = document.getLineStartOffset(document.getLineNumber(selection.getStartOffset())); int end = document.getLineEndOffset(document.getLineNumber(selection.getEndOffset())); document.replaceString(start, end, text); editor.getSelectionModel().setSelection(start, start + text.length()); return start; }