From 6cb284c7275815eaa4869c200ad0e47a2feb0d63 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Andr=C3=A9=20P=C3=B6nitz?= Date: Sat, 14 Aug 2004 20:34:46 +0000 Subject: [PATCH] fix some crash when we start selection outside an inset and get the first motion event inside this iset git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@8930 a592a061-630c-0410-9148-cb99ea01b6c8 --- src/mathed/math_nestinset.C | 23 ++++++------ src/text3.C | 74 ++++++++++++++++++------------------- 2 files changed, 48 insertions(+), 49 deletions(-) diff --git a/src/mathed/math_nestinset.C b/src/mathed/math_nestinset.C index 432bd33b52..3b82d0e65c 100644 --- a/src/mathed/math_nestinset.C +++ b/src/mathed/math_nestinset.C @@ -924,17 +924,17 @@ void MathNestInset::lfunMousePress(LCursor & cur, FuncRequest & cmd) void MathNestInset::lfunMouseMotion(LCursor & cur, FuncRequest & cmd) { // only select with button 1 - if (cmd.button() != mouse_button::button1) - return; - - if (abs(cmd.x - first_x) < 2 && abs(cmd.y - first_y) < 2) - return; - - first_x = cmd.x; - first_y = cmd.y; - - cur.bv().cursor().setCursor(cur); - cur.bv().cursor().selection() = true; + if (cmd.button() == mouse_button::button1) { + LCursor & bvcur = cur.bv().cursor(); + if (abs(cmd.x - first_x) + abs(cmd.y - first_y) > 4 + && cur.size() <= bvcur.anchor_.size()) { + first_x = cmd.x; + first_y = cmd.y; + + bvcur.setCursor(cur); + bvcur.selection() = true; + } + } } @@ -943,7 +943,6 @@ void MathNestInset::lfunMouseRelease(LCursor & cur, FuncRequest & cmd) lyxerr << "lfunMouseRelease: buttons: " << cmd.button() << endl; if (cmd.button() == mouse_button::button1) { - // try to dispatch to enclosed insets first //cur.bv().stuffClipboard(cur.grabSelection()); return; } diff --git a/src/text3.C b/src/text3.C index 4b69a2b010..3900a13a11 100644 --- a/src/text3.C +++ b/src/text3.C @@ -1060,43 +1060,6 @@ void LyXText::dispatch(LCursor & cur, FuncRequest & cmd) } break; - case LFUN_MOUSE_MOTION: { - // Only use motion with button 1 - //if (cmd.button() != mouse_button::button1) - // return false; - // We want to use only motion events for which - // the button press event was on the drawing area too. - if (!selection_possible) { - lyxerr[Debug::ACTION] << "BufferView::Pimpl::" - "dispatch: no selection possible\n"; - lyxerr << "BufferView::Pimpl::dispatch: no selection possible\n"; - break; - } - - // ignore motions deeper nested than the real anchor - LCursor & bvcur = cur.bv().cursor(); - if (bvcur.selection() && bvcur.anchor_.size() < cur.size()) - break; - - CursorSlice old = cur.top(); - setCursorFromCoordinates(cur, cmd.x, cmd.y); - - // This is to allow jumping over large insets - // FIXME: shouldn't be top-text-specific - if (isMainText() && cur.top() == old) { - if (cmd.y - bv->top_y() >= bv->workHeight()) - cursorDown(cur); - else if (cmd.y - bv->top_y() < 0) - cursorUp(cur); - } - - // don't set anchor_ - bv->cursor().setCursor(cur); - bv->cursor().selection() = true; - lyxerr << "MOTION: " << bv->cursor() << endl; - break; - } - // Single-click on work area case LFUN_MOUSE_PRESS: { // Right click on a footnote flag opens float menu @@ -1151,6 +1114,43 @@ void LyXText::dispatch(LCursor & cur, FuncRequest & cmd) break; } + case LFUN_MOUSE_MOTION: { + // Only use motion with button 1 + //if (cmd.button() != mouse_button::button1) + // return false; + // We want to use only motion events for which + // the button press event was on the drawing area too. + if (!selection_possible) { + lyxerr[Debug::ACTION] << "BufferView::Pimpl::" + "dispatch: no selection possible\n"; + lyxerr << "BufferView::Pimpl::dispatch: no selection possible\n"; + break; + } + + // ignore motions deeper nested than the real anchor + LCursor & bvcur = cur.bv().cursor(); + if (bvcur.anchor_.size() < cur.size()) + break; + + CursorSlice old = cur.top(); + setCursorFromCoordinates(cur, cmd.x, cmd.y); + + // This is to allow jumping over large insets + // FIXME: shouldn't be top-text-specific + if (isMainText() && cur.top() == old) { + if (cmd.y - bv->top_y() >= bv->workHeight()) + cursorDown(cur); + else if (cmd.y - bv->top_y() < 0) + cursorUp(cur); + } + + // don't set anchor_ + bv->cursor().setCursor(cur); + bv->cursor().selection() = true; + lyxerr << "MOTION: " << bv->cursor() << endl; + break; + } + case LFUN_MOUSE_RELEASE: { selection_possible = false; -- 2.39.2