mirror of
https://git.lyx.org/repos/lyx.git
synced 2024-12-23 13:31:49 +00:00
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. git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@37669 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
parent
d6d4a80fc6
commit
fbaba7782a
@ -233,8 +233,7 @@ GuiWorkArea::GuiWorkArea(QWidget *)
|
||||
: buffer_view_(0), lyx_view_(0),
|
||||
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))
|
||||
{
|
||||
}
|
||||
|
||||
@ -243,8 +242,7 @@ GuiWorkArea::GuiWorkArea(Buffer & buffer, GuiView & gv)
|
||||
: buffer_view_(0), read_only_(buffer.isReadonly()), lyx_view_(0),
|
||||
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))
|
||||
{
|
||||
setGuiView(gv);
|
||||
setBuffer(buffer);
|
||||
@ -697,26 +695,28 @@ bool GuiWorkArea::event(QEvent * e)
|
||||
|
||||
void GuiWorkArea::contextMenuEvent(QContextMenuEvent * e)
|
||||
{
|
||||
QPoint pos;
|
||||
docstring name;
|
||||
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();
|
||||
// the 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;
|
||||
@ -763,8 +763,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();
|
||||
|
||||
|
@ -263,10 +263,11 @@ private:
|
||||
/// Special mode in which Esc and Enter (with or without Shift)
|
||||
/// are ignored
|
||||
bool dialog_mode_;
|
||||
/// 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
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user