On Sun, Feb 8, 2015 at 4:14 PM, Scott Kostyshak <skost...@lyx.org> wrote:
> On Thu, Nov 20, 2014 at 3:28 AM, Scott Kostyshak <skost...@lyx.org> wrote:
>> On Tue, Oct 28, 2014 at 7:03 AM, Scott Kostyshak <skost...@lyx.org> wrote:
>>> I have a patch that enables "word selection mode" on double click. It
>>> seems to work well. The patch is here:
>>>
>>> http://www.lyx.org/trac/attachment/ticket/7890/0001-Fix-9160-and-7890.patch
>>>
>>> The only major issue is that when dragging to the left, you cannot
>>> highlight the first word. Does anyone have an idea for where to fix
>>> this?
>>>
>>> The following patch might give a clue as to where the problem is. When
>>> applied, you can select the first word. It is not meant to be taken as
>>> a correct patch:
>>>
>>> http://www.lyx.org/trac/attachment/ticket/7890/0002-HACK-just-to-show-where-the-problem-is.patch
>>
>> I'm still looking for help on this in case anyone is motivated.
>
> Still looking for help on this (perhaps just a guess on where in the
> code to look to fix the problem?). It would be nice to put this into
> 2.2.

I've made some progress. The attached patch does not suffer from not
being able to select the first word on a line, except if the line
spans several "screen lines" (i.e. the line wraps). In order to solve
the problem when the line is wrapped, how do I get the position of the
cursor on the visual line? I'm currently conditioning on pos() == 0. I
imagine I need to condition on something defined in frontend/ but I'm
not sure what.

Scott
From bbc5231387a886af1251c1a589fdac4521f79bf8 Mon Sep 17 00:00:00 2001
From: Scott Kostyshak <skost...@lyx.org>
Date: Sat, 25 Oct 2014 06:08:41 -0400
Subject: [PATCH] Word sel mode on double click (#9160 and #7890)

A double click now begins word selection mode.

Because of how LyX places the cursor on word selection,
there is an annoyance when doing word selection with the
mouse: if you double-click a word and drag to the left, the
word you double clicked will become unselected.
---
 src/Text.cpp  | 6 +++++-
 src/Text3.cpp | 3 +++
 2 files changed, 8 insertions(+), 1 deletion(-)

diff --git a/src/Text.cpp b/src/Text.cpp
index a2ae1ae..cce0db0 100644
--- a/src/Text.cpp
+++ b/src/Text.cpp
@@ -1227,6 +1227,7 @@ void Text::selectWord(Cursor & cur, word_location loc)
 	LBUFERR(this == cur.text());
 	CursorSlice from = cur.top();
 	CursorSlice to = cur.top();
+	CursorSlice to_orig = cur.top();
 	getWord(from, to, loc);
 	if (cur.top() != from)
 		setCursor(cur, from.pit(), from.pos());
@@ -1234,7 +1235,10 @@ void Text::selectWord(Cursor & cur, word_location loc)
 		return;
 	if (!cur.selection())
 		cur.resetAnchor();
-	setCursor(cur, to.pit(), to.pos());
+	if (to_orig.pos() == 0)
+		setCursor(cur, to.pit(), 0);
+	else
+		setCursor(cur, to.pit(), to.pos());
 	cur.setSelection();
 	cur.setWordSelection(true);
 }
diff --git a/src/Text3.cpp b/src/Text3.cpp
index fc8846e..d3d5141 100644
--- a/src/Text3.cpp
+++ b/src/Text3.cpp
@@ -1611,6 +1611,9 @@ void Text::dispatch(Cursor & cur, FuncRequest & cmd)
 		// reset the anchor.
 		bvcur.setCursor(cur);
 		bvcur.setSelection(true);
+		if (bvcur.wordSelection())
+			selectWord(bvcur, WHOLE_WORD);
+
 		if (cur.top() == old) {
 			// We didn't move one iota, so no need to update the screen.
 			cur.screenUpdateFlags(Update::SinglePar | Update::FitCursor);
-- 
2.1.0

Reply via email to