Package org.fife.ui.rsyntaxtextarea

Examples of org.fife.ui.rsyntaxtextarea.DocumentRange


    String text = context.getSearchFor();
    boolean forward = context.getSearchForward();

    // Find the next location of the text we're searching for.
    DocumentRange range = null;
    if (!context.isRegularExpression()) {
      int pos = getNextMatchPos(text, findIn, forward,
                context.getMatchCase(), context.getWholeWord());
      findIn = null; // May help garbage collecting.
      if (pos!=-1) {
        range = new DocumentRange(pos, pos+text.length());
      }
    }

    else {
      // Regex matches can have varying widths.  The returned point's
      // x- and y-values represent the start and end indices of the
      // match in findIn.
      Point regExPos = null;
      int start = 0;
      do {
        regExPos = getNextMatchPosRegEx(text, findIn.substring(start),
          forward, context.getMatchCase(), context.getWholeWord());
        if (regExPos!=null) {
          if (regExPos.x!=regExPos.y) {
            regExPos.translate(start, start);
            range = new DocumentRange(regExPos.x, regExPos.y);
          }
          else {
            start += regExPos.x + 1;
          }
        }
View Full Code Here


        findIn = findIn.toLowerCase();
      }

      SearchResult res = SearchEngine.findImpl(findIn, context);
      while (res.wasFound()) {
        DocumentRange match = res.getMatchRange().translate(start);
        if (match.isZeroLength()) {
          // Searched for a regex like "foo|".  The "empty string"
          // part of the regex matches space between chars.  We want
          // to skip these in the case of mark-all.
          start = match.getEndOffset() + 1;
          if (start>findIn.length()) {
            break;
          }
        }
        else {
          highlights.add(match);
          start = match.getEndOffset();
        }
        res = SearchEngine.findImpl(findIn.substring(start), context);
      }
      textArea.markAll(highlights);
      markAllCount = highlights.size();
View Full Code Here

    // Find the next location of the text we're searching for.
    RegExReplaceInfo info = getRegExReplaceInfo(findIn, context);

    // If a match was found, do the replace and return!
    DocumentRange range = null;
    if (info!=null) {

      // Without this, if JTextArea isn't in focus, selection won't
      // appear selected.
      c.setSelectionVisible(true);

      int matchStart = info.getStartIndex();
      int matchEnd = info.getEndIndex();
      if (forward) {
        matchStart += start;
        matchEnd += start;
      }
      textArea.setSelectionStart(matchStart);
      textArea.setSelectionEnd(matchEnd);
      String replacement = info.getReplacement();
      textArea.replaceSelection(replacement);

      // If there is another match, find and select it.
      int dot = matchStart + replacement.length();
      findIn = getFindInCharSequence(textArea, dot, forward);
      info = getRegExReplaceInfo(findIn, context);
      if (info!=null) {
        matchStart = info.getStartIndex();
        matchEnd = info.getEndIndex();
        if (forward) {
          matchStart += dot;
          matchEnd += dot;
        }
        range = new DocumentRange(matchStart, matchEnd);
      }
      else {
        range = new DocumentRange(dot, dot);
      }
      RSyntaxUtilities.selectAndPossiblyCenter(textArea, range, true);

    }
View Full Code Here

          dot += length;
        }
        textArea.setCaretPosition(dot);

        SearchResult next = find(textArea, context);
        DocumentRange range;
        if (next.wasFound()) {
          range = next.getMatchRange();
        }
        else {
          range = new DocumentRange(dot, dot);
        }
        res.setMatchRange(range);
        RSyntaxUtilities.selectAndPossiblyCenter(textArea, range, true);

      }
View Full Code Here

    List<DocumentRange> list = new ArrayList<DocumentRange>(
        markAllHighlights.size());
    for (HighlightInfo info : markAllHighlights) {
      int start = info.getStartOffset();
      int end = info.getEndOffset() + 1; // HACK
      DocumentRange range = new DocumentRange(start, end);
      list.add(range);
    }
    return list;
  }
View Full Code Here

    context.setMatchCase(false);
    textArea.setCaretPosition(end);
    boolean found = findImpl(context);
    assertTrue(found);
    assertSelected("chuck", 60, context.getMatchCase());
    assertResult(new SearchResult(new DocumentRange(60, 65), 1, markedCount));
    found = findImpl(context);
    assertTrue(found);
    assertSelected("chuck", 48, context.getMatchCase());
    assertResult(new SearchResult(new DocumentRange(48, 53), 1, markedCount));
    found = findImpl(context);
    assertTrue(found);
    assertSelected("chuck", 32, context.getMatchCase());
    assertResult(new SearchResult(new DocumentRange(32, 37), 1, markedCount));
    found = findImpl(context);
    assertTrue(found);
    assertSelected("chuck", 26, context.getMatchCase());
    assertResult(new SearchResult(new DocumentRange(26, 31), 1, markedCount));
    found = findImpl(context);
    assertFalse(found);
    assertResult(new SearchResult(null, 0, markedCount));

    // Search for "Chuck", matching case.
    context.setSearchFor("Chuck");
    markedCount = markAll ? 1 : 0;
    context.setMatchCase(true);
    textArea.setCaretPosition(end);
    found = findImpl(context);
    assertTrue(found);
    assertSelected("Chuck", 26, context.getMatchCase());
    assertResult(new SearchResult(new DocumentRange(26, 31), 1, markedCount));
    found = findImpl(context);
    assertFalse(found);
    assertResult(new SearchResult(null, 0, markedCount));

    // Search for "chuck", ignoring case, whole word
    context.setSearchFor("Chuck");
    markedCount = markAll ? 2 : 0;
    context.setMatchCase(false);
    context.setWholeWord(true);
    textArea.setCaretPosition(end);
    found = findImpl(context);
    assertTrue(found);
    assertSelected("chuck", 60, context.getMatchCase());
    assertResult(new SearchResult(new DocumentRange(60, 65), 1, markedCount));
    found = findImpl(context);
    assertTrue(found);
    assertSelected("chuck", 32, context.getMatchCase());
    assertResult(new SearchResult(new DocumentRange(32, 37), 1, markedCount));
    found = findImpl(context);
    assertFalse(found);
    assertResult(new SearchResult(null, 0, markedCount));

    // Search for "wood", matching case, whole word
    context.setSearchFor("wood");
    markedCount = markAll ? 1 : 0;
    context.setMatchCase(true);
    context.setWholeWord(true);
    textArea.setCaretPosition(end);
    found = findImpl(context);
    assertTrue(found);
    assertSelected("wood", 9, context.getMatchCase());
    assertResult(new SearchResult(new DocumentRange(9, 13), 1, markedCount));
    found = findImpl(context);
    assertFalse(found);
    assertResult(new SearchResult(null, 0, markedCount));

    // Search for ".ould", regex, ignoring case
    context.setSearchFor(".ould");
    markedCount = markAll ? 2 : 0;
    context.setMatchCase(false);
    context.setWholeWord(false);
    context.setRegularExpression(true);
    textArea.setCaretPosition(end);
    found = findImpl(context);
    assertTrue(found);
    assertSelected("could", 54, true);
    assertResult(new SearchResult(new DocumentRange(54, 59), 1, markedCount));
    found = findImpl(context);
    assertTrue(found);
    assertSelected("wOuld", 14, true);
    assertResult(new SearchResult(new DocumentRange(14, 19), 1, markedCount));
    found = findImpl(context);
    assertFalse(found);
    assertResult(new SearchResult(null, 0, markedCount));

    // Search for ".ould", regex, matching case
    context.setSearchFor(".ould");
    markedCount = markAll ? 1 : 0;
    context.setMatchCase(true);
    context.setWholeWord(false);
    context.setRegularExpression(true);
    textArea.setCaretPosition(end);
    found = findImpl(context);
    assertTrue(found);
    assertSelected("could", 54, true);
    assertResult(new SearchResult(new DocumentRange(54, 59), 1, markedCount));
    found = findImpl(context);
    assertFalse(found);
    assertResult(new SearchResult(null, 0, markedCount));

    // Search for "[cd]huck", regex, ignoring case, whole word
    context.setSearchFor("[cd]hUCk");
    markedCount = markAll ? 2 : 0;
    context.setMatchCase(false);
    context.setWholeWord(true);
    context.setRegularExpression(true);
    textArea.setCaretPosition(end);
    found = findImpl(context);
    assertTrue(found);
    assertSelected("chuck", 60, context.getMatchCase());
    assertResult(new SearchResult(new DocumentRange(60, 65), 1, markedCount));
    found = findImpl(context);
    assertTrue(found);
    assertSelected("chuck", 32, context.getMatchCase());
    assertResult(new SearchResult(new DocumentRange(32, 37), 1, markedCount));
    found = findImpl(context);
    assertFalse(found);
    assertResult(new SearchResult(null, 0, markedCount));

    // Search for "[cd]huck", regex, matching case, whole word
    context.setSearchFor("[cd]huck");
    markedCount = markAll ? 1 : 0;
    context.setMatchCase(true);
    context.setWholeWord(true);
    context.setRegularExpression(true);
    textArea.setCaretPosition(end);
    found = findImpl(context);
    assertTrue(found);
    assertSelected("chuck", 60, true);
    assertResult(new SearchResult(new DocumentRange(60, 65), 1, markedCount));
    found = findImpl(context);
    assertFalse(found);
    assertResult(new SearchResult(null, 0, markedCount));

  }
View Full Code Here

    context.setSearchFor("chuck");
    int markedCount = markAll ? 4 : 0;
    boolean found = findImpl(context);
    assertTrue(found);
    assertSelected("chuck", 26, context.getMatchCase());
    assertResult(new SearchResult(new DocumentRange(26, 31), 1, markedCount));
    found = findImpl(context);
    assertTrue(found);
    assertSelected("chuck", 32, context.getMatchCase());
    assertResult(new SearchResult(new DocumentRange(32, 37), 1, markedCount));
    found = findImpl(context);
    assertTrue(found);
    assertSelected("chuck", 48, context.getMatchCase());
    assertResult(new SearchResult(new DocumentRange(48, 53), 1, markedCount));
    found = findImpl(context);
    assertTrue(found);
    assertSelected("chuck", 60, context.getMatchCase());
    assertResult(new SearchResult(new DocumentRange(60, 65), 1, markedCount));
    found = findImpl(context);
    assertFalse(found);
    assertResult(new SearchResult(null, 0, markedCount));

    // Search for "Chuck", matching case.
    context.setSearchFor("Chuck");
    markedCount = markAll ? 1 : 0;
    context.setMatchCase(true);
    textArea.setCaretPosition(0);
    found = findImpl(context);
    assertTrue(found);
    assertSelected("Chuck", 26, context.getMatchCase());
    assertResult(new SearchResult(new DocumentRange(26, 31), 1, markedCount));
    found = findImpl(context);
    assertFalse(found);
    assertResult(new SearchResult(null, 0, markedCount));

    // Search for "chuck", ignoring case, whole word
    context.setSearchFor("chuck");
    markedCount = markAll ? 2 : 0;
    context.setMatchCase(false);
    context.setWholeWord(true);
    textArea.setCaretPosition(0);
    found = findImpl(context);
    assertTrue(found);
    assertSelected("chuck", 32, context.getMatchCase());
    assertResult(new SearchResult(new DocumentRange(32, 37), 1, markedCount));
    found = findImpl(context);
    assertTrue(found);
    assertSelected("chuck", 60, context.getMatchCase());
    assertResult(new SearchResult(new DocumentRange(60, 65), 1, markedCount));
    found = findImpl(context);
    assertFalse(found);
    assertResult(new SearchResult(null, 0, markedCount));

    // Search for "wood", matching case, whole word
    context.setSearchFor("wood");
    markedCount = markAll ? 1 : 0;
    context.setMatchCase(true);
    context.setWholeWord(true);
    textArea.setCaretPosition(0);
    found = findImpl(context);
    assertTrue(found);
    assertSelected("wood", 9, context.getMatchCase());
    assertResult(new SearchResult(new DocumentRange(9, 13), 1, markedCount));
    found = findImpl(context);
    assertFalse(found);
    assertResult(new SearchResult(null, 0, markedCount));

    // Search for ".ould", regex, ignoring case
    context.setSearchFor(".ould");
    markedCount = markAll ? 2 : 0;
    context.setMatchCase(false);
    context.setWholeWord(false);
    context.setRegularExpression(true);
    textArea.setCaretPosition(0);
    found = findImpl(context);
    assertTrue(found);
    assertSelected("wOuld", 14, true);
    assertResult(new SearchResult(new DocumentRange(14, 19), 1, markedCount));
    found = findImpl(context);
    assertTrue(found);
    assertSelected("could", 54, true);
    assertResult(new SearchResult(new DocumentRange(54, 59), 1, markedCount));
    found = findImpl(context);
    assertFalse(found);
    assertResult(new SearchResult(null, 0, markedCount));

    // Search for ".ould", regex, matching case
    context.setSearchFor(".ould");
    markedCount = markAll ? 1 : 0;
    context.setMatchCase(true);
    context.setWholeWord(false);
    context.setRegularExpression(true);
    textArea.setCaretPosition(0);
    found = findImpl(context);
    assertTrue(found);
    assertSelected("could", 54, true);
    assertResult(new SearchResult(new DocumentRange(54, 59), 1, markedCount));
    found = findImpl(context);
    assertFalse(found);
    assertResult(new SearchResult(null, 0, markedCount));

    // Search for "[cd]huck", regex, ignoring case, whole word
    context.setSearchFor("[cd]hUCk");
    markedCount = markAll ? 2 : 0;
    context.setMatchCase(false);
    context.setWholeWord(true);
    context.setRegularExpression(true);
    textArea.setCaretPosition(0);
    found = findImpl(context);
    assertTrue(found);
    assertSelected("chuck", 32, context.getMatchCase());
    assertResult(new SearchResult(new DocumentRange(32, 37), 1, markedCount));
    found = findImpl(context);
    assertTrue(found);
    assertSelected("chuck", 60, context.getMatchCase());
    assertResult(new SearchResult(new DocumentRange(60, 65), 1, markedCount));
    found = findImpl(context);
    assertFalse(found);
    assertResult(new SearchResult(null, 0, markedCount));

    // Search for "[cd]huck", regex, matching case, whole word
    context.setSearchFor("[cd]huck");
    markedCount = markAll ? 1 : 0;
    context.setMatchCase(true);
    context.setWholeWord(true);
    context.setRegularExpression(true);
    textArea.setCaretPosition(0);
    found = findImpl(context);
    assertTrue(found);
    assertSelected("chuck", 60, true);
    assertResult(new SearchResult(new DocumentRange(60, 65), 1, markedCount));
    found = findImpl(context);
    assertFalse(found);
    assertResult(new SearchResult(null, 0, markedCount));

  }
View Full Code Here

    String searchFor = "[how]{3}|";
    SearchContext context = new SearchContext(searchFor);
    context.setRegularExpression(true);

    assertTrue(findImpl(context));
    assertResult(new SearchResult(new DocumentRange(0, 3), 1, 4));
    assertTrue(findImpl(context));
    assertResult(new SearchResult(new DocumentRange(8, 11), 1, 4));
    assertTrue(findImpl(context));
    assertResult(new SearchResult(new DocumentRange(27, 30), 1, 4));
    assertTrue(findImpl(context));
    assertResult(new SearchResult(new DocumentRange(30, 33), 1, 4));
    assertFalse(findImpl(context));

  }
View Full Code Here

TOP

Related Classes of org.fife.ui.rsyntaxtextarea.DocumentRange

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.