Exemple #1
0
 /**
  * Vim doesn't start a delimited range on a newline or end a range on an empty line (try 'vi{'
  * while within a function for proof).
  */
 public static Position fixLeftDelimiter(TextContent model, CursorService cursor, Position delim) {
   // check if the character after delimiter is a newline
   if (isNewLine(model.getText(delim.getModelOffset() + 1, 1))) {
     // start after newline
     LineInformation line = model.getLineInformationOfOffset(delim.getModelOffset());
     LineInformation nextLine = model.getLineInformation(line.getNumber() + 1);
     delim = cursor.newPositionForModelOffset(nextLine.getBeginOffset());
   } else {
     delim = delim.addModelOffset(1);
   }
   return delim;
 }
Exemple #2
0
 /**
  * Calculates an offset position. Line breaks are not counted.
  *
  * @param position TODO
  */
 public static int calculatePositionForOffset(
     final TextContent p, int position, final int offset) {
   LineInformation line = p.getLineInformationOfOffset(position);
   if (offset < 0) {
     int i = -offset;
     while (i > 0) {
       if (position > line.getBeginOffset()) {
         position -= 1;
       } else {
         final int nextLine = line.getNumber() - 1;
         if (nextLine < 0) {
           break;
         }
         line = p.getLineInformation(nextLine);
         position = Math.max(line.getBeginOffset(), line.getEndOffset() - 1);
       }
       i -= 1;
     }
   } else if (offset > 0) {
     int i = offset;
     int end = Math.max(line.getBeginOffset(), line.getEndOffset() - 1);
     while (i > 0) {
       if (position < end) {
         position += 1;
       } else {
         final int nextLine = line.getNumber() + 1;
         if (nextLine > p.getNumberOfLines() - 1) {
           break;
         }
         line = p.getLineInformation(nextLine);
         end = Math.max(line.getBeginOffset(), line.getEndOffset() - 1);
         position = line.getBeginOffset();
       }
       i -= 1;
     }
   }
   return position;
 }
Exemple #3
0
  public static Position fixRightDelimiter(
      TextContent model, CursorService cursor, Position delim) {
    int delimIndex = delim.getModelOffset();
    LineInformation line = model.getLineInformationOfOffset(delimIndex);
    int lineStart = line.getBeginOffset();

    if (delimIndex > lineStart) {
      // is everything before the delimiter just whitespace?
      String text = model.getText(lineStart, delimIndex - lineStart);
      if (VimUtils.isBlank(text)) {
        // end on previous line
        LineInformation previousLine = model.getLineInformation(line.getNumber() - 1);
        delimIndex = previousLine.getEndOffset();
        delim = cursor.newPositionForModelOffset(delimIndex);
      }
    }
    return delim;
  }
Exemple #4
0
 public static int calculateLine(final TextContent text, final int offset) {
   final LineInformation line = text.getLineInformationOfOffset(offset);
   return line.getNumber();
 }
Exemple #5
0
 /** @return true, if the last character in the text buffer is newline */
 public static boolean endsWithEOL(final EditorAdaptor editor) {
   final TextContent content = editor.getModelContent();
   final LineInformation line = content.getLineInformation(content.getNumberOfLines() - 1);
   return line.getNumber() > 0 && line.getLength() == 0;
 }