]> git.lyx.org Git - features.git/commitdiff
Fix bug #6108: Crash on menu key
authorVincent van Ravesteijn <vfr@lyx.org>
Mon, 27 Jul 2009 07:39:14 +0000 (07:39 +0000)
committerVincent van Ravesteijn <vfr@lyx.org>
Mon, 27 Jul 2009 07:39:14 +0000 (07:39 +0000)
The wrong context menu is being expanded, because the location where the context menu is requested is computed wrongly by Qt.

Actually, the problem seemed to be in InputMethodQuery?. For some reason, the box of the cursor is shifted right under the cursor box.

The menu key uses InputMethodQuery? to locate the context menu, just as he Japanese input method locates the box with possibilities.

1.6.x shows the same behaviour, but in that case it doesn't crash because the spellchecker entry does not exist there, but there might be another case in which it will crash.

git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@30797 a592a061-630c-0410-9148-cb99ea01b6c8

src/frontends/qt4/GuiWorkArea.cpp

index 0be7bad473411bcdfd175fe69b45fac00f198746..4e7197fb7c5c89610af3f22586ce411fd33865d1 100644 (file)
@@ -662,6 +662,19 @@ bool GuiWorkArea::event(QEvent * e)
 void GuiWorkArea::contextMenuEvent(QContextMenuEvent * e)
 {
        QPoint pos = e->pos();
+       Cursor const & cur = buffer_view_->cursor();
+       if (e->reason() == QContextMenuEvent::Keyboard && cur.inTexted()) {
+               // Do not access the context menu of math right in front of before
+               // the cursor. This does not work when the cursor is in text.
+               Inset * inset = cur.paragraph().getInset(cur.pos());
+               if (inset && inset->asInsetMath())
+                       --pos.rx();
+               else if (cur.pos() > 0) {
+                       Inset * inset = cur.paragraph().getInset(cur.pos() - 1);
+                       if (inset)
+                               ++pos.rx();
+               }
+       }
        docstring name = buffer_view_->contextMenu(pos.x(), pos.y());
        if (name.empty()) {
                QAbstractScrollArea::contextMenuEvent(e);
@@ -1152,7 +1165,8 @@ QVariant GuiWorkArea::inputMethodQuery(Qt::InputMethodQuery query) const
                        cur_r = cursor_->rect();
                        if (preedit_lines_ != 1)
                                cur_r.moveLeft(10);
-                       cur_r.moveBottom(cur_r.bottom() + cur_r.height() * preedit_lines_);
+                       cur_r.moveBottom(cur_r.bottom()
+                               + cur_r.height() * (preedit_lines_ - 1));
                        // return lower right of cursor in LyX.
                        return cur_r;
                default: