private int calcOffset(int col, int lineNumber, int lineStartOffset) { if (myDocumentWindow.getTextLength() == 0) return 0; int end = myDocumentWindow.getLineEndOffset(lineNumber); CharSequence text = myDocumentWindow.getCharsSequence(); return EditorUtil.calcOffset( this, text, lineStartOffset, end, col, EditorUtil.getTabSize(myDelegate), null); }
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; }
private int calcLogicalColumnNumber(int offsetInLine, int lineNumber, int lineStartOffset) { if (myDocumentWindow.getTextLength() == 0) return 0; if (offsetInLine == 0) return 0; int end = myDocumentWindow.getLineEndOffset(lineNumber); if (offsetInLine > end - lineStartOffset) offsetInLine = end - lineStartOffset; CharSequence text = myDocumentWindow.getCharsSequence(); return EditorUtil.calcColumnNumber( this, text, lineStartOffset, lineStartOffset + offsetInLine, EditorUtil.getTabSize(myDelegate)); }
@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); } }