Updated 2012-10-08 01:00:52 by RLE

When text is inserted into a text widget via the keyboard, tags from the previous index are not inherited. In a c.l.t thread [1], Donal Fellows provides the following to accomplish this:
 Adrian Davis wrote:
 > Sorry, on second reading my posting was a bit ambiguous...
 >
 > ...I'm inserting the additional text into the end of the text widget by
 > typing it in directly using the keyboard.

 Ah, that's probably easier to do by using a new binding tag:

  # Copy the class bindings from the Text tag
  foreach seq [bind Text] {bind modText $seq [bind Text $seq]}
  # Install our new binding for normal insert
  bind modText <Key> {modTextInsert %W %A}
  proc modTextInsert {w s} {
     # This is copied from the Tk8.3 implementation
     if {[string equal $s ""] || [string equal [$w cget -state] "disabled"]} {
        return
     }
     catch {
        if {
           [$w compare sel.first <= insert] && [$w compare sel.last >= insert]
        } then {
           $w delete sel.first sel.last
        }
     }
     # The next line is the only substantive modification
     $w insert insert $s [$w tag names insert-1c]
     $w see insert
  }
  # Modify the bindings for the widget in question (in variable $w)
  bindtags $w [list $w modText [winfo toplevel $w] all]

 I'll leave handling <<Paste>> actions as an exercise.