Buggy code:
int maxWidth ; int maxWidthLineIndex ; public ContentWidthCache ( StyledText parent , StyledTextContent content ) { } public void calculate ( int startLine , int lineCount ) { } void calculateVisible ( int startLine , int newLineCount ) { } int contentWidth ( String line , int lineOffset ) { } void expandLines ( int numLines ) { } public int getWidth ( ) { } void linesChanged ( int startLine , int delta ) { } public void redrawReset ( int startLine , int lineCount , boolean calculateMaxWidth ) { } public void reset ( int startLine , int lineCount , boolean calculateMaxWidth ) { } public void textChanged ( int startOffset , int newLineCount , int replaceLineCount , int newCharCount , int replaceCharCount ) { } } class WordWrapCache implements StyledText . LineCache { StyledText parent ; WrappedContent visualContent ; public WordWrapCache ( StyledText parent , WrappedContent content ) { } public void calculate ( int startLine , int lineCount ) { } public int getWidth ( ) { } public void redrawReset ( int startLine , int lineCount , boolean calculateMaxWidth ) { } public void reset ( int startLine , int lineCount , boolean calculateMaxWidth ) { } public void textChanged ( int startOffset , int newLineCount , int replaceLineCount , int newCharCount , int replaceCharCount ) { } } public StyledText ( Composite parent , int style ) { } public void addExtendedModifyListener ( ExtendedModifyListener extendedModifyListener ) { } public void setKeyBinding ( int key , int action ) { } public void addBidiSegmentListener ( BidiSegmentListener listener ) { } public void addLineBackgroundListener ( LineBackgroundListener listener ) { } public void addLineStyleListener ( LineStyleListener listener ) { } public void addModifyListener ( ModifyListener modifyListener ) { } public void addSelectionListener ( SelectionListener listener ) { } public void addVerifyKeyListener ( VerifyKeyListener listener ) { } public void addVerifyListener ( VerifyListener verifyListener ) { } public void append ( String string ) { } void calculateContentWidth ( ) { } void calculateScrollBars ( ) { } void calculateTopIndex ( ) { } static int checkStyle ( int style ) { } void claimBottomFreeSpace ( ) { } void claimRightFreeSpace ( ) { } void clearMargin ( GC gc , Color background , Rectangle clientArea , int y ) { } void clearSelection ( boolean sendEvent ) { } public Point computeSize ( int wHint , int hHint , boolean changed ) { } public void copy ( ) { } public void copy ( int clipboardType ) { } String getModelDelimitedText ( String text ) { } void createKeyBindings ( ) { } void createCaretBitmaps ( ) { } public void cut ( ) { } void doAutoScroll ( Event event ) { } void doAutoScroll ( int direction ) { } void doBackspace ( ) { } void doContent ( char key ) { } void doContentEnd ( ) { } void doContentStart ( ) { } void doCursorPrevious ( ) { } void doCursorNext ( ) { } void doDelete ( ) { } void doDeleteWordNext ( ) { } void doDeleteWordPrevious ( ) { } int doLineDown ( ) { } void doLineEnd ( ) { } void doLineStart ( ) { } int doLineUp ( ) { } void doMouseLocationChange ( int x , int y , boolean select ) { int line = ( y + ( verticalScrollOffset ) ) // ( lineHeight ) ; int lineCount = content . getLineCount ( ) ; int newCaretOffset ; int newCaretLine ; boolean oldAdvancing = advancing ; updateCaretDirection = true ; if ( line > ( lineCount - 1 ) ) { line = lineCount - 1 ; } if ( ( line < 0 ) || ( ( isSingleLine ( ) ) && ( line > 0 ) ) ) { return ; } newCaretOffset = getOffsetAtMouseLocation ( x , line ) ; if ( mouseDoubleClick ) { newCaretOffset = doMouseWordSelect ( x , newCaretOffset , line ) ; } newCaretLine = content . getLineAtOffset ( newCaretOffset ) ; <START_BUG> if ( ( ( y >= 0 ) && ( y < ( getClientArea ( ) . height ) ) ) && ( ( ( x >= 0 ) && ( x < ( getClientArea ( ) . width ) ) ) || ( newCaretLine != ( content . getLineAtOffset ( caretOffset ) ) ) ) ) { <END_BUG> if ( ( newCaretOffset != ( caretOffset ) ) || ( ( advancing ) != oldAdvancing ) ) { caretOffset = newCaretOffset ; if ( select ) { doMouseSelection ( ) ; } showCaret ( ) ; } } if ( select == false ) { caretOffset = newCaretOffset ; clearSelection ( true ) ; } } void doMouseSelection ( ) { } int doMouseWordSelect ( int x , int newCaretOffset , int line ) { } void doPageDown ( boolean select ) { } void doPageEnd ( ) { } void doPageStart ( ) { } void doPageUp ( ) { } void doSelection ( int direction ) { } void doSelectionCursorNext ( ) { } void doSelectionCursorPrevious ( ) { } void doSelectionLineDown ( ) { } void doSelectionLineUp ( ) { } void doSelectionPageDown ( ) { } void doSelectionPageUp ( ) { } void doSelectionWordNext ( ) { } void doSelectionWordPrevious ( ) { } void doVisualPrevious ( ) { } void doVisualNext ( ) { } void doWordNext ( ) { } void doWordPrevious ( ) { } void draw ( int x , int y , int width , int height , boolean clearBackground ) { } void endAutoScroll ( ) { } public Color getBackground ( ) { } public int getBaseline ( ) { } public boolean getBidiColoring ( ) { } int getBottomIndex ( ) { } public int getCaretOffset ( ) { } int getOffsetAtX ( String line , int lineOffset , int lineXOffset ) { } int getCaretWidth ( ) { }

Fix:
if ( ( ( y >= 0 ) && ( y < ( getClientArea ( ) . height ) ) ) && ( ( ( ( x >= 0 ) && ( x < ( getClientArea ( ) . width ) ) ) || ( wordWrap ) ) || ( newCaretLine != ( content . getLineAtOffset ( caretOffset ) ) ) ) ) {