zsh-workers
 help / color / mirror / code / Atom feed
* PATCH: fix updates to region_highlight, accounting for PREDISPLAY
@ 2023-01-10 16:55 Oliver Kiddle
  2023-01-11 13:01 ` Oliver Kiddle
  0 siblings, 1 reply; 2+ messages in thread
From: Oliver Kiddle @ 2023-01-10 16:55 UTC (permalink / raw)
  To: Zsh workers

I've been paying more attention than usual to any glitches related to
terminal attributes and this fixes an old bug where dynamic updates to
region_highlight failed to allow for the PREDISPLAY part of the buffer.
You can see this bug by invoking Functions/Zle/replace-string, typing a
few characters and then using backspace - bold highlighting is lost.

I think the intention in read-from-minibuffer is that bold is only used
for the prompt. But the user-entered string starts empty and when new
characters are added to the right of a region_highlight entry, they
are included. We could solve this by excluding bold highlighting for
the final space in the read-from-minibuffer prompt but the prompt is a
parameter and may not end in a space. It would be possible to add ZRH_*
flags and some syntax for whether regions expand for new characters at
the left and right. Or perhaps just make a special case for the end of
PREDISPLAY?

I'm not certain of the code path to reach the meta half of shiftchars().

Oliver

diff --git a/Src/Zle/zle_utils.c b/Src/Zle/zle_utils.c
index 1a580a9e6..45a82dd5e 100644
--- a/Src/Zle/zle_utils.c
+++ b/Src/Zle/zle_utils.c
@@ -866,13 +866,13 @@ shiftchars(int to, int cnt)
 		    if (rhp->start_meta - sub > to + cnt)
 			rhp->start_meta -= cnt;
 		    else
-			rhp->start_meta = to;
+			rhp->start_meta = to + sub;
 		}
 		if (rhp->end_meta - sub > to) {
 		    if (rhp->end_meta - sub > to + cnt)
 			rhp->end_meta -= cnt;
 		    else
-			rhp->end_meta = to;
+			rhp->end_meta = to + sub;
 		}
 	    }
 	}
@@ -896,13 +896,13 @@ shiftchars(int to, int cnt)
 		    if (rhp->start - sub > to + cnt)
 			rhp->start -= cnt;
 		    else
-			rhp->start = to;
+			rhp->start = to + sub;
 		}
 		if (rhp->end - sub > to) {
 		    if (rhp->end - sub > to + cnt)
 			rhp->end -= cnt;
 		    else
-			rhp->end = to;
+			rhp->end = to + sub;
 		}
 	    }
 	}


^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: PATCH: fix updates to region_highlight, accounting for PREDISPLAY
  2023-01-10 16:55 PATCH: fix updates to region_highlight, accounting for PREDISPLAY Oliver Kiddle
@ 2023-01-11 13:01 ` Oliver Kiddle
  0 siblings, 0 replies; 2+ messages in thread
From: Oliver Kiddle @ 2023-01-11 13:01 UTC (permalink / raw)
  To: Zsh workers

I wrote:
> Or perhaps just make a special case for the end of PREDISPLAY?

After thinking about it, this approach is probably logical. It is
already the case that a region will only be extended at the end if the
cursor is positioned there.

In testing this, I also found an old bug where attributes could be
messed up because they were saved to an int instead of a zattr.

Oliver

diff --git a/Src/Zle/zle_utils.c b/Src/Zle/zle_utils.c
index 45a82dd5e..9ce91049c 100644
--- a/Src/Zle/zle_utils.c
+++ b/Src/Zle/zle_utils.c
@@ -580,7 +580,7 @@ struct zle_region;
 struct zle_region  {
     struct zle_region *next;
     /* Entries of region_highlight, as needed */
-    int atr;
+    zattr atr;
     int start;
     int end;
     int flags;
@@ -799,7 +799,7 @@ spaceinline(int ct)
 		if (rhp->start_meta - sub >= zlemetacs) {
 		    rhp->start_meta += ct;
 		}
-		if (rhp->end_meta - sub >= zlemetacs) {
+		if (rhp->end_meta - sub >= zlemetacs && (!predisplaylen || zlecs)) {
 		    rhp->end_meta += ct;
 		}
 	    }
@@ -827,7 +827,7 @@ spaceinline(int ct)
 		if (rhp->start - sub >= zlecs) {
 		    rhp->start += ct;
 		}
-		if (rhp->end - sub >= zlecs) {
+		if (rhp->end - sub >= zlecs && (!predisplaylen || zlecs)) {
 		    rhp->end += ct;
 		}
 	    }


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2023-01-11 13:01 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-01-10 16:55 PATCH: fix updates to region_highlight, accounting for PREDISPLAY Oliver Kiddle
2023-01-11 13:01 ` Oliver Kiddle

Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/zsh/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).