Logo Search packages:      
Sourcecode: ktikz version File versions  Download package

QString TikzEditor::textUnderCursor (  ) const [private]

Determines the word on which the cursor is positioned (necessary for completion).

Definition at line 399 of file tikzeditor.cpp.

{
      QTextCursor cursor = textCursor();
      const int oldPos = cursor.position();
//    cursor.select(QTextCursor::WordUnderCursor);
//    const int newPos = cursor.selectionStart();
      int newPos;
      for (newPos = oldPos; newPos > 0;) // move the cursor to the beginning of the word
      {
            cursor.setPosition(--newPos, QTextCursor::KeepAnchor);
            if (cursor.selectedText().trimmed().isEmpty()) // if the current char is a whitespace, then we have reached the beginning of the word
            {
                  cursor.clearSelection();
                  cursor.setPosition(++newPos, QTextCursor::MoveAnchor);
                  break;
            }
            else if (cursor.selectedText() == "\\" || cursor.atBlockStart()) // these characters also delimit the beginning of the word (the beginning of a TikZ command)
            {
                  cursor.clearSelection();
                  break;
            }
            else if (cursor.selectedText() == "["
                || cursor.selectedText() == ",") // these characters also delimit the beginning of the word (the beginning of a TikZ option)
            {
                  cursor.clearSelection();
                  cursor.setPosition(++newPos, QTextCursor::MoveAnchor);
                  break;
            }
            cursor.clearSelection();
      }
//    cursor.setPosition(newPos, QTextCursor::MoveAnchor);
      cursor.setPosition(oldPos, QTextCursor::KeepAnchor);
      QString word = cursor.selectedText();
//    if (word.right(1) != word.trimmed().right(1))
//          word = "";
      return word;
}

Generated by  Doxygen 1.6.0   Back to index