Exemplo n.º 1
0
 @Override
 @NotNull
 public LogicalPosition offsetToLogicalPosition(final int offset, boolean softWrapAware) {
   assert isValid();
   int lineNumber = myDocumentWindow.getLineNumber(offset);
   int lineStartOffset = myDocumentWindow.getLineStartOffset(lineNumber);
   int column = calcLogicalColumnNumber(offset - lineStartOffset, lineNumber, lineStartOffset);
   return new LogicalPosition(lineNumber, column);
 }
Exemplo n.º 2
0
 private LogicalPosition fitInsideEditor(LogicalPosition pos) {
   int lineCount = myDocumentWindow.getLineCount();
   if (pos.line >= lineCount) {
     pos = new LogicalPosition(lineCount - 1, pos.column);
   }
   int lineLength =
       myDocumentWindow.getLineEndOffset(pos.line) - myDocumentWindow.getLineStartOffset(pos.line);
   if (pos.column >= lineLength) {
     pos = new LogicalPosition(pos.line, Math.max(0, lineLength - 1));
   }
   return pos;
 }
Exemplo n.º 3
0
  @NotNull
  public LogicalPosition injectedToHost(@NotNull LogicalPosition pos) {
    assert isValid();
    // beware the virtual space
    int column = pos.column;
    int lineStartOffset = myDocumentWindow.getLineStartOffset(pos.line);
    int lineEndOffset = myDocumentWindow.getLineEndOffset(pos.line);
    if (column > lineEndOffset - lineStartOffset) {
      // in virtual space, calculate the host pos as an offset from the line end
      int delta = column - (lineEndOffset - lineStartOffset);

      int baseOffsetInHost = myDocumentWindow.injectedToHost(lineEndOffset);
      LogicalPosition lineStartPosInHost = myDelegate.offsetToLogicalPosition(baseOffsetInHost);
      return new LogicalPosition(lineStartPosInHost.line, lineStartPosInHost.column + delta);
    } else {
      int offset = lineStartOffset + column;
      int hostOffset = getDocument().injectedToHost(offset);
      int hostLineNumber = getDocument().getDelegate().getLineNumber(hostOffset);
      int hostLineStart = getDocument().getDelegate().getLineStartOffset(hostLineNumber);

      return new LogicalPosition(hostLineNumber, hostOffset - hostLineStart);
    }
  }
Exemplo n.º 4
0
 @Override
 public int logicalPositionToOffset(@NotNull final LogicalPosition pos) {
   int lineStartOffset = myDocumentWindow.getLineStartOffset(pos.line);
   return calcOffset(pos.column, pos.line, lineStartOffset);
 }