int (Editor editor, int tailOffset, char c, boolean overwrite) { Document document = editor.getDocument(); int textLength = document.getTextLength(); CharSequence chars = document.getCharsSequence(); if (tailOffset == textLength || !overwrite || chars.charAt(tailOffset) != c) { document.insertString(tailOffset, String.valueOf(c)); } return moveCaret(editor, tailOffset, 1); }