From 886071393bff859b23c660106d10b4f252b165a6 Mon Sep 17 00:00:00 2001 From: Vincent van Ravesteijn Date: Mon, 5 Oct 2009 18:20:55 +0000 Subject: [PATCH] branch: Fix bug #6108: Crash on menu key 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. see r30797. git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/branches/BRANCH_1_6_X@31531 a592a061-630c-0410-9148-cb99ea01b6c8 --- src/frontends/qt4/GuiWorkArea.cpp | 16 +++++++++++++++- status.16x | 2 ++ 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/src/frontends/qt4/GuiWorkArea.cpp b/src/frontends/qt4/GuiWorkArea.cpp index 988afee611..88ba18e21b 100644 --- a/src/frontends/qt4/GuiWorkArea.cpp +++ b/src/frontends/qt4/GuiWorkArea.cpp @@ -636,6 +636,19 @@ void GuiWorkArea::contextMenuEvent(QContextMenuEvent * e) pos = context_target_pos_; else 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); @@ -1097,7 +1110,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: diff --git a/status.16x b/status.16x index 68fe9291a2..384b6d47ec 100644 --- a/status.16x +++ b/status.16x @@ -170,6 +170,8 @@ What's new - When starting LyX, open each document in a new view when "Open documents in tabs" is unchecked (bug 4906). + +- Fix the location of context menus requested by the menu key (bug 6108). * DOCUMENTATION AND LOCALIZATION