From a800da1bfe62b4b78c4eba7ebe4a315927762aa5 Mon Sep 17 00:00:00 2001 From: Abdelrazak Younes Date: Thu, 11 Oct 2007 14:46:53 +0000 Subject: [PATCH] initial support for shift + right-mouse-click selection. git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@20903 a592a061-630c-0410-9148-cb99ea01b6c8 --- src/BufferView.cpp | 20 ++++++++++++++------ src/BufferView.h | 2 +- src/Text3.cpp | 5 ++++- 3 files changed, 19 insertions(+), 8 deletions(-) diff --git a/src/BufferView.cpp b/src/BufferView.cpp index 9a892e8e98..72d6382a7d 100644 --- a/src/BufferView.cpp +++ b/src/BufferView.cpp @@ -1697,13 +1697,14 @@ bool BufferView::checkDepm(Cursor & cur, Cursor & old) } -bool BufferView::mouseSetCursor(Cursor & cur) +bool BufferView::mouseSetCursor(Cursor & cur, bool select) { BOOST_ASSERT(&cur.bv() == this); - // this event will clear selection so we save selection for - // persistent selection - cap::saveSelection(cursor()); + if (!select) + // this event will clear selection so we save selection for + // persistent selection + cap::saveSelection(cursor()); // Has the cursor just left the inset? bool badcursor = false; @@ -1711,12 +1712,15 @@ bool BufferView::mouseSetCursor(Cursor & cur) if (leftinset) badcursor = notifyCursorLeaves(d.cursor_, cur); + // FIXME: shift-mouse selection doesn't work well across insets. + bool do_selection = select && &d.cursor_.anchor().inset() == &cur.inset(); + // do the dEPM magic if needed // FIXME: (1) move this to InsetText::notifyCursorLeaves? // FIXME: (2) if we had a working InsetText::notifyCursorLeaves, // the leftinset bool would not be necessary (badcursor instead). bool update = leftinset; - if (!badcursor && d.cursor_.inTexted()) + if (!do_selection && !badcursor && d.cursor_.inTexted()) update |= checkDepm(cur, d.cursor_); // if the cursor was in an empty script inset and the new @@ -1738,7 +1742,11 @@ bool BufferView::mouseSetCursor(Cursor & cur) d.cursor_.setCursor(dit); d.cursor_.boundary(cur.boundary()); - d.cursor_.clearSelection(); + if (do_selection) + d.cursor_.setSelection(); + else + d.cursor_.clearSelection(); + finishUndo(); return update; } diff --git a/src/BufferView.h b/src/BufferView.h index b92e908368..df58d927e4 100644 --- a/src/BufferView.h +++ b/src/BufferView.h @@ -190,7 +190,7 @@ public: bool checkDepm(Cursor & cur, Cursor & old); /// sets cursor. /// This is used when handling LFUN_MOUSE_PRESS. - bool mouseSetCursor(Cursor & cur); + bool mouseSetCursor(Cursor & cur, bool select = false); /// sets the selection. /* When \c backwards == false, set anchor diff --git a/src/Text3.cpp b/src/Text3.cpp index d9d5b8f70b..1dd9b126b8 100644 --- a/src/Text3.cpp +++ b/src/Text3.cpp @@ -922,11 +922,14 @@ void Text::dispatch(Cursor & cur, FuncRequest & cmd) // Single-click on work area case LFUN_MOUSE_PRESS: { // Right click on a footnote flag opens float menu + // FIXME: Why should we clear the selection in this case? if (cmd.button() == mouse_button::button3) cur.clearSelection(); + bool do_selection = cmd.button() == mouse_button::button1 + && cmd.argument() == "region-select"; // Set the cursor - bool update = bv->mouseSetCursor(cur); + bool update = bv->mouseSetCursor(cur, do_selection); // Insert primary selection with middle mouse // if there is a local selection in the current buffer, -- 2.39.2