Tk Source Code

Artifact [84dbd2ee]
Login

Artifact 84dbd2ee38a315bbd66aee0fbfb7b23f5fadf9051c85e36c7fd53d559ee1a457:

Attachment "7655f65ae7-entrywidgets.diff" to ticket [7655f65a] added by chrstphrchvz 2020-04-16 01:38:05.
diff --git generic/tkEntry.c generic/tkEntry.c
index 9c53769f7..de6226ec0 100644
--- generic/tkEntry.c
+++ generic/tkEntry.c
@@ -1727,18 +1727,13 @@ DisplayEntry(
 	}
     }
 
-    /*
-     * Draw the text in two pieces: first the unselected portion, then the
-     * selected portion on top of it.
-     */
-
-    Tk_DrawTextLayout(entryPtr->display, pixmap, entryPtr->textGC,
-	    entryPtr->textLayout, entryPtr->layoutX, entryPtr->layoutY,
-	    entryPtr->leftIndex, entryPtr->numChars);
-
     if (showSelection && (entryPtr->state != STATE_DISABLED)
 	    && (entryPtr->selTextGC != entryPtr->textGC)
 	    && (entryPtr->selectFirst < entryPtr->selectLast)) {
+	/*
+	 * Draw the selected and unselected portions separately.
+	 * Do not redraw the selected portion (see bug 7655f65ae7).
+	 */
 	int selFirst;
 
 	if (entryPtr->selectFirst < entryPtr->leftIndex) {
@@ -1746,9 +1741,24 @@ DisplayEntry(
 	} else {
 	    selFirst = entryPtr->selectFirst;
 	}
+	if (entryPtr->leftIndex < selFirst) {
+	    Tk_DrawTextLayout(entryPtr->display, pixmap, entryPtr->textGC,
+		    entryPtr->textLayout, entryPtr->layoutX, entryPtr->layoutY,
+		    entryPtr->leftIndex, selFirst);
+	}
 	Tk_DrawTextLayout(entryPtr->display, pixmap, entryPtr->selTextGC,
 		entryPtr->textLayout, entryPtr->layoutX, entryPtr->layoutY,
 		selFirst, entryPtr->selectLast);
+	if (entryPtr->selectLast < entryPtr->numChars) {
+	    Tk_DrawTextLayout(entryPtr->display, pixmap, entryPtr->textGC,
+		    entryPtr->textLayout, entryPtr->layoutX, entryPtr->layoutY,
+		    entryPtr->selectLast, entryPtr->numChars);
+	}
+    } else {
+	/* Draw the entire visible text */
+	Tk_DrawTextLayout(entryPtr->display, pixmap, entryPtr->textGC,
+		entryPtr->textLayout, entryPtr->layoutX, entryPtr->layoutY,
+		entryPtr->leftIndex, entryPtr->numChars);
     }
 
     if (entryPtr->type == TK_SPINBOX) {
diff --git generic/ttk/ttkEntry.c generic/ttk/ttkEntry.c
index 96f3cf260..86cef4528 100644
--- generic/ttk/ttkEntry.c
+++ generic/ttk/ttkEntry.c
@@ -1274,16 +1274,27 @@ static void EntryDisplay(void *clientData, Drawable d)
     /* Draw the text:
      */
     gc = EntryGetGC(entryPtr, es.foregroundObj, clipRegion);
-    Tk_DrawTextLayout(
-	Tk_Display(tkwin), d, gc, entryPtr->entry.textLayout,
-	entryPtr->entry.layoutX, entryPtr->entry.layoutY,
-	leftIndex, rightIndex);
-    XSetClipMask(Tk_Display(tkwin), gc, None);
-    Tk_FreeGC(Tk_Display(tkwin), gc);
-
-    /* Overwrite the selected portion (if any) in the -selectforeground color:
-     */
     if (showSelection) {
+	/* Draw the selected and unselected portions separately.
+	 * Do not overwrite the selected portion (see bug 7655f65ae7).
+	 */
+	if (leftIndex < selFirst) {
+	    Tk_DrawTextLayout(
+		Tk_Display(tkwin), d, gc, entryPtr->entry.textLayout,
+		entryPtr->entry.layoutX, entryPtr->entry.layoutY,
+		leftIndex, selFirst);
+	}
+	if (selLast < rightIndex) {
+	    Tk_DrawTextLayout(
+		Tk_Display(tkwin), d, gc, entryPtr->entry.textLayout,
+		entryPtr->entry.layoutX, entryPtr->entry.layoutY,
+		selLast, rightIndex);
+	}
+	XSetClipMask(Tk_Display(tkwin), gc, None);
+	Tk_FreeGC(Tk_Display(tkwin), gc);
+
+	/* Draw the selected portion in the -selectforeground color:
+	 */
 	gc = EntryGetGC(entryPtr, es.selForegroundObj, clipRegion);
 	Tk_DrawTextLayout(
 	    Tk_Display(tkwin), d, gc, entryPtr->entry.textLayout,
@@ -1291,6 +1302,14 @@ static void EntryDisplay(void *clientData, Drawable d)
 	    selFirst, selLast);
 	XSetClipMask(Tk_Display(tkwin), gc, None);
 	Tk_FreeGC(Tk_Display(tkwin), gc);
+    } else {
+	/* Draw the entire visible text */
+	Tk_DrawTextLayout(
+	    Tk_Display(tkwin), d, gc, entryPtr->entry.textLayout,
+	    entryPtr->entry.layoutX, entryPtr->entry.layoutY,
+	    leftIndex, rightIndex);
+	XSetClipMask(Tk_Display(tkwin), gc, None);
+	Tk_FreeGC(Tk_Display(tkwin), gc);
     }
 
     /* Drop the region. Note that we have to manually remove the reference to