Index: library/entry.tcl ================================================================== --- library/entry.tcl +++ library/entry.tcl @@ -141,11 +141,11 @@ bind Entry <> { tk::EntryKeySelect %W [tk::EntryPreviousWord %W insert] tk::EntrySeeInsert %W } bind Entry <> { - tk::EntryKeySelect %W [tk::EntryNextWord %W insert] + tk::EntryKeySelect %W [tk::EntrySelectNextWord %W insert] tk::EntrySeeInsert %W } bind Entry <> { tk::EntrySetCursor %W 0 } @@ -586,46 +586,50 @@ $w insert insert $new EntrySeeInsert $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. + +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 +} + +# ::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. -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 - } -} 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 - } +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 -- # # Returns the index of the previous word position before a given Index: library/spinbox.tcl ================================================================== --- library/spinbox.tcl +++ library/spinbox.tcl @@ -151,11 +151,11 @@ bind Spinbox <> { ::tk::EntryKeySelect %W [::tk::EntryPreviousWord %W insert] ::tk::EntrySeeInsert %W } bind Spinbox <> { - ::tk::EntryKeySelect %W [::tk::EntryNextWord %W insert] + ::tk::EntryKeySelect %W [::tk::EntrySelectNextWord %W insert] ::tk::EntrySeeInsert %W } bind Spinbox <> { ::tk::EntrySetCursor %W 0 } Index: library/text.tcl ================================================================== --- library/text.tcl +++ library/text.tcl @@ -136,11 +136,11 @@ } bind Text <> { tk::TextKeySelect %W [tk::TextPrevPos %W insert tk::startOfPreviousWord] } bind Text <> { - tk::TextKeySelect %W [tk::TextNextWord %W insert] + tk::TextKeySelect %W [tk::TextSelectNextWord %W insert] } bind Text <> { tk::TextKeySelect %W [tk::TextPrevPara %W insert] } bind Text <> { @@ -1084,29 +1084,34 @@ } } } # ::tk::TextNextWord -- -# Returns the index of the next word position after a given position in the -# text. 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 text window in which the cursor is to move. +# start - Position at which to start search. + +proc ::tk::TextNextWord {w start} { + TextNextPos $w [TextNextPos $w $start tk::endOfWord] \ + tk::startOfNextWord +} + +# ::tk::TextSelectNextWord -- +# Returns the index of the next end-of-word position after a given +# position in the text. # # Arguments: # w - The text window in which the cursor is to move. # start - Position at which to start search. -if {[tk windowingsystem] eq "win32"} { - proc ::tk::TextNextWord {w start} { - TextNextPos $w [TextNextPos $w $start tk::endOfWord] \ - tk::startOfNextWord - } -} else { - proc ::tk::TextNextWord {w start} { - TextNextPos $w $start tk::endOfWord - } -} +proc ::tk::TextSelectNextWord {w start} { + TextNextPos $w $start tk::endOfWord +} + # ::tk::TextNextPos -- # Returns the index of the next position after the given starting # position in the text as computed by a specified function. # Index: library/ttk/entry.tcl ================================================================== --- library/ttk/entry.tcl +++ library/ttk/entry.tcl @@ -102,11 +102,11 @@ bind TEntry <> { ttk::entry::Move %W end } bind TEntry <> { ttk::entry::Extend %W prevchar } bind TEntry <> { ttk::entry::Extend %W nextchar } bind TEntry <> { ttk::entry::Extend %W prevword } -bind TEntry <> { ttk::entry::Extend %W nextword } +bind TEntry <> { ttk::entry::Extend %W selectnextword } bind TEntry <> { ttk::entry::Extend %W home } bind TEntry <> { ttk::entry::Extend %W end } bind TEntry <> { %W selection range 0 end } bind TEntry <> { %W selection clear } @@ -246,30 +246,41 @@ if {$c < [$w index @0] || $c >= [$w index @[winfo width $w]]} { $w xview $c } } -## NextWord -- Find the next word position. -# Note: The "next word position" follows platform conventions: -# either the next end-of-word position, or the start-of-word -# position following the next end-of-word position. -# -set ::ttk::entry::State(startNext) \ - [string equal [tk windowingsystem] "win32"] - +## NextWord -- +# Returns the index of the next start-of-word position after the next +# end-of-word position after a given position in the text. +# proc ttk::entry::NextWord {w start} { # the check on [winfo class] is because the spinbox and combobox also use this proc if {[winfo class $w] eq "TEntry" && [$w cget -show] ne ""} { return end } - variable State set pos [tk::endOfWord [$w get] [$w index $start]] - if {$pos >= 0 && $State(startNext)} { + if {$pos >= 0} { set pos [tk::startOfNextWord [$w get] $pos] } if {$pos < 0} { return end + } + return $pos +} + +## SelectNextWord -- +# Returns the index of the next end-of-word position after a given +# position in the text. +# +proc ttk::entry::SelectNextWord {w start} { + # the check on [winfo class] is because the spinbox and combobox also use this proc + if {[winfo class $w] eq "TEntry" && [$w cget -show] ne ""} { + return end + } + set pos [tk::endOfWord [$w get] [$w index $start]] + if {$pos < 0} { + return end } return $pos } ## PrevWord -- Find the previous word position. @@ -313,10 +324,11 @@ switch -- $where { prevchar { PrevChar $w $index } nextchar { NextChar $w $index } prevword { PrevWord $w $index } nextword { NextWord $w $index } + selectnextword { SelectNextWord $w $index } home { return 0 } end { $w index end } default { error "Bad relative index $index" } } } Index: tests/spinbox.test ================================================================== --- tests/spinbox.test +++ tests/spinbox.test @@ -3890,19 +3890,26 @@ } -result {can't trace "thisnsdoesntexist::myvar": parent namespace doesn't exist} test spinbox-25.3 {Bugs [2a32225cd1] and [9fa3e08243]} -setup { destroy .s pack [spinbox .s] update + set res {} } -body { .s insert end "A sample text" .s icursor end event generate .s <> ; # shall move insert to index 9 .s delete insert end - .s get + lappend res [.s get] + .s delete 0 end + .s insert end "A sample text" + .s icursor 2 + event generate .s <> ; # shall move insert to index 9 + .s delete 0 insert + lappend res [.s get] } -cleanup { destroy .s -} -result {A sample } +} -result {{A sample } text} # Collected comments about lacks from the test # XXX Still need to write tests for SpinboxBlinkProc, SpinboxFocusProc, # and SpinboxTextVarProc. # No tests for DisplaySpinbox. Index: tests/ttk/spinbox.test ================================================================== --- tests/ttk/spinbox.test +++ tests/ttk/spinbox.test @@ -289,19 +289,26 @@ test spinbox-11.2 {Bugs [2a32225cd1] and [9fa3e08243]} -setup { destroy .s pack [ttk::spinbox .s] update + set res {} } -body { .s insert end "A sample text" .s icursor end event generate .s <> ; # shall move insert to index 9 .s delete insert end - .s get + lappend res [.s get] + .s delete 0 end + .s insert end "A sample text" + .s icursor 2 + event generate .s <> ; # shall move insert to index 9 + .s delete 0 insert + lappend res [.s get] } -cleanup { destroy .s -} -result {A sample } +} -result {{A sample } text} # nostomp: NB intentional difference between ttk::spinbox and tk::spinbox; # see also #1439266 #