When the menu is pressed, a context menu is located at the cursor. The location of the cursor is retrieved via the InputMethodQuery function (just as the japanese list of possibilities). However, for some reason the box around the cursor that needs to be returned in this function is shifted down by one times the height. This causes the context menu to be retrieved for a different location than were the cursor is, and this can lead to a crash eventually.

This patch adjusts the output of InputMethodQuery (and has thus influence on the position of the japanese list), and makes the behaviour of the context menu more intuitive. This means: no math context menu if you are in text, no context menu of the float that is before the cursor.

Ok ?

Vincent
Index: GuiWorkArea.cpp
===================================================================
--- GuiWorkArea.cpp     (revision 30748)
+++ GuiWorkArea.cpp     (working copy)
@@ -662,6 +662,19 @@
 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 @@
                        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:

Reply via email to