Exemplo n.º 1
0
  public int search(
      @NotNull Editor editor, @NotNull String command, int startOffset, int count, int flags) {
    int dir = 1;
    char type = '/';
    String pattern = lastSearch;
    String offset = lastOffset;
    if ((flags & Command.FLAG_SEARCH_REV) != 0) {
      dir = -1;
      type = '?';
    }

    if (command.length() > 0) {
      if (command.charAt(0) != type) {
        CharPointer p = new CharPointer(command);
        CharPointer end = RegExp.skip_regexp(p.ref(0), type, true);
        pattern = p.substring(end.pointer() - p.pointer());
        if (logger.isDebugEnabled()) logger.debug("pattern=" + pattern);
        if (p.charAt() != type) {
          logger.debug("no offset");
          offset = "";
        } else {
          p.inc();
          offset = p.toString();
          if (logger.isDebugEnabled()) logger.debug("offset=" + offset);
        }
      } else if (command.length() == 1) {
        offset = "";
      } else {
        offset = command.substring(1);
        if (logger.isDebugEnabled()) logger.debug("offset=" + offset);
      }
    }

    lastSearch = pattern;
    if (pattern != null) {
      setLastPattern(editor, pattern);
    }
    lastOffset = offset;
    lastDir = dir;

    if (logger.isDebugEnabled()) {
      logger.debug("lastSearch=" + lastSearch);
      logger.debug("lastOffset=" + lastOffset);
      logger.debug("lastDir=" + lastDir);
    }

    searchHighlight(false);

    return findItOffset(editor, startOffset, count, lastDir, false);
  }