]> git.lyx.org Git - lyx.git/blob - src/frontends/qt4/GuiCompleter.cpp
b5c223c1f9b774050b72e72f96464f6e2590b848
[lyx.git] / src / frontends / qt4 / GuiCompleter.cpp
1 /**
2  * \file GuiCompleter.cpp
3  * This file is part of LyX, the document processor.
4  * Licence details can be found in the file COPYING.
5  *
6  * \author Stefan Schimanski
7  *
8  * Full author contact details are available in file CREDITS.
9  */
10
11 #include <config.h>
12
13 #include "GuiWorkArea.h"
14
15 #include "Buffer.h"
16 #include "BufferView.h"
17 #include "Cursor.h"
18 #include "Dimension.h"
19 #include "FuncRequest.h"
20 #include "GuiView.h"
21 #include "LyXFunc.h"
22 #include "LyXRC.h"
23 #include "Paragraph.h"
24 #include "version.h"
25
26 #include "support/debug.h"
27
28 #include <QApplication>
29 #include <QAbstractListModel>
30 #include <QHeaderView>
31 #include <QPainter>
32 #include <QPixmapCache>
33 #include <QScrollBar>
34 #include <QItemDelegate>
35 #include <QTreeView>
36 #include <QTimer>
37
38 using namespace std;
39 using namespace lyx::support;
40
41 namespace lyx {
42 namespace frontend {
43
44 class RtlItemDelegate : public QItemDelegate {
45 public:
46         explicit RtlItemDelegate(QObject * parent = 0)
47                 : QItemDelegate(parent) {}
48
49 protected:
50         virtual void drawDisplay(QPainter * painter,
51                 QStyleOptionViewItem const & option,
52                 QRect const & rect, QString const & text) const
53         {
54                 // FIXME: do this more elegantly
55                 docstring stltext = qstring_to_ucs4(text);
56                 reverse(stltext.begin(), stltext.end());
57                 QItemDelegate::drawDisplay(painter, option, rect, toqstr(stltext));
58         }
59 };
60
61
62 class PixmapItemDelegate : public QItemDelegate {
63 public:
64         explicit PixmapItemDelegate(QObject *parent = 0)
65         : QItemDelegate(parent) {}
66
67 protected:
68         void paint(QPainter *painter, const QStyleOptionViewItem &option,
69                    const QModelIndex &index) const
70         {
71                 QStyleOptionViewItem opt = setOptions(index, option);
72                 QVariant value = index.data(Qt::DisplayRole);
73                 QPixmap pixmap = qvariant_cast<QPixmap>(value);
74                 
75                 // draw
76                 painter->save();
77                 drawBackground(painter, opt, index);
78                 if (!pixmap.isNull()) {
79                         const QSize size = pixmap.size();
80                         painter->drawPixmap(option.rect.left() + (16 - size.width()) / 2,
81                                 option.rect.top() + (option.rect.height() - size.height()) / 2,
82                                 pixmap);
83                 }
84                 drawFocus(painter, opt, option.rect);
85                 painter->restore();
86         }
87 };
88
89
90 class GuiCompletionModel : public QAbstractListModel {
91 public:
92         ///
93         GuiCompletionModel(QObject * parent,
94                 Inset::CompletionList const * l)
95                 : QAbstractListModel(parent), list_(l) {}
96         ///
97         ~GuiCompletionModel()
98                 { delete list_; }
99         ///
100         bool sorted() const
101         {
102                 if (list_)
103                         return list_->sorted();
104                 else
105                         return false;
106         }
107         ///
108         int columnCount(const QModelIndex & /*parent*/ = QModelIndex()) const
109         {
110                 return 2;
111         }
112         ///
113         int rowCount(const QModelIndex & /*parent*/ = QModelIndex()) const
114         {
115                 if (list_ == 0)
116                         return 0;
117                 else
118                         return list_->size();
119         }
120
121         ///
122         QVariant data(const QModelIndex & index, int role) const
123         {
124                 if (list_ == 0)
125                         return QVariant();
126
127                 if (index.row() < 0 || index.row() >= rowCount())
128                         return QVariant();
129
130                 if (role != Qt::DisplayRole && role != Qt::EditRole)
131                     return QVariant();
132                     
133                 if (index.column() == 0) {
134                         docstring const word = list_->data(index.row());
135                         return toqstr(word);
136                 } else if (index.column() == 1) {
137                         // get icon from cache
138                         QPixmap scaled;
139                         QString const name = ":" + toqstr(list_->icon(index.row()));
140                         if (!QPixmapCache::find("completion" + name, scaled)) {
141                                 // load icon from disk
142                                 QPixmap p = QPixmap(name);
143                                 if (!p.isNull()) {
144                                         // scale it to 16x16 or smaller
145                                         scaled = p.scaled(min(16, p.width()), min(16, p.height()), 
146                                                 Qt::KeepAspectRatio, Qt::SmoothTransformation);
147                                 }
148
149                                 QPixmapCache::insert("completion" + name, scaled);
150                         }
151                         return scaled;
152                 }
153                 return QVariant();
154         }
155
156 private:
157         ///
158         Inset::CompletionList const * list_;
159 };
160
161
162 GuiCompleter::GuiCompleter(GuiWorkArea * gui, QObject * parent)
163         : QCompleter(parent), gui_(gui), updateLock_(0),
164           inlineVisible_(false)
165 {
166         // Setup the completion popup
167         setModel(new GuiCompletionModel(this, 0));
168         setCompletionMode(QCompleter::PopupCompletion);
169         setWidget(gui_);
170         
171         // create the popup
172         QTreeView *listView = new QTreeView;
173         listView->setEditTriggers(QAbstractItemView::NoEditTriggers);
174         listView->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
175         listView->setSelectionBehavior(QAbstractItemView::SelectRows);
176         listView->setSelectionMode(QAbstractItemView::SingleSelection);
177         listView->header()->hide();
178         listView->setIndentation(0);
179         listView->setUniformRowHeights(true);
180         setPopup(listView);
181         popup()->setItemDelegateForColumn(1, new PixmapItemDelegate(this));
182         rtlItemDelegate_ = new RtlItemDelegate(this);
183         
184         // create timeout timers
185         popup_timer_.setSingleShot(true);
186         inline_timer_.setSingleShot(true);
187         connect(this, SIGNAL(highlighted(const QString &)),
188                 this, SLOT(popupHighlighted(const QString &)));
189         connect(this, SIGNAL(activated(const QString &)),
190                 this, SLOT(popupActivated(const QString &)));
191         connect(&popup_timer_, SIGNAL(timeout()),
192                 this, SLOT(showPopup()));
193         connect(&inline_timer_, SIGNAL(timeout()),
194                 this, SLOT(showInline()));
195 }
196
197
198 GuiCompleter::~GuiCompleter()
199 {
200         popup()->hide();
201 }
202
203
204 bool GuiCompleter::eventFilter(QObject * watched, QEvent * e)
205 {
206         // hijack back the tab key from the popup
207         // (which stole it from the workspace before)
208         if (e->type() == QEvent::KeyPress && popupVisible()) {
209                 QKeyEvent *ke = static_cast<QKeyEvent *>(e);
210                 switch (ke->key()) {
211                 case Qt::Key_Tab:
212                         tab();
213                         ke->accept();
214                         return true;
215                 default: break;
216                 }
217         }
218         
219         return QCompleter::eventFilter(watched, e);
220 }
221
222
223 bool GuiCompleter::popupPossible(Cursor const & cur) const
224 {
225         return QApplication::activeWindow()
226                 && gui_->hasFocus()
227                 && cur.inset().completionSupported(cur);
228 }
229
230
231 bool GuiCompleter::inlinePossible(Cursor const & cur) const
232 {
233         return cur.inset().inlineCompletionSupported(cur);
234 }
235
236
237 bool GuiCompleter::completionAvailable() const
238 {
239         size_t n = popup()->model()->rowCount();
240
241         // if there is exactly one, we have to check whether it is a 
242         // real completion, i.e. longer than the current prefix.
243         if (n == 1 && completionPrefix() == currentCompletion())
244             return false;
245
246         return n > 0;
247 }
248
249
250 bool GuiCompleter::popupVisible() const
251 {
252         return popup()->isVisible();
253 }
254
255
256 bool GuiCompleter::inlineVisible() const
257 {
258         // In fact using BufferView::inlineCompletionPos.empty() should be
259         // here. But unfortunately this information is not good enough
260         // because destructive operations like backspace might invalidate
261         // inlineCompletionPos. But then the completion should stay visible
262         // (i.e. reshown on the next update). Hence be keep this information
263         // in the inlineVisible_ variable.
264         return inlineVisible_;
265 }
266
267
268 void GuiCompleter::updateVisibility(Cursor & cur, bool start, bool keep, bool cursorInView)
269 {
270         // parameters which affect the completion
271         bool moved = cur != old_cursor_;
272         if (moved)
273                 old_cursor_ = cur;
274
275         bool possiblePopupState = popupPossible(cur) && cursorInView;
276         bool possibleInlineState = inlinePossible(cur) && cursorInView;
277
278         // we moved or popup state is not ok for popup?
279         if ((moved && !keep) || !possiblePopupState)
280                 hidePopup(cur);
281
282         // we moved or inline state is not ok for inline completion?
283         if ((moved && !keep) || !possibleInlineState)
284                 hideInline(cur);
285
286         // we inserted something and are in a possible popup state?
287         if (!popupVisible() && possiblePopupState && start
288                 && cur.inset().automaticPopupCompletion())
289                 popup_timer_.start(int(lyxrc.completion_popup_delay * 1000));
290
291         // we inserted something and are in a possible inline completion state?
292         if (!inlineVisible() && possibleInlineState && start
293                 && cur.inset().automaticInlineCompletion())
294                 inline_timer_.start(int(lyxrc.completion_inline_delay * 1000));
295
296         // update prefix if any completion is possible
297         bool modelActive = model()->rowCount() > 0;
298         if (possiblePopupState || possibleInlineState) {
299                 if (modelActive)
300                         updatePrefix(cur);
301                 else
302                         updateAvailability();
303         }
304 }
305
306
307 void GuiCompleter::updateVisibility(bool start, bool keep)
308 {
309         Cursor cur = gui_->bufferView().cursor();
310         cur.updateFlags(Update::None);
311         
312         updateVisibility(cur, start, keep);
313         
314         if (cur.disp_.update())
315                 gui_->bufferView().processUpdateFlags(cur.disp_.update());
316 }
317
318
319 void GuiCompleter::updatePrefix(Cursor & cur)
320 {
321         // get new prefix. Do nothing if unchanged
322         QString newPrefix = toqstr(cur.inset().completionPrefix(cur));
323         if (newPrefix == completionPrefix())
324                 return;
325         
326         // value which should be kept selected
327         QString old = currentCompletion();
328         if (old.length() == 0)
329                 old = last_selection_;
330         
331         // update completer to new prefix
332         setCompletionPrefix(newPrefix);
333
334         // update popup because its size might have changed
335         if (popupVisible())
336                 updatePopup(cur);
337
338         // restore old selection
339         setCurrentCompletion(old);
340         
341         // if popup is not empty, the new selection will
342         // be our last valid one
343         QString const & s = currentCompletion();
344         if (s.length() > 0)
345                 last_selection_ = s;
346         else
347                 last_selection_ = old;
348         
349         // update inline completion because the default
350         // completion string might have changed
351         if (inlineVisible())
352                 updateInline(cur, s);
353 }
354
355
356 void GuiCompleter::updateInline(Cursor & cur, QString const & completion)
357 {
358         if (!cur.inset().inlineCompletionSupported(cur))
359                 return;
360         
361         // compute postfix
362         docstring prefix = cur.inset().completionPrefix(cur);
363         docstring postfix = from_utf8(fromqstr(completion.mid(prefix.length())));
364         
365         // shorten it if necessary
366         if (lyxrc.completion_inline_dots != -1
367             && postfix.size() > unsigned(lyxrc.completion_inline_dots))
368                 postfix = postfix.substr(0, lyxrc.completion_inline_dots - 1) + "...";
369
370         // set inline completion at cursor position
371         size_t uniqueTo = max(longestUniqueCompletion().size(), prefix.size());
372         gui_->bufferView().setInlineCompletion(cur, cur, postfix, uniqueTo - prefix.size());
373         inlineVisible_ = true;
374 }
375
376
377 void GuiCompleter::updatePopup(Cursor & cur)
378 {
379         if (!cur.inset().completionSupported(cur))
380                 return;
381         
382         if (completionCount() == 0)
383                 return;
384         
385         // get dimensions of completion prefix
386         Dimension dim;
387         int x;
388         int y;
389         cur.inset().completionPosAndDim(cur, x, y, dim);
390         
391         // and calculate the rect of the popup
392         QRect rect;
393         if (popup()->layoutDirection() == Qt::RightToLeft)
394                 rect = QRect(x + dim.width() - 200, y - dim.ascent() - 3, 200, dim.height() + 6);
395         else
396                 rect = QRect(x, y - dim.ascent() - 3, 200, dim.height() + 6);
397         
398         // show/update popup
399         QTreeView * p = static_cast<QTreeView *>(popup());
400         p->setColumnWidth(0, popup()->width() - 22 - p->verticalScrollBar()->width());
401
402         complete(rect);
403 }
404
405
406 void GuiCompleter::updateAvailability()
407 {
408         // this should really only be of interest if no completion is
409         // visible yet, i.e. especially if automatic completion is disabled.
410         if (inlineVisible() || popupVisible())
411                 return;
412         Cursor & cur = gui_->bufferView().cursor();
413         if (!popupPossible(cur) && !inlinePossible(cur))
414                 return;
415         
416         updateModel(cur, false, false);
417 }
418         
419
420 void GuiCompleter::updateModel(Cursor & cur, bool popupUpdate, bool inlineUpdate)
421 {
422         // value which should be kept selected
423         QString old = currentCompletion();
424         if (old.length() == 0)
425                 old = last_selection_;
426
427         // set whether rtl
428         bool rtl = false;
429         if (cur.inTexted()) {
430                 Paragraph const & par = cur.paragraph();
431                 Font const font =
432                 par.getFontSettings(cur.bv().buffer().params(), cur.pos());
433                 rtl = font.isVisibleRightToLeft();
434         }
435         popup()->setLayoutDirection(rtl ? Qt::RightToLeft : Qt::LeftToRight);
436
437         // turn the direction of the strings in the popup.
438         // Qt does not do that itself.
439         popup()->setItemDelegateForColumn(0, rtl ? rtlItemDelegate_ : 0);
440
441         // set new model
442         Inset::CompletionList const * list = cur.inset().createCompletionList(cur);
443         setModel(new GuiCompletionModel(this, list));
444         if (list->sorted())
445                 setModelSorting(QCompleter::CaseSensitivelySortedModel);
446         else
447                 setModelSorting(QCompleter::UnsortedModel);
448
449         // set prefix
450         QString newPrefix = toqstr(cur.inset().completionPrefix(cur));
451         if (newPrefix != completionPrefix())
452                 setCompletionPrefix(newPrefix);
453
454         // show popup
455         if (popupUpdate)
456                 updatePopup(cur);
457
458         // restore old selection
459         setCurrentCompletion(old);
460         
461         // if popup is not empty, the new selection will
462         // be our last valid one
463         QString const & s = currentCompletion();
464         if (s.length() > 0)
465                 last_selection_ = s;
466         else
467                 last_selection_ = old;
468
469         // show inline completion
470         if (inlineUpdate)
471                 updateInline(cur, currentCompletion());
472 }
473
474
475 void GuiCompleter::showPopup(Cursor & cur)
476 {
477         if (!popupPossible(cur))
478                 return;
479         
480         updateModel(cur, true, inlineVisible());
481 }
482
483
484 void GuiCompleter::hidePopup(Cursor & cur)
485 {
486         popup()->hide();
487         if (popup_timer_.isActive())
488                 popup_timer_.stop();
489         
490         if (!inlineVisible())
491                 setModel(new GuiCompletionModel(this, 0));
492 }
493
494
495 void GuiCompleter::showInline(Cursor & cur)
496 {
497         if (!inlinePossible(cur))
498                 return;
499         
500         updateModel(cur, popupVisible(), true);
501 }
502
503
504 void GuiCompleter::hideInline(Cursor & cur)
505 {
506         gui_->bufferView().setInlineCompletion(cur, DocIterator(), docstring());
507         inlineVisible_ = false;
508         
509         if (!popupVisible())
510                 setModel(new GuiCompletionModel(this, 0));
511 }
512
513
514 void GuiCompleter::showPopup()
515 {
516         Cursor cur = gui_->bufferView().cursor();
517         cur.updateFlags(Update::None);
518         
519         showPopup(cur);
520
521         // redraw if needed
522         if (cur.disp_.update())
523                 gui_->bufferView().processUpdateFlags(cur.disp_.update());
524 }
525
526
527 void GuiCompleter::showInline()
528 {
529         Cursor cur = gui_->bufferView().cursor();
530         cur.updateFlags(Update::None);
531         
532         showInline(cur);
533
534         // redraw if needed
535         if (cur.disp_.update())
536                 gui_->bufferView().processUpdateFlags(cur.disp_.update());
537 }
538
539
540 void GuiCompleter::hidePopup()
541 {
542         Cursor cur = gui_->bufferView().cursor();
543         cur.updateFlags(Update::None);
544         
545         hidePopup(cur);
546         
547         // redraw if needed
548         if (cur.disp_.update())
549                 gui_->bufferView().processUpdateFlags(cur.disp_.update());
550 }
551
552
553 void GuiCompleter::hideInline()
554 {
555         Cursor cur = gui_->bufferView().cursor();
556         cur.updateFlags(Update::None);
557         
558         hideInline(cur);
559         
560         // redraw if needed
561         if (cur.disp_.update())
562                 gui_->bufferView().processUpdateFlags(cur.disp_.update());
563 }
564
565
566 void GuiCompleter::activate()
567 {
568         if (!popupVisible() && !inlineVisible())
569                 return;
570
571         popupActivated(currentCompletion());
572 }
573
574
575 void GuiCompleter::tab()
576 {
577         BufferView * bv = &gui_->bufferView();
578         Cursor cur = bv->cursor();
579         cur.updateFlags(Update::None);
580         
581         // check that inline completion is active
582         if (!inlineVisible()) {
583                 // try to activate the inline completion
584                 if (cur.inset().inlineCompletionSupported(cur)) {
585                         showInline();
586                         
587                         // show popup without delay because the completion was not unique
588                         if (lyxrc.completion_popup_after_complete
589                             && !popupVisible()
590                             && popup()->model()->rowCount() > 1)
591                                 popup_timer_.start(0);
592
593                         return;
594                 }
595                 // or try popup
596                 if (!popupVisible() && cur.inset().completionSupported(cur)) {
597                         showPopup();
598                         return;
599                 }
600                 
601                 return;
602         }
603         
604         // If completion is active, at least complete by one character
605         docstring prefix = cur.inset().completionPrefix(cur);
606         docstring completion = from_utf8(fromqstr(currentCompletion()));
607         if (completion.size() <= prefix.size()) {
608                 // finalize completion
609                 cur.inset().insertCompletion(cur, docstring(), true);
610                 
611                 // hide popup and inline completion
612                 hidePopup(cur);
613                 hideInline(cur);
614                 updateVisibility(false, false);
615                 return;
616         }
617         docstring nextchar = completion.substr(prefix.size(), 1);
618         if (!cur.inset().insertCompletion(cur, nextchar, false))
619                 return;
620         updatePrefix(cur);
621
622         // try to complete as far as it is unique
623         docstring longestCompletion = longestUniqueCompletion();
624         prefix = cur.inset().completionPrefix(cur);
625         docstring postfix = longestCompletion.substr(min(longestCompletion.size(), prefix.size()));
626         cur.inset().insertCompletion(cur, postfix, false);
627         old_cursor_ = bv->cursor();
628         updatePrefix(cur);
629
630         // show popup without delay because the completion was not unique
631         if (lyxrc.completion_popup_after_complete
632             && !popupVisible()
633             && popup()->model()->rowCount() > 1)
634                 popup_timer_.start(0);
635
636         // redraw if needed
637         if (cur.disp_.update())
638                 gui_->bufferView().processUpdateFlags(cur.disp_.update());
639 }
640
641
642 QString GuiCompleter::currentCompletion() const
643 {
644         if (!popup()->selectionModel()->hasSelection())
645                 return QString();
646
647         // Not sure if this is bug in Qt: currentIndex() always 
648         // return the first element in the list.
649         QModelIndex idx = popup()->currentIndex();
650         return popup()->model()->data(idx, Qt::EditRole).toString();
651 }
652
653
654 void GuiCompleter::setCurrentCompletion(QString const & s)
655 {       
656         QAbstractItemModel const & model = *popup()->model();
657         size_t n = model.rowCount();
658         if (n == 0)
659                 return;
660
661         // select the first if s is empty
662         if (s.length() == 0) {
663                 updateLock_++;
664                 popup()->setCurrentIndex(model.index(0, 0));
665                 updateLock_--;
666                 return;
667         }
668
669         // find old selection in model
670         size_t i;
671         if (modelSorting() == QCompleter::UnsortedModel) {
672                 // In unsorted models, iterate through list until the s is found
673                 for (i = 0; i < n; ++i) {
674                         QString const & is
675                         = model.data(model.index(i, 0), Qt::EditRole).toString();
676                         if (is == s)
677                                 break;
678                 }
679         } else {
680                 // In sorted models, do binary search for s.
681                 int l = 0;
682                 int r = n - 1;
683                 while (r >= l && l < int(n)) {
684                         size_t mid = (r + l) / 2;
685                         QString const & mids
686                         = model.data(model.index(mid, 0),
687                                      Qt::EditRole).toString();
688
689                         // left or right?
690                         // FIXME: is this really the same order that the docstring
691                         // from the CompletionList has?
692                         int c = s.compare(mids, Qt::CaseSensitive);
693                         if (c == 0) {
694                                 l = mid;
695                                 break;
696                         } else if (l == r) {
697                                 l = n;
698                                 break;
699                         } else if (c > 0)
700                                 // middle is not far enough
701                                 l = mid + 1;
702                         else
703                                 // middle is too far
704                                 r = mid - 1;
705                 }
706
707                 // loop was left without finding anything
708                 if (r < l)
709                         i = n;
710                 else
711                         i = l;
712                 BOOST_ASSERT(0 <= i && i <= n);
713         }
714
715         // select the first if none was found
716         if (i == n)
717                 i = 0;
718
719         updateLock_++;
720         popup()->setCurrentIndex(model.index(i, 0));
721         updateLock_--;
722 }
723
724
725 size_t commonPrefix(QString const & s1, QString const & s2)
726 {
727         // find common prefix
728         size_t j;
729         size_t n1 = s1.length();
730         size_t n2 = s2.length();
731         for (j = 0; j < n1 && j < n2; ++j) {
732                 if (s1.at(j) != s2.at(j))
733                         break;
734         }
735         return j;
736 }
737
738
739 docstring GuiCompleter::longestUniqueCompletion() const
740 {
741         QAbstractItemModel const & model = *popup()->model();
742         QString s = currentCompletion();
743         size_t n = model.rowCount();
744
745         if (modelSorting() == QCompleter::UnsortedModel) {
746                 // For unsorted model we cannot do more than iteration.
747                 // Iterate through the completions and cut off where s differs
748                 for (size_t i = 0; i < n && s.length() > 0; ++i) {
749                         QString const & is
750                         = model.data(model.index(i, 0), Qt::EditRole).toString();
751
752                         s = s.left(commonPrefix(is, s));
753                 }
754         } else {
755                 // For sorted models we can do binary search multiple times,
756                 // each time to find the first string which has s not as prefix.
757                 size_t i = 0;
758                 while (i < n && s.length() > 0) {
759                         // find first string that does not have s as prefix
760                         // via binary search in [i,n-1]
761                         size_t r = n - 1;
762                         do {
763                                 // get common prefix with the middle string
764                                 size_t mid = (r + i) / 2;
765                                 QString const & mids
766                                 = model.data(model.index(mid, 0), 
767                                         Qt::EditRole).toString();
768                                 size_t oldLen = s.length();
769                                 size_t len = commonPrefix(mids, s);
770                                 s = s.left(len);
771
772                                 // left or right?
773                                 if (oldLen == len) {
774                                         // middle is not far enough
775                                         i = mid + 1;
776                                 } else {
777                                         // middle is maybe too far
778                                         r = mid;
779                                 }
780                         } while (r - i > 0 && i < n);
781                 }
782         }
783
784         return from_utf8(fromqstr(s));
785 }
786
787
788 void GuiCompleter::popupActivated(const QString & completion)
789 {
790         Cursor cur = gui_->bufferView().cursor();
791         cur.updateFlags(Update::None);
792         
793         docstring prefix = cur.inset().completionPrefix(cur);
794         docstring postfix = from_utf8(fromqstr(completion.mid(prefix.length())));
795         cur.inset().insertCompletion(cur, postfix, true);
796         hidePopup(cur);
797         hideInline(cur);
798         
799         if (cur.disp_.update())
800                 gui_->bufferView().processUpdateFlags(cur.disp_.update());
801 }
802
803
804 void GuiCompleter::popupHighlighted(const QString & completion)
805 {
806         if (updateLock_ > 0)
807                 return;
808
809         Cursor cur = gui_->bufferView().cursor();
810         cur.updateFlags(Update::None);
811         
812         if (inlineVisible())
813                 updateInline(cur, completion);
814         
815         if (cur.disp_.update())
816                 gui_->bufferView().processUpdateFlags(cur.disp_.update());
817 }
818
819 } // namespace frontend
820 } // namespace lyx
821
822 #include "GuiCompleter_moc.cpp"