Re: Text entered at different place than cursor

2022-01-02 Thread Jean-Marc Lasgouttes


Le 01/01/2022 à 17:29, Kornel Benko a écrit :

Am Sat, 1 Jan 2022 17:13:04 +0100
schrieb Jean-Marc Lasgouttes :


Le 01/01/2022 à 15:09, Kornel Benko a écrit :

Open the example.
Close comment.
You see the space before the comment.
Place cursor behind the space (but before the comment).
Open comment => cursor is moved into comment.


Forget it. Opening the comment via right-click works as expected.


Indeed LyX 2.3 does the same.

However I notice that LyX 2.3 does show the space before the opened
note, whereas my recent changes hide the space as at a automatic line break.

What is the preferred behavior? In fact, it would have been easier to
get the 2.3 behavior, so if it is good, I might as well redo the patch.

JMarc


I'd prefer to see the space if possible.


I played with 2.3 and the situation is very weird there: the space is 
here, but it is skipped with cursor-right.


Let's continue the discussion at #12499.
https://www.lyx.org/trac/ticket/12449

JMarc
--
lyx-devel mailing list
lyx-devel@lists.lyx.org
http://lists.lyx.org/mailman/listinfo/lyx-devel


Re: Text entered at different place than cursor

2022-01-01 Thread Kornel Benko
Am Sat, 1 Jan 2022 17:13:04 +0100
schrieb Jean-Marc Lasgouttes :

> Le 01/01/2022 à 15:09, Kornel Benko a écrit :
> >> Open the example.
> >> Close comment.
> >> You see the space before the comment.
> >> Place cursor behind the space (but before the comment).
> >> Open comment => cursor is moved into comment.  
> > 
> > Forget it. Opening the comment via right-click works as expected.  
> 
> Indeed LyX 2.3 does the same.
> 
> However I notice that LyX 2.3 does show the space before the opened 
> note, whereas my recent changes hide the space as at a automatic line break.
> 
> What is the preferred behavior? In fact, it would have been easier to 
> get the 2.3 behavior, so if it is good, I might as well redo the patch.
> 
> JMarc

I'd prefer to see the space if possible.

Kornel


pgp5bjRMJHrnM.pgp
Description: Digitale Signatur von OpenPGP
-- 
lyx-devel mailing list
lyx-devel@lists.lyx.org
http://lists.lyx.org/mailman/listinfo/lyx-devel


Re: Text entered at different place than cursor

2022-01-01 Thread Jean-Marc Lasgouttes

Le 01/01/2022 à 15:09, Kornel Benko a écrit :

Open the example.
Close comment.
You see the space before the comment.
Place cursor behind the space (but before the comment).
Open comment => cursor is moved into comment.


Forget it. Opening the comment via right-click works as expected.


Indeed LyX 2.3 does the same.

However I notice that LyX 2.3 does show the space before the opened 
note, whereas my recent changes hide the space as at a automatic line break.


What is the preferred behavior? In fact, it would have been easier to 
get the 2.3 behavior, so if it is good, I might as well redo the patch.


JMarc
--
lyx-devel mailing list
lyx-devel@lists.lyx.org
http://lists.lyx.org/mailman/listinfo/lyx-devel


Re: Text entered at different place than cursor

2022-01-01 Thread Kornel Benko
Am Sat, 1 Jan 2022 14:44:17 +0100
schrieb Kornel Benko :

> Am Sat, 1 Jan 2022 14:06:53 +0100
> schrieb Jean-Marc Lasgouttes :
> 
> > Le 15/12/2021 à 13:51, Scott Kostyshak a écrit :  
> > > In the attached example, there is a space between the main text and the
> > > note inset. If I put the cursor at the end of the second visual line
> > > (see the screenshot for what I refer to visual lines), it appears to be
> > > after the space, but if I enter text it is entered before the space.
> > > 
> > > JMarc, I'm guessing this is for you?
> > 
> > Here is a tentative fix. I'd appreciate if somebody could give it a 
> > quick go before I commit, since I could have forgotten something obvious 
> > and embarrassing.
> > 
> > Best wishes,
> > JMarc  
> 
> Open the example.
> Close comment.
> You see the space before the comment.
> Place cursor behind the space (but before the comment).
> Open comment => cursor is moved into comment.
> 
>   Kornel

Forget it. Opening the comment via right-click works as expected.

Kornel


pgpg7mXD1fYUf.pgp
Description: Digitale Signatur von OpenPGP
-- 
lyx-devel mailing list
lyx-devel@lists.lyx.org
http://lists.lyx.org/mailman/listinfo/lyx-devel


Re: Text entered at different place than cursor

2022-01-01 Thread Kornel Benko
Am Sat, 1 Jan 2022 14:06:53 +0100
schrieb Jean-Marc Lasgouttes :

> Le 15/12/2021 à 13:51, Scott Kostyshak a écrit :
> > In the attached example, there is a space between the main text and the
> > note inset. If I put the cursor at the end of the second visual line
> > (see the screenshot for what I refer to visual lines), it appears to be
> > after the space, but if I enter text it is entered before the space.
> > 
> > JMarc, I'm guessing this is for you?  
> 
> Here is a tentative fix. I'd appreciate if somebody could give it a 
> quick go before I commit, since I could have forgotten something obvious 
> and embarrassing.
> 
> Best wishes,
> JMarc

Open the example.
Close comment.
You see the space before the comment.
Place cursor behind the space (but before the comment).
Open comment => cursor is moved into comment.

Kornel


pgppPF7rK2skS.pgp
Description: Digitale Signatur von OpenPGP
-- 
lyx-devel mailing list
lyx-devel@lists.lyx.org
http://lists.lyx.org/mailman/listinfo/lyx-devel


Re: Text entered at different place than cursor

2022-01-01 Thread Jean-Marc Lasgouttes

Le 15/12/2021 à 13:51, Scott Kostyshak a écrit :

In the attached example, there is a space between the main text and the
note inset. If I put the cursor at the end of the second visual line
(see the screenshot for what I refer to visual lines), it appears to be
after the space, but if I enter text it is entered before the space.

JMarc, I'm guessing this is for you?


Here is a tentative fix. I'd appreciate if somebody could give it a 
quick go before I commit, since I could have forgotten something obvious 
and embarrassing.


Best wishes,
JMarcFrom ebaf374113aec5e7734708661eb99ec35d02282d Mon Sep 17 00:00:00 2001
From: Jean-Marc Lasgouttes 
Date: Tue, 28 Dec 2021 20:56:57 +0100
Subject: [PATCH] Better handling of trailing spaces in rows.

When a string is broken at the margin by the Qt algorithm, the space
at which breaking occurred is automatically skipped in width
computation. However, the ending space of the string is taken into
account and is visible for example at paragraph end.

When the trailing space is followed by a displayed inset, then the
space should be skipped too, which means that the width of the last
row element has to be recomputed. For the sake of performance, the
width of the element without trailing spaces is computed in advance in
FontMetrics::breakString.

This "no space" width will be used when trimming a row element of its trailing
spaces instead of the original one.

Fixes bug with trailing space before display inset.
---
 src/Row.cpp |  2 ++
 src/Row.h   |  4 +++-
 src/frontends/FontMetrics.h |  7 +-
 src/frontends/qt/GuiFontMetrics.cpp | 35 -
 4 files changed, 35 insertions(+), 13 deletions(-)

diff --git a/src/Row.cpp b/src/Row.cpp
index 6d6d319194..41b9ce0596 100644
--- a/src/Row.cpp
+++ b/src/Row.cpp
@@ -172,6 +172,7 @@ bool Row::Element::splitAt(int const width, int next_width, bool force,
 		e.str = str.substr(i, brk.len);
 		e.endpos = e.pos + brk.len;
 		e.dim.wid = brk.wid;
+		e.nspc_wid = brk.nspc_wid;
 		e.row_flags = CanBreakInside | BreakAfter;
 		if (first) {
 			// this element eventually goes to *this
@@ -218,6 +219,7 @@ void Row::Element::rtrim()
 	 */
 	str = support::rtrim(str);
 	endpos = pos + str.length();
+	dim.wid = nspc_wid;
 }
 
 
diff --git a/src/Row.h b/src/Row.h
index 2c60638f34..aba7913fdb 100644
--- a/src/Row.h
+++ b/src/Row.h
@@ -119,9 +119,11 @@ public:
 		pos_type pos;
 		// first position after the element in the paragraph
 		pos_type endpos;
-		// The dimension of the chunk (does not contains the
+		// The dimension of the chunk (does not contain the
 		// separator correction)
 		Dimension dim;
+		// The width of the element without trailing spaces
+		int nspc_wid = 0;
 
 		// Non-zero only if element is an inset
 		Inset const * inset = nullptr;
diff --git a/src/frontends/FontMetrics.h b/src/frontends/FontMetrics.h
index b78bc2dbcd..66cd22d439 100644
--- a/src/frontends/FontMetrics.h
+++ b/src/frontends/FontMetrics.h
@@ -126,9 +126,14 @@ public:
 
 	// The places where to break a string and the width of the resulting lines.
 	struct Break {
-		Break(int l, int w) : len(l), wid(w) {}
+		Break(int l, int w, int nsw) : len(l), wid(w), nspc_wid(nsw) {}
+		// Number of characters
 		int len = 0;
+		// text width
 		int wid = 0;
+		// text width when trailing spaces are removed; only makes a
+		// difference for the last break.
+		int nspc_wid = 0;
 	};
 	typedef std::vector Breaks;
 	/**
diff --git a/src/frontends/qt/GuiFontMetrics.cpp b/src/frontends/qt/GuiFontMetrics.cpp
index e638e10d09..0dc0de5cb4 100644
--- a/src/frontends/qt/GuiFontMetrics.cpp
+++ b/src/frontends/qt/GuiFontMetrics.cpp
@@ -19,7 +19,6 @@
 
 #include "support/convert.h"
 #include "support/lassert.h"
-#include "support/lstrings.h"
 #include "support/lyxlib.h"
 #include "support/debug.h"
 
@@ -579,9 +578,6 @@ GuiFontMetrics::breakString_helper(docstring const & s, int first_wid, int wid,
 	 */
 	to.setWrapMode(force ? QTextOption::WrapAtWordBoundaryOrAnywhere
 	 : QTextOption::WordWrap);
-	// Let QTextLine::naturalTextWidth() account for trailing spaces
-	// (horizontalAdvance() still does not).
-	to.setFlags(QTextOption::IncludeTrailingSpaces);
 	tl.setTextOption(to);
 
 	bool first = true;
@@ -600,26 +596,43 @@ GuiFontMetrics::breakString_helper(docstring const & s, int first_wid, int wid,
 	int pos = 0;
 	for (int i = 0 ; i < tl.lineCount() ; ++i) {
 		QTextLine const & line = tl.lineAt(i);
-		int const epos = brkstr2str_pos(qs, s, line.textStart() + line.textLength());
+		int const line_epos = line.textStart() + line.textLength();
+		int const epos = brkstr2str_pos(qs, s, line_epos);
 #if QT_VERSION >= 0x05
-		int const wid = i + 1 < tl.lineCount() ? iround(line.horizontalAdvance())
-		   : iround(line.naturalTextWidth());
+		// This does not take trailing spaces into account, except for the last line.
+		int const wid = 

Re: Text entered at different place than cursor

2021-12-27 Thread Jean-Marc Lasgouttes

Le 27/12/2021 à 17:39, Scott Kostyshak a écrit :

On Wed, Dec 15, 2021 at 07:51:35AM -0500, Scott Kostyshak wrote:

In the attached example, there is a space between the main text and the
note inset. If I put the cursor at the end of the second visual line
(see the screenshot for what I refer to visual lines), it appears to be
after the space, but if I enter text it is entered before the space.

JMarc, I'm guessing this is for you?


JMarc can you reproduce?


Sorry I forgot about it. I will check, this may be my fault.

JMarc
--
lyx-devel mailing list
lyx-devel@lists.lyx.org
http://lists.lyx.org/mailman/listinfo/lyx-devel


Re: Text entered at different place than cursor

2021-12-27 Thread Scott Kostyshak
On Wed, Dec 15, 2021 at 07:51:35AM -0500, Scott Kostyshak wrote:
> In the attached example, there is a space between the main text and the
> note inset. If I put the cursor at the end of the second visual line
> (see the screenshot for what I refer to visual lines), it appears to be
> after the space, but if I enter text it is entered before the space.
> 
> JMarc, I'm guessing this is for you?

JMarc can you reproduce?

Scott


signature.asc
Description: PGP signature
-- 
lyx-devel mailing list
lyx-devel@lists.lyx.org
http://lists.lyx.org/mailman/listinfo/lyx-devel


Text entered at different place than cursor

2021-12-15 Thread Scott Kostyshak
In the attached example, there is a space between the main text and the
note inset. If I put the cursor at the end of the second visual line
(see the screenshot for what I refer to visual lines), it appears to be
after the space, but if I enter text it is entered before the space.

JMarc, I'm guessing this is for you?


cursor-diff-from-entry.23.lyx
Description: application/lyx


signature.asc
Description: PGP signature
-- 
lyx-devel mailing list
lyx-devel@lists.lyx.org
http://lists.lyx.org/mailman/listinfo/lyx-devel