const CodeDocument::Position CodeEditorComponent::getPositionAt (int x, int y) { const int line = y / lineHeight + firstLineOnScreen; const int column = roundToInt ((x - (gutter - xOffset * charWidth)) / charWidth); const int index = columnToIndex (line, column); return CodeDocument::Position (&document, line, index); }
void CodeEditorComponent::moveLineDelta (const int delta, const bool selecting) { CodeDocument::Position pos (caretPos); const int newLineNum = pos.getLineNumber() + delta; if (columnToTryToMaintain < 0) columnToTryToMaintain = indexToColumn (pos.getLineNumber(), pos.getIndexInLine()); pos.setLineAndIndex (newLineNum, columnToIndex (newLineNum, columnToTryToMaintain)); const int colToMaintain = columnToTryToMaintain; moveCaretTo (pos, selecting); columnToTryToMaintain = colToMaintain; }
bool CodeEditorComponent::skipBackwardsToPreviousTab() { const String currentLineText (caretPos.getLineText().removeCharacters ("\r\n")); const int currentIndex = caretPos.getIndexInLine(); if (currentLineText.isNotEmpty() && currentLineText.length() == currentIndex) { const int currentLine = caretPos.getLineNumber(); const int currentColumn = indexToColumn (currentLine, currentIndex); const int previousTabColumn = (currentColumn - 1) - ((currentColumn - 1) % spacesPerTab); const int previousTabIndex = columnToIndex (currentLine, previousTabColumn); if (currentLineText.substring (previousTabIndex, currentIndex).trim().isEmpty()) { selectionStart.moveBy (previousTabIndex - currentIndex); return true; } } return false; }