Esempio n. 1
0
  LeafBlockWrapper getOffsetRespBlockBefore(final LeafBlockWrapper block) {
    LeafBlockWrapper result = null;
    if (myOffsetRespBlocks != EMPTY) {
      LeafBlockWrapper lastBlockAfterLineFeed = null;
      LeafBlockWrapper firstAlignedBlock = null;
      LeafBlockWrapper lastAlignedBlock = null;
      for (Iterator<LeafBlockWrapper> each = myOffsetRespBlocks.iterator(); each.hasNext(); ) {
        final LeafBlockWrapper current = each.next();
        if (block == null || current.getStartOffset() < block.getStartOffset()) {
          if (firstAlignedBlock == null
              || firstAlignedBlock.getStartOffset() > current.getStartOffset()) {
            firstAlignedBlock = current;
          }

          if (lastAlignedBlock == null
              || lastAlignedBlock.getStartOffset() < current.getStartOffset()) {
            lastAlignedBlock = current;
          }

          if (current.getWhiteSpace().containsLineFeeds()
              && (lastBlockAfterLineFeed == null
                  || lastBlockAfterLineFeed.getStartOffset() < current.getStartOffset())) {
            lastBlockAfterLineFeed = current;
          }
        }
        // each.remove();
      }
      if (lastBlockAfterLineFeed != null) {
        result = lastBlockAfterLineFeed;
      } else if (firstAlignedBlock != null) {
        result = firstAlignedBlock;
      } else {
        result = lastAlignedBlock;
      }
    }
    if (result == null && myParentAlignment != null) {
      return myParentAlignment.getOffsetRespBlockBefore(block);
    } else {
      return result;
    }
  }