예제 #1
0
 @Override
 public TextRange rightDelimiter(EditorAdaptor editorAdaptor, int count)
     throws CommandExecutionException {
   TextRange result = super.rightDelimiter(editorAdaptor, count);
   int offset = result.getLeftBound().getModelOffset();
   TextContent modelContent = editorAdaptor.getModelContent();
   int beginOffset = modelContent.getLineInformationOfOffset(offset).getBeginOffset();
   int length = offset - beginOffset;
   String content = modelContent.getText(beginOffset, length);
   int i = length - 1;
   while (Character.isWhitespace(content.charAt(i))) {
     if (--i < 0) return result;
   }
   return new StartEndTextRange(
       result.getLeftBound().addModelOffset(i - length + 1), result.getRightBound());
 }
예제 #2
0
 @Override
 public TextRange leftDelimiter(EditorAdaptor editorAdaptor, int count)
     throws CommandExecutionException {
   TextRange result = super.leftDelimiter(editorAdaptor, count);
   int offset = result.getRightBound().getModelOffset();
   TextContent modelContent = editorAdaptor.getModelContent();
   int length = modelContent.getLineInformationOfOffset(offset).getEndOffset() - offset;
   String content = modelContent.getText(offset, length);
   int i = 0;
   while (Character.isWhitespace(content.charAt(i))) if (++i == length) return result;
   return new StartEndTextRange(result.getLeftBound(), result.getRightBound().addModelOffset(i));
 }
예제 #3
0
  void execute(EditorAdaptor editorAdaptor, TextRange region, int count)
      throws CommandExecutionException {
    try {
      String action =
          left
              ? ITextEditorActionDefinitionIds.SHIFT_LEFT
              : ITextEditorActionDefinitionIds.SHIFT_RIGHT;
      editorAdaptor.getHistory().beginCompoundChange();
      editorAdaptor.getHistory().lock();
      TextContent modelContent = editorAdaptor.getModelContent();
      int startOffset = region.getLeftBound().getModelOffset();
      int startLine;
      // if the start is on a newline, put start on the next line
      // (otherwise, >i{ will indent the line ending with a '{')
      if (VimUtils.isNewLine(modelContent.getText(startOffset, 1))) {
        startLine = modelContent.getLineInformationOfOffset(startOffset).getNumber() + 1;
      } else {
        startLine = modelContent.getLineInformationOfOffset(startOffset).getNumber();
      }

      int rightBoundOffset = region.getRightBound().getModelOffset();
      LineInformation endLineInformation =
          modelContent.getLineInformationOfOffset(rightBoundOffset);
      String endText =
          modelContent.getText(
              endLineInformation.getBeginOffset(),
              rightBoundOffset - endLineInformation.getBeginOffset());
      int endLine = endLineInformation.getNumber();
      if (rightBoundOffset > endLineInformation.getBeginOffset() && !endText.matches("\\s*")) {
        // if the right bound is beyond the first character of a line, include that entire line
        // (unless everything within the bounds of this line is whitespace)
        endLine++;
      }
      for (int i = 0; i < count; i++) {
        editorAdaptor.setSelection(createSelection(editorAdaptor, startLine, endLine));
        EclipseCommand.doIt(1, action, editorAdaptor);
      }
      editorAdaptor.setPosition(
          editorAdaptor
              .getCursorService()
              .newPositionForModelOffset(
                  VimUtils.getFirstNonWhiteSpaceOffset(
                      modelContent, modelContent.getLineInformation(startLine))),
          true);
    } finally {
      editorAdaptor.getHistory().unlock();
      editorAdaptor.getHistory().endCompoundChange();
    }
  }