TextEditor: Introduce some convenience text accessors in the editor

And adjust users.

Change-Id: I9329257cfa5f3298731deb07c2881bc37d9a051d
Reviewed-by: Christian Stenger <christian.stenger@digia.com>
This commit is contained in:
hjk
2014-08-27 11:57:32 +02:00
parent d2c243464e
commit 2a5c602341
19 changed files with 111 additions and 104 deletions

View File

@@ -105,42 +105,41 @@ void CMakeEditor::build()
QString CMakeEditor::contextHelpId() const
{
int pos = position();
BaseTextDocument *doc = const_cast<CMakeEditor*>(this)->textDocument();
QChar chr;
do {
--pos;
if (pos < 0)
break;
chr = doc->characterAt(pos);
chr = characterAt(pos);
if (chr == QLatin1Char('('))
return QString();
} while (chr.unicode() != QChar::ParagraphSeparator);
++pos;
chr = doc->characterAt(pos);
chr = characterAt(pos);
while (chr.isSpace()) {
++pos;
chr = doc->characterAt(pos);
chr = characterAt(pos);
}
int begin = pos;
do {
++pos;
chr = doc->characterAt(pos);
chr = characterAt(pos);
} while (chr.isLetterOrNumber() || chr == QLatin1Char('_'));
int end = pos;
while (chr.isSpace()) {
++pos;
chr = doc->characterAt(pos);
chr = characterAt(pos);
}
// Not a command
if (chr != QLatin1Char('('))
return QString();
QString command = doc->textAt(begin, end - begin).toLower();
QString command = textAt(begin, end - begin).toLower();
return QLatin1String("command/") + command;
}