22 #include "katecursor.h"
24 #include "katedocument.h"
25 #include "katetextline.h"
31 KateDocCursor::KateDocCursor(KateDocument *doc) :
KateTextCursor(), m_doc(doc)
35 KateDocCursor::KateDocCursor(
int line,
int col, KateDocument *doc)
40 bool KateDocCursor::validPosition(uint line, uint col)
42 return line < m_doc->numLines() && (int)col <= m_doc->lineLength(line);
45 bool KateDocCursor::validPosition()
47 return validPosition(line(), col());
50 void KateDocCursor::position(uint *pline, uint *pcol)
const
53 *pline = (uint)line();
59 bool KateDocCursor::setPosition(uint line, uint col)
61 bool ok = validPosition(line, col);
69 bool KateDocCursor::gotoNextLine()
71 bool ok = (line() + 1 < (int)m_doc->numLines());
81 bool KateDocCursor::gotoPreviousLine()
83 bool ok = (line() > 0);
93 bool KateDocCursor::gotoEndOfNextLine()
95 bool ok = gotoNextLine();
97 m_col = m_doc->lineLength(line());
102 bool KateDocCursor::gotoEndOfPreviousLine()
104 bool ok = gotoPreviousLine();
106 m_col = m_doc->lineLength(line());
111 int KateDocCursor::nbCharsOnLineAfter()
113 return ((
int)m_doc->lineLength(line()) - col());
116 bool KateDocCursor::moveForward(uint nbChar)
118 int nbCharLeft = nbChar - nbCharsOnLineAfter();
121 return gotoNextLine() && moveForward((uint)nbCharLeft);
128 bool KateDocCursor::moveBackward(uint nbChar)
130 int nbCharLeft = nbChar - m_col;
132 return gotoEndOfPreviousLine() && moveBackward((uint)nbCharLeft);
139 bool KateDocCursor::insertText(
const TQString& s)
141 return m_doc->insertText(line(), col(), s);
144 bool KateDocCursor::removeText(uint nbChar)
148 endCursor.moveForward(nbChar);
151 return m_doc->removeText((uint)line(), (uint)col(),
152 (uint)endCursor.line(), (uint)endCursor.col());
155 TQChar KateDocCursor::currentChar()
const
157 return m_doc->plainKateTextLine(line())->getChar(col());
160 uchar KateDocCursor::currentAttrib()
const
162 return m_doc->plainKateTextLine(line())->attribute(col());
167 for(; m_line < (int)m_doc->numLines(); m_line++) {
181 m_col = m_doc->plainKateTextLine(line())->previousNonSpaceChar(col());
182 if(m_col != -1)
return true;
183 if(m_line == 0)
return false;
185 m_col = m_doc->plainKateTextLine(m_line)->length();
Cursor class with a pointer to its document.
bool previousNonSpaceChar()
Find the position (line and col) of the previous char that is not a space.
bool nextNonSpaceChar()
Find the position (line and col) of the next char that is not a space.
Simple cursor class with no document pointer.