Commit 24e0cd60 authored by Tomas Mecir's avatar Tomas Mecir

make tab completion work with new console

parent 7afa8ee4
......@@ -314,11 +314,32 @@ void cConsole::setHistorySize (int size) {
d->historySize = size;
}
// grab all the words from the last 100 lines that meet the prefix/length criteria
QStringList cConsole::words (QString prefix, int minLength) {
QStringList res;
// TODO
int lineLimit = 100;
int lines = 0;
QTextBlock block = d->text->lastBlock();
while ((block != d->text->firstBlock()) && (lines < lineLimit)) {
lines += block.lineCount();
QString text = block.text();
// split the text into words
QStringList words = text.split (QRegExp ("[\\s\\.\\,\\(\\)\\[\\]\\?\\!\\:\\;\"\']"));
//store words that meet the requirements
for (QString word : words) {
if (word.length() < minLength) continue;
if ((!prefix.isEmpty()) && (!word.startsWith (prefix, Qt::CaseInsensitive))) continue;
// case-sensitive comparison here, so we store all the used upper/lowercase variants
if (res.contains (word)) continue;
res.push_back (word);
}
block = block.previous();
}
// We intentionally don't sort the list.
return res;
}
......@@ -353,7 +374,6 @@ void cConsole::addNewText (cTextChunk *chunk, bool endTheLine)
}
if (endTheLine) d->wantNewLine = true;
// TODO - if the buffer is full, remove old blocks/lines
while (totalLines() > d->historySize) {
// check the height of the first block; if removing it won't put us below the history limit, remove it
QTextBlock fblock = d->text->firstBlock();
......
......@@ -390,11 +390,15 @@ void cInputLine::handleTabExpansion ()
if (expandPos == cursorPos + 1)
return; //do nothing if we're at a space
// find the next space - we want to remove the entire word if we are in the middle of one
int wordEnd = t.indexOf (' ', cursorPos);
int wordLength = ((wordEnd > 0) ? wordEnd : t.length()) - expandPos;
//find prefix and get list of all matching words
QString prefix = t.mid (expandPos, cursorPos - expandPos + 1);
int prefixLen = prefix.length();
if (prefixLen < 2)
return;
if (prefixLen < 2) return;
cOutput *output = dynamic_cast<cOutput *>(object ("output"));
tabWords = output->console()->words (prefix);
if (tabWords.count() == 0)
......@@ -403,8 +407,8 @@ void cInputLine::handleTabExpansion ()
//initialize the expansion
tabListPos = tabWords.count()-1; // Set the position to the last occuranc of the prefix (ML 051006)
//delete the prefix
t.remove (expandPos, prefixLen);
// delete the word
t.remove (expandPos, wordLength);
}
else
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment