diff options
author | jan.nijtmans <nijtmans@users.sourceforge.net> | 2024-02-19 12:48:32 (GMT) |
---|---|---|
committer | jan.nijtmans <nijtmans@users.sourceforge.net> | 2024-02-19 12:48:32 (GMT) |
commit | 76acfc3d9d190b8c24dfddc364e45f0ecf5eb5c1 (patch) | |
tree | d37e3fddbc707331cd8ba2f5f2f6f3649cd5239b /library/entry.tcl | |
parent | dce78bcb0455e180116b61b634496b64c6e5254d (diff) | |
parent | fbc43284e28780ef359f599b6da2f7f3ed1d930a (diff) | |
download | tk-76acfc3d9d190b8c24dfddc364e45f0ecf5eb5c1.zip tk-76acfc3d9d190b8c24dfddc364e45f0ecf5eb5c1.tar.gz tk-76acfc3d9d190b8c24dfddc364e45f0ecf5eb5c1.tar.bz2 |
TIP #686: Make NextWord/SelectNextWord behavior platform-independant
Diffstat (limited to 'library/entry.tcl')
-rw-r--r-- | library/entry.tcl | 64 |
1 files changed, 34 insertions, 30 deletions
diff --git a/library/entry.tcl b/library/entry.tcl index 0509063..b344a63 100644 --- a/library/entry.tcl +++ b/library/entry.tcl @@ -143,7 +143,7 @@ bind Entry <<SelectPrevWord>> { tk::EntrySeeInsert %W } bind Entry <<SelectNextWord>> { - tk::EntryKeySelect %W [tk::EntryNextWord %W insert] + tk::EntryKeySelect %W [tk::EntrySelectNextWord %W insert] tk::EntrySeeInsert %W } bind Entry <<LineStart>> { @@ -588,42 +588,46 @@ proc ::tk::EntryTranspose w { } # ::tk::EntryNextWord -- -# Returns the index of the next word position after a given position in the -# entry. The next word is platform dependent and may be either the next -# end-of-word position or the next start-of-word position after the next -# end-of-word position. +# Returns the index of the next start-of-word position after the next +# end-of-word position after a given position in the text. # # Arguments: # w - The entry window in which the cursor is to move. # start - Position at which to start search. -if {[tk windowingsystem] eq "win32"} { - proc ::tk::EntryNextWord {w start} { - # the check on [winfo class] is because the spinbox also uses this proc - if {[winfo class $w] eq "Entry" && [$w cget -show] ne ""} { - return end - } - set pos [tk::endOfWord [$w get] [$w index $start]] - if {$pos >= 0} { - set pos [tk::startOfNextWord [$w get] $pos] - } - if {$pos < 0} { - return end - } - return $pos +proc ::tk::EntryNextWord {w start} { + # the check on [winfo class] is because the spinbox also uses this proc + if {[winfo class $w] eq "Entry" && [$w cget -show] ne ""} { + return end } -} else { - proc ::tk::EntryNextWord {w start} { - # the check on [winfo class] is because the spinbox also uses this proc - if {[winfo class $w] eq "Entry" && [$w cget -show] ne ""} { - return end - } - set pos [tk::endOfWord [$w get] [$w index $start]] - if {$pos < 0} { - return end - } - return $pos + set pos [tk::endOfWord [$w get] [$w index $start]] + if {$pos >= 0} { + set pos [tk::startOfNextWord [$w get] $pos] } + if {$pos < 0} { + return end + } + return $pos +} + +# ::tk::EntrySelectNextWord -- +# Returns the index of the next end-of-word position after a given +# position in the text. +# +# Arguments: +# w - The entry window in which the cursor is to move. +# start - Position at which to start search. + +proc ::tk::EntrySelectNextWord {w start} { + # the check on [winfo class] is because the spinbox also uses this proc + if {[winfo class $w] eq "Entry" && [$w cget -show] ne ""} { + return end + } + set pos [tk::endOfWord [$w get] [$w index $start]] + if {$pos < 0} { + return end + } + return $pos } # ::tk::EntryPreviousWord -- |