Buggy code:
public Color getSelectionBackground ( ) { } public int getSelectionCount ( ) { } public Color getSelectionForeground ( ) { } public String getSelectionText ( ) { } public int getStyle ( ) { } int [ ] getBidiSegments ( int lineOffset , String line ) { } int [ ] getBidiSegmentsCompatibility ( String line , int lineOffset ) { } public StyleRange getStyleRangeAtOffset ( int offset ) { } public StyleRange [ ] getStyleRanges ( ) { } public StyleRange [ ] getStyleRanges ( boolean includeRanges ) { } public StyleRange [ ] getStyleRanges ( int start , int length ) { } public StyleRange [ ] getStyleRanges ( int start , int length , boolean includeRanges ) { } public int getTabs ( ) { } public String getText ( ) { } public String getText ( int start , int end ) { } public Rectangle getTextBounds ( int start , int end ) { } public String getTextRange ( int start , int length ) { } public int getTextLimit ( ) { } public int getTopIndex ( ) { } public int getTopPixel ( ) { } int getVerticalIncrement ( ) { } int getVerticalScrollOffset ( ) { } int getVisualLineIndex ( TextLayout layout , int offsetInLine ) { } int getCaretDirection ( ) { } int getCaretLine ( ) { } int getWrapWidth ( ) { } int getWordNext ( int offset , int movement ) { } int getWordPrevious ( int offset , int movement ) { } public boolean getWordWrap ( ) { } Point getPointAtOffset ( int offset ) { } public void insert ( String string ) { } void insertBlockSelectionText ( String text , int action ) { int firstLine = getLineIndex ( ( ( blockYAnchor ) - ( getVerticalScrollOffset ( ) ) ) ) ; int lastLine = getLineIndex ( ( ( blockYLocation ) - ( getVerticalScrollOffset ( ) ) ) ) ; if ( firstLine > lastLine ) { int temp = firstLine ; firstLine = lastLine ; lastLine = temp ; } int left = blockXAnchor ; int right = blockXLocation ; if ( left > right ) { left = blockXLocation ; right = blockXAnchor ; } int start = 0 ; int end = 0 ; StringBuffer buffer = new StringBuffer ( ) ; for ( int lineIndex = firstLine ; lineIndex <= lastLine ; lineIndex ++ ) { String line = content . getLine ( lineIndex ) ; int lineOffset = content . getOffsetAtLine ( lineIndex ) ; int lineStart = getOffsetAtPoint ( left , 0 , lineIndex ) ; int lineEnd = getOffsetAtPoint ( right , 0 , lineIndex ) ; switch ( action ) { case ST . DELETE_PREVIOUS : { if ( ( lineStart == lineEnd ) && ( lineStart > lineOffset ) ) { if ( ( getOffsetAtPoint ( left , getLinePixel ( lineIndex ) , null , true ) ) != ( - 1 ) ) { lineStart = getClusterPrevious ( lineStart , lineIndex ) ; } } break ; } case ST . DELETE_NEXT : { if ( ( lineStart == lineEnd ) && ( lineEnd < ( lineOffset + ( line . length ( ) ) ) ) ) { lineEnd = getClusterNext ( lineEnd , lineIndex ) ; } break ; } } if ( lineIndex == firstLine ) start = lineStart ; if ( lineIndex == lastLine ) end = lineEnd ; if ( lineIndex != firstLine ) { buffer . append ( line . substring ( 0 , ( lineStart - lineOffset ) ) ) ; } buffer . append ( text ) ; if ( lineIndex != lastLine ) { buffer . append ( line . substring ( ( lineEnd - lineOffset ) ) ) ; buffer . append ( content . getLineDelimiter ( ) ) ; } } Event event = new Event ( ) ; event . text = buffer . toString ( ) ; event . start = start ; event . end = end ; sendKeyEvent ( event ) ; <START_BUG> int x = getPointAtOffset ( ( ( event . start ) + ( event . text . length ( ) ) ) ) . x ; <END_BUG> setBlockSelectionLocation ( x , ( ( blockYLocation ) - ( getVerticalScrollOffset ( ) ) ) ) ; blockXAnchor = blockXLocation ; } void installDefaultContent ( ) { } void installListeners ( ) { } void internalRedrawRange ( int start , int length ) { } void handleCompositionOffset ( Event event ) { } void handleCompositionSelection ( Event event ) { } void handleCompositionChanged ( Event event ) { } void handleDispose ( Event event ) { } void handleHorizontalScroll ( Event event ) { } void handleKey ( Event event ) { } void handleKeyDown ( Event event ) { } void handleKeyUp ( Event event ) { } void handleMouseDown ( Event event ) { } void handleMouseMove ( Event event ) { } void handleMouseUp ( Event event ) { } void handlePaint ( Event event ) { } void handleResize ( Event event ) { } void handleTextChanged ( TextChangedEvent event ) { } void handleTextChanging ( TextChangingEvent event ) { } void handleTextSet ( TextChangedEvent event ) { } void handleTraverse ( Event event ) { } void handleVerticalScroll ( Event event ) { } void initializeAccessible ( ) { } Label getAssociatedLabel ( ) { } String stripMnemonic ( String string ) { } char _findMnemonic ( String string ) { } public void invokeAction ( int action ) { } boolean invokeBlockSelectionAction ( int action ) { } boolean isBidi ( ) { } boolean isBidiCaret ( ) { } boolean isFixedLineHeight ( ) { } boolean isLineDelimiter ( int offset ) { } boolean isMirrored ( ) { } boolean isSingleLine ( ) { } void modifyContent ( Event event , boolean updateCaret ) { }

Fix:
int x = getPointAtOffset ( caretOffset ) . x ;