RangeMarker (int endOffset, Document document, String temporary) { CharSequence chars = document.getCharsSequence(); if (endOffset < chars.length() && Character.isJavaIdentifierPart(chars.charAt(endOffset))){ document.insertString(endOffset, temporary); RangeMarker toDelete = document.createRangeMarker(endOffset, endOffset + 1); toDelete.setGreedyToLeft(true); toDelete.setGreedyToRight(true); return toDelete; } return null; }