* fix for binary search if string was not found

git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@23225 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
Stefan Schimanski 2008-02-25 13:08:51 +00:00
parent 159c18bfb9
commit 32f9f03ebc

View File

@ -431,6 +431,11 @@ void GuiCompleter::updateModel(Cursor & cur, bool popupUpdate, bool inlineUpdate
else
setModelSorting(QCompleter::UnsortedModel);
// set prefix
QString newPrefix = toqstr(cur.inset().completionPrefix(cur));
if (newPrefix != completionPrefix())
setCompletionPrefix(newPrefix);
// show popup
if (popupUpdate)
updatePopup(cur);
@ -458,7 +463,6 @@ void GuiCompleter::showPopup(Cursor & cur)
return;
updateModel(cur, true, inlineVisible());
updatePrefix(cur);
}
@ -468,7 +472,6 @@ void GuiCompleter::showInline(Cursor & cur)
return;
updateModel(cur, popupVisible(), true);
updatePrefix(cur);
}
@ -619,6 +622,7 @@ void GuiCompleter::setCurrentCompletion(QString const & s)
// In sorted models, do binary search for s.
i = 0;
size_t r = n - 1;
int c;
do {
size_t mid = (r + i) / 2;
QString const & mids
@ -628,7 +632,7 @@ void GuiCompleter::setCurrentCompletion(QString const & s)
// left or right?
// FIXME: is this really the same order that the docstring
// from the CompletionList has?
int c = s.compare(mids, Qt::CaseSensitive);
c = s.compare(mids, Qt::CaseSensitive);
if (c == 0) {
i = mid;
break;
@ -637,9 +641,14 @@ void GuiCompleter::setCurrentCompletion(QString const & s)
i = mid + 1;
else
// middle is too far
r = mid - 1;
r = mid;
} while (r - i > 0 && i < n);
// loop was left with failed comparison?
// i.e. word was not found.
if (c != 0)
i = n;
}
// select the first if none was found