JUCE  v5.1.1-3-g1a0b28c73
JUCE API
CodeDocument::Position Class Reference

A position in a code document. More...

#include <juce_CodeDocument.h>

Collaboration diagram for CodeDocument::Position:

Public Member Functions

 Position () noexcept
 Creates an uninitialised position. More...
 
 Position (const CodeDocument &ownerDocument, int line, int indexInLine) noexcept
 Creates a position based on a line and index in a document. More...
 
 Position (const CodeDocument &ownerDocument, int charactersFromStartOfDocument) noexcept
 Creates a position based on a character index in a document. More...
 
 Position (const Position &) noexcept
 Creates a copy of another position. More...
 
 ~Position ()
 Destructor. More...
 
juce_wchar getCharacter () const
 Returns the character in the document at this position. More...
 
int getIndexInLine () const noexcept
 Returns the number of characters from the start of the line. More...
 
int getLineNumber () const noexcept
 Returns the line number of this position. More...
 
String getLineText () const
 Returns the line from the document that this position is within. More...
 
int getPosition () const noexcept
 Returns the position as the number of characters from the start of the document. More...
 
void moveBy (int characterDelta)
 Moves the position forwards or backwards by the specified number of characters. More...
 
Position movedBy (int characterDelta) const
 Returns a position which is the same as this one, moved by the specified number of characters. More...
 
Position movedByLines (int deltaLines) const
 Returns a position which is the same as this one, moved up or down by the specified number of lines. More...
 
bool operator!= (const Position &) const noexcept
 
Positionoperator= (const Position &)
 
bool operator== (const Position &) const noexcept
 
void setLineAndIndex (int newLineNumber, int newIndexInLine)
 Moves the position to a new line and index within the line. More...
 
void setPosition (int charactersFromStartOfDocument)
 Points this object at a new position within the document. More...
 
void setPositionMaintained (bool isMaintained)
 Allows the position to be automatically updated when the document changes. More...
 

Private Attributes

int characterPos
 
int indexInLine
 
int line
 
CodeDocumentowner
 
bool positionMaintained
 

Detailed Description

A position in a code document.

Using this class you can find a position in a code document and quickly get its character position, line, and index. By calling setPositionMaintained (true), the position is automatically updated when text is inserted or deleted in the document, so that it maintains its original place in the text.

Constructor & Destructor Documentation

◆ Position() [1/4]

CodeDocument::Position::Position ( )
noexcept

Creates an uninitialised position.

Don't attempt to call any methods on this until you've given it an owner document to refer to!

◆ Position() [2/4]

CodeDocument::Position::Position ( const CodeDocument ownerDocument,
int  line,
int  indexInLine 
)
noexcept

Creates a position based on a line and index in a document.

Note that this index is NOT the column number, it's the number of characters from the start of the line. The "column" number isn't quite the same, because if the line contains any tab characters, the relationship of the index to its visual column depends on the number of spaces per tab being used!

Lines are numbered from zero, and if the line or index are beyond the bounds of the document, they will be adjusted to keep them within its limits.

◆ Position() [3/4]

CodeDocument::Position::Position ( const CodeDocument ownerDocument,
int  charactersFromStartOfDocument 
)
noexcept

Creates a position based on a character index in a document.

This position is placed at the specified number of characters from the start of the document. The line and column are auto-calculated.

If the position is beyond the range of the document, it'll be adjusted to keep it inside.

◆ Position() [4/4]

CodeDocument::Position::Position ( const Position )
noexcept

Creates a copy of another position.

This will copy the position, but the new object will not be set to maintain its position, even if the source object was set to do so.

◆ ~Position()

CodeDocument::Position::~Position ( )

Destructor.

Member Function Documentation

◆ getCharacter()

juce_wchar CodeDocument::Position::getCharacter ( ) const

Returns the character in the document at this position.

See also
getLineText

◆ getIndexInLine()

int CodeDocument::Position::getIndexInLine ( ) const
inlinenoexcept

Returns the number of characters from the start of the line.

Note that this value is NOT the column at which the position appears in an editor. If the line contains any tab characters, the relationship of the index to its visual position depends on the number of spaces per tab being used!

◆ getLineNumber()

int CodeDocument::Position::getLineNumber ( ) const
inlinenoexcept

Returns the line number of this position.

The first line in the document is numbered zero, not one!

◆ getLineText()

String CodeDocument::Position::getLineText ( ) const

Returns the line from the document that this position is within.

See also
getCharacter, getLineNumber

◆ getPosition()

int CodeDocument::Position::getPosition ( ) const
inlinenoexcept

Returns the position as the number of characters from the start of the document.

See also
setPosition, getLineNumber, getIndexInLine

◆ moveBy()

void CodeDocument::Position::moveBy ( int  characterDelta)

Moves the position forwards or backwards by the specified number of characters.

See also
movedBy

◆ movedBy()

Position CodeDocument::Position::movedBy ( int  characterDelta) const

Returns a position which is the same as this one, moved by the specified number of characters.

See also
moveBy

◆ movedByLines()

Position CodeDocument::Position::movedByLines ( int  deltaLines) const

Returns a position which is the same as this one, moved up or down by the specified number of lines.

See also
movedBy

◆ operator!=()

bool CodeDocument::Position::operator!= ( const Position ) const
noexcept

◆ operator=()

Position& CodeDocument::Position::operator= ( const Position )

◆ operator==()

bool CodeDocument::Position::operator== ( const Position ) const
noexcept

◆ setLineAndIndex()

void CodeDocument::Position::setLineAndIndex ( int  newLineNumber,
int  newIndexInLine 
)

Moves the position to a new line and index within the line.

Note that the index is NOT the column at which the position appears in an editor. If the line contains any tab characters, the relationship of the index to its visual position depends on the number of spaces per tab being used!

Lines are numbered from zero, and if the line or index are beyond the bounds of the document, they will be adjusted to keep them within its limits.

◆ setPosition()

void CodeDocument::Position::setPosition ( int  charactersFromStartOfDocument)

Points this object at a new position within the document.

If the position is beyond the range of the document, it'll be adjusted to keep it inside.

See also
getPosition, setLineAndIndex

◆ setPositionMaintained()

void CodeDocument::Position::setPositionMaintained ( bool  isMaintained)

Allows the position to be automatically updated when the document changes.

If this is set to true, the position will register with its document so that when the document has text inserted or deleted, this position will be automatically moved to keep it at the same position in the text.

Member Data Documentation

◆ characterPos

int CodeDocument::Position::characterPos
private

◆ indexInLine

int CodeDocument::Position::indexInLine
private

◆ line

int CodeDocument::Position::line
private

◆ owner

CodeDocument* CodeDocument::Position::owner
private

◆ positionMaintained

bool CodeDocument::Position::positionMaintained
private

The documentation for this class was generated from the following file: