branch: Fix bug #7209: Crash when clicking on unfinished command in math.

This was a similar problem as for bug #5796 in r30807. There I made sure that the position that is used for the context menu is set at mousepress. That was because also the cursor was set at mousepress and we want to get the context menu at the place where the mousebutton was pressed, and not where the mousebutton was released.

However, in this case, the position of the context menu is stored on mousepress, but we don't take into account that the cursor might move afterwards due to the DEPM.

So, the solution is not to save the position of the mouseclick, but to save the name of the context menu we requested.

PS. Perhaps we could save the cursor position, but this seems to work too.

see r37669.

git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/branches/BRANCH_1_6_X@37688 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
Vincent van Ravesteijn 2011-02-16 12:53:08 +00:00
parent e2e87c6756
commit 24b1363ee3
2 changed files with 30 additions and 24 deletions

View File

@ -234,8 +234,7 @@ GuiWorkArea::GuiWorkArea(Buffer & buffer, GuiView & lv)
: buffer_view_(new BufferView(buffer)), lyx_view_(&lv),
cursor_visible_(false),
need_resize_(false), schedule_redraw_(false),
preedit_lines_(1), completer_(new GuiCompleter(this, this)),
context_target_pos_()
preedit_lines_(1), completer_(new GuiCompleter(this, this))
{
buffer.workAreaManager().add(this);
// Setup the signals
@ -628,26 +627,28 @@ bool GuiWorkArea::event(QEvent * e)
void GuiWorkArea::contextMenuEvent(QContextMenuEvent * e)
{
QPoint pos;
if (e->reason() == QContextMenuEvent::Mouse)
// the position is set on mouse press
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;
if (e->reason() == QContextMenuEvent::Mouse) {
// the context menu name is set on mouse press
name = context_menu_name_;
} else {
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();
}
}
name = buffer_view_->contextMenu(pos.x(), pos.y());
}
docstring name = buffer_view_->contextMenu(pos.x(), pos.y());
if (name.empty()) {
QAbstractScrollArea::contextMenuEvent(e);
return;
@ -696,8 +697,12 @@ void GuiWorkArea::mousePressEvent(QMouseEvent * e)
return;
}
// Save the context menu on mouse press, because also the mouse
// cursor is set on mouse press. Afterwards, we can either release
// the mousebutton somewhere else, or the cursor might have moved
// due to the DEPM.
if (e->button() == Qt::RightButton)
context_target_pos_ = e->pos();
context_menu_name_ = buffer_view_->contextMenu(e->x(), e->y());
inputContext()->reset();

View File

@ -240,10 +240,11 @@ private:
///
GuiCompleter * completer_;
/// store the position of the rightclick when the mouse is
/// store the name of the context menu when the mouse is
/// pressed. This is used to get the correct context menu
/// when the menu is actually shown (after releasing on Windwos).
QPoint context_target_pos_;
/// when the menu is actually shown (after releasing on Windows)
/// and after the DEPM has done its job.
docstring context_menu_name_;
}; // GuiWorkArea