/** Replace one occurrence of the search string with the replacement string. */
  private static int replaceOne(
      View view,
      JEditBuffer buffer,
      SearchMatcher.Match occur,
      int offset,
      CharSequence found,
      boolean smartCaseReplace)
      throws Exception {
    String subst = replaceOne(view, buffer, occur, found);
    if (smartCaseReplace && ignoreCase) {
      int strCase = TextUtilities.getStringCase(found);
      if (strCase == TextUtilities.LOWER_CASE) subst = subst.toLowerCase();
      else if (strCase == TextUtilities.UPPER_CASE) subst = subst.toUpperCase();
      else if (strCase == TextUtilities.TITLE_CASE) subst = TextUtilities.toTitleCase(subst);
    }

    if (subst != null) {
      int start = offset + occur.start;
      int end = offset + occur.end;

      if (end - start > 0) buffer.remove(start, end - start);
      buffer.insert(start, subst);
      return subst.length();
    } else return -1;
  } // }}}
Beispiel #2
0
  protected void updateBracketHighlight(int newCaretPosition) {
    if (newCaretPosition == 0) {
      bracketPosition = bracketLine = -1;
      return;
    }

    try {
      int offset = TextUtilities.findMatchingBracket(document, newCaretPosition - 1);
      if (offset != -1) {
        bracketLine = getLineOfOffset(offset);
        bracketPosition = offset - getLineStartOffset(bracketLine);
        return;
      }
    } catch (BadLocationException bl) {
      bl.printStackTrace();
    }

    bracketLine = bracketPosition = -1;
  }
Beispiel #3
0
    private void doDoubleClick(MouseEvent evt, int line, int offset, int dot)
        throws BadLocationException {
      // Ignore empty lines
      if (getLineLength(line) == 0) return;

      try {
        int bracket = TextUtilities.findMatchingBracket(document, Math.max(0, dot - 1));
        if (bracket != -1) {
          int mark = getMarkPosition();
          // Hack
          if (bracket > mark) {
            bracket++;
            mark--;
          }
          select(mark, bracket);
          return;
        }
      } catch (BadLocationException bl) {
        bl.printStackTrace();
      }

      // Ok, it's not a bracket... select the word
      String lineText = getLineText(line);
      char ch = lineText.charAt(Math.max(0, offset - 1));

      String noWordSep = (String) document.getProperty("noWordSep");
      if (noWordSep == null) noWordSep = "";

      // If the user clicked on a non-letter char,
      // we select the surrounding non-letters
      boolean selectNoLetter = (!Character.isLetterOrDigit(ch) && noWordSep.indexOf(ch) == -1);

      int wordStart = 0;

      for (int i = offset - 1; i >= 0; i--) {
        ch = lineText.charAt(i);
        if (selectNoLetter ^ (!Character.isLetterOrDigit(ch) && noWordSep.indexOf(ch) == -1)) {
          wordStart = i + 1;
          break;
        }
      }

      int wordEnd = lineText.length();
      for (int i = offset; i < lineText.length(); i++) {
        ch = lineText.charAt(i);
        if (selectNoLetter ^ (!Character.isLetterOrDigit(ch) && noWordSep.indexOf(ch) == -1)) {
          wordEnd = i;
          break;
        }
      }

      int lineStart = getLineStartOffset(line);
      select(lineStart + wordStart, lineStart + wordEnd);

      /*
      String lineText = getLineText(line);
      String noWordSep = (String)document.getProperty("noWordSep");
      int wordStart = TextUtilities.findWordStart(lineText,offset,noWordSep);
      int wordEnd = TextUtilities.findWordEnd(lineText,offset,noWordSep);

      int lineStart = getLineStartOffset(line);
      select(lineStart + wordStart,lineStart + wordEnd);
      */
    }
 /**
  * Returns if the replacement string will assume the same case as each specific occurrence of the
  * search string.
  *
  * @since jEdit 4.2pre10
  */
 public static boolean getSmartCaseReplace() {
   return (replace != null && TextUtilities.getStringCase(replace) == TextUtilities.LOWER_CASE);
 } // }}}