Issues With Enter/Leave Events

Try the following example:

set font [list [font configure TkTextFont -family] -36]
pack [text .t -width 10 -height 1 -background white -font $font]
.t tag configure word -background yellow
.t tag configure emph -background lightblue
.t tag bind word <Enter> {
    .t tag remove emph 1.0 end
    if {"a" in [.t tag names current]} { set word a } else { set word b }
    .t tag add emph $word.first $word.last
}
.t tag bind word <Leave> {
    .t tag remove emph 1.0 end
}
.t insert end "Alpha" {word a} "\u2009" {} "Beta" {word b}
.t configure -state disabled

When moving the mouse pointer slowly from "Alpha" to "Beta" (or vice versa) the word underneath the mouse pointer will be highlighted (with light blue). But when moving faster the highlighting does not work properly (tested with X11).

The reason is that the toolkit is collapsing mouse motion events per default. When moving the mouse pointer faster the intermediate motion events, when hovering the space between the words, are missing, and the event handling for tags does not work. In revised widget this has been fixed, the missing motion events for a proper Enter/Leave event handling will be computed.

Try next example:

set font [list [font configure TkFixedFont -family] -16]
text .t -width 17 -height 3 -background white -font $font -wrap word
pack .t -expand yes -fill both

.t tag configure hlalpha -background yellow
.t tag configure hlbeta  -background lightgreen
.t tag configure hlgamma -background lightblue

proc AddTag {t} {
    foreach {first last} [.t tag ranges $t] {
        if {[.t compare current >= $first] && [.t compare $last >= current]} {
            .t tag add hl$t $first $last
        }
    }
}

foreach t {alpha beta gamma} {
    .t tag bind $t <Enter> [list AddTag $t]
    .t tag bind $t <Leave> [list .t tag remove hl$t 1.0 end]
}

.t insert end "alpha" alpha  " " {}  "beta" beta  " " {}  "gamma" gamma  " "
.t insert end "alpha" alpha  " " {}  "beta" beta  " " {}  "gamma" gamma
.t configure -state disabled

Hover with mouse pointer the first "alpha", and then move to same word in second row. The highlighting does not work, because no Leave/Enter pair will be triggered, but this is required for a proper handling. The documentation (Tk text manual) about this point is not clear.

Shrink the width of the widget so that you will see three lines (instead of two), but the first and second line still contains the word "alpha". Now when hovering first "alpha", and then moving to next "alpha" in second line, the highlighting works. This means that in old implementation the tag event handling depends on contingencies of the layout (font, line wrapping, indentation), and this must not happen. With revised version the tag event handling is independend from layout, because an Leave/Enter pair will be triggered anyway when the display line is changing while moving the mouse pointer, provided it's not the same region (contiguous sequence of characters associated with this tag).