* 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

@ -329,7 +329,7 @@ void GuiCompleter::updatePrefix(Cursor & cur)
// update completer to new prefix // update completer to new prefix
setCompletionPrefix(newPrefix); setCompletionPrefix(newPrefix);
// update popup because its size might have changed // update popup because its size might have changed
if (popupVisible()) if (popupVisible())
updatePopup(cur); updatePopup(cur);
@ -431,6 +431,11 @@ void GuiCompleter::updateModel(Cursor & cur, bool popupUpdate, bool inlineUpdate
else else
setModelSorting(QCompleter::UnsortedModel); setModelSorting(QCompleter::UnsortedModel);
// set prefix
QString newPrefix = toqstr(cur.inset().completionPrefix(cur));
if (newPrefix != completionPrefix())
setCompletionPrefix(newPrefix);
// show popup // show popup
if (popupUpdate) if (popupUpdate)
updatePopup(cur); updatePopup(cur);
@ -445,7 +450,7 @@ void GuiCompleter::updateModel(Cursor & cur, bool popupUpdate, bool inlineUpdate
last_selection_ = s; last_selection_ = s;
else else
last_selection_ = old; last_selection_ = old;
// show inline completion // show inline completion
if (inlineUpdate) if (inlineUpdate)
updateInline(cur, currentCompletion()); updateInline(cur, currentCompletion());
@ -458,9 +463,8 @@ void GuiCompleter::showPopup(Cursor & cur)
return; return;
updateModel(cur, true, inlineVisible()); updateModel(cur, true, inlineVisible());
updatePrefix(cur);
} }
void GuiCompleter::showInline(Cursor & cur) void GuiCompleter::showInline(Cursor & cur)
{ {
@ -468,7 +472,6 @@ void GuiCompleter::showInline(Cursor & cur)
return; return;
updateModel(cur, popupVisible(), true); updateModel(cur, popupVisible(), true);
updatePrefix(cur);
} }
@ -619,6 +622,7 @@ void GuiCompleter::setCurrentCompletion(QString const & s)
// In sorted models, do binary search for s. // In sorted models, do binary search for s.
i = 0; i = 0;
size_t r = n - 1; size_t r = n - 1;
int c;
do { do {
size_t mid = (r + i) / 2; size_t mid = (r + i) / 2;
QString const & mids QString const & mids
@ -628,7 +632,7 @@ void GuiCompleter::setCurrentCompletion(QString const & s)
// left or right? // left or right?
// FIXME: is this really the same order that the docstring // FIXME: is this really the same order that the docstring
// from the CompletionList has? // from the CompletionList has?
int c = s.compare(mids, Qt::CaseSensitive); c = s.compare(mids, Qt::CaseSensitive);
if (c == 0) { if (c == 0) {
i = mid; i = mid;
break; break;
@ -637,9 +641,14 @@ void GuiCompleter::setCurrentCompletion(QString const & s)
i = mid + 1; i = mid + 1;
else else
// middle is too far // middle is too far
r = mid - 1; r = mid;
} while (r - i > 0 && i < n); } 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 // select the first if none was found