### Eclipse Workspace Patch 1.0 #P org.eclipse.text Index: src/org/eclipse/jface/text/FindReplaceDocumentAdapter.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.text/src/org/eclipse/jface/text/FindReplaceDocumentAdapter.java,v retrieving revision 1.23 diff -u -r1.23 FindReplaceDocumentAdapter.java --- src/org/eclipse/jface/text/FindReplaceDocumentAdapter.java 23 Jul 2007 14:37:04 -0000 1.23 +++ src/org/eclipse/jface/text/FindReplaceDocumentAdapter.java 26 Jul 2007 08:56:20 -0000 @@ -120,7 +120,7 @@ * @throws IllegalStateException if a REPLACE or REPLACE_FIND operation is not preceded by a successful FIND operation * @throws PatternSyntaxException if a regular expression has invalid syntax */ - private IRegion findReplace(final FindReplaceOperationCode operationCode, int startOffset, String findString, String replaceText, boolean forwardSearch, boolean caseSensitive, boolean wholeWord, boolean regExSearch) throws BadLocationException { + private IRegion findReplace(FindReplaceOperationCode operationCode, int startOffset, String findString, String replaceText, boolean forwardSearch, boolean caseSensitive, boolean wholeWord, boolean regExSearch) throws BadLocationException { // Validate option combinations Assert.isTrue(!(regExSearch && wholeWord)); @@ -155,6 +155,9 @@ if (!regExSearch && !wholeWord) findString= asRegPattern(findString); + if (fFindReplaceMatchOffset == startOffset) + operationCode= FIND_NEXT; // https://bugs.eclipse.org/bugs/show_bug.cgi?id=80661 + fFindReplaceMatchOffset= startOffset; if (fFindReplaceMatcher != null && fFindReplaceMatcher.pattern().pattern().equals(findString) && fFindReplaceMatcher.pattern().flags() == patternFlags) { /* @@ -203,8 +206,11 @@ if (operationCode == REPLACE_FIND_NEXT) fFindReplaceState= FIND_NEXT; - if (found && fFindReplaceMatcher.group().length() > 0) - return new Region(fFindReplaceMatcher.start(), fFindReplaceMatcher.group().length()); + if (found) { + fFindReplaceMatchOffset= fFindReplaceMatcher.start(); + int end= fFindReplaceMatcher.end(); + return new Region(fFindReplaceMatchOffset, end - fFindReplaceMatchOffset); + } return null; } @@ -212,7 +218,7 @@ boolean found= fFindReplaceMatcher.find(0); int index= -1; int length= -1; - while (found && fFindReplaceMatcher.start() + fFindReplaceMatcher.group().length() <= fFindReplaceMatchOffset + 1) { + while (found && fFindReplaceMatcher.start() + fFindReplaceMatcher.group().length() <= fFindReplaceMatchOffset) { index= fFindReplaceMatcher.start(); length= fFindReplaceMatcher.group().length(); found= fFindReplaceMatcher.find(index + 1); #P org.eclipse.jface.text Index: src/org/eclipse/jface/text/TextViewer.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.jface.text/src/org/eclipse/jface/text/TextViewer.java,v retrieving revision 1.180 diff -u -r1.180 TextViewer.java --- src/org/eclipse/jface/text/TextViewer.java 20 Jun 2007 14:30:54 -0000 1.180 +++ src/org/eclipse/jface/text/TextViewer.java 26 Jul 2007 08:56:31 -0000 @@ -4222,9 +4222,14 @@ int length= matchRegion.getLength(); // Prevents setting of widget selection with line delimiters at beginning or end - char startChar= adapter.charAt(widgetPos); - char endChar= adapter.charAt(widgetPos+length-1); - boolean borderHasLineDelimiter= startChar == '\n' || startChar == '\r' || endChar == '\n' || endChar == '\r'; + boolean borderHasLineDelimiter= false; + try { + char startChar= adapter.charAt(widgetPos); + char endChar= adapter.charAt(widgetPos+length-1); + borderHasLineDelimiter= startChar == '\n' || startChar == '\r' || endChar == '\n' || endChar == '\r'; + } catch (IndexOutOfBoundsException e) { + // Not a problem at beginning or end of document + } boolean redraws= redraws(); if (borderHasLineDelimiter && redraws) setRedraw(false);