From 1fd741b0b4c30061a7a61056f53dd0421e9353b4 Mon Sep 17 00:00:00 2001 From: "jan.nijtmans" Date: Fri, 26 Jan 2024 16:17:54 +0000 Subject: Possible fix for [55e742aea6]: In text, Ctrl+Left and Ctrl+Right behave different in Windows and Linux. Text-widget only (for now). Entry and Spinbox will need the same change. For discussion. --- library/text.tcl | 33 +++++++++++++++++++-------------- 1 file changed, 19 insertions(+), 14 deletions(-) diff --git a/library/text.tcl b/library/text.tcl index 99d5841..15bdef2 100644 --- a/library/text.tcl +++ b/library/text.tcl @@ -138,7 +138,7 @@ 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] @@ -1086,26 +1086,31 @@ proc ::tk_textPaste w { } # ::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. -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::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. + +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. -- cgit v0.12 From c8a2197a8f8889526bac61c8f6bc61f27ec225f4 Mon Sep 17 00:00:00 2001 From: "jan.nijtmans" Date: Sat, 27 Jan 2024 00:13:30 +0000 Subject: Same change for Entry en (ttk::)spinbox --- library/entry.tcl | 60 +++++++++++++++++++++++++++------------------------ library/spinbox.tcl | 2 +- library/ttk/entry.tcl | 31 ++++++++++++++++++-------- 3 files changed, 55 insertions(+), 38 deletions(-) diff --git a/library/entry.tcl b/library/entry.tcl index e8f260b..2090fa7 100644 --- a/library/entry.tcl +++ b/library/entry.tcl @@ -143,7 +143,7 @@ bind Entry <> { tk::EntrySeeInsert %W } bind Entry <> { - tk::EntryKeySelect %W [tk::EntryNextWord %W insert] + tk::EntryKeySelect %W [tk::EntrySelectNextWord %W insert] tk::EntrySeeInsert %W } bind Entry <> { @@ -588,40 +588,44 @@ 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} { - if {[$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} { + if {[$w cget -show] ne ""} { + return end } -} else { - proc ::tk::EntryNextWord {w start} { - if {[$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::EntryNextWord -- +# 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} { + if {[$w cget -show] ne ""} { + return end } + set pos [tk::endOfWord [$w get] [$w index $start]] + if {$pos < 0} { + return end + } + return $pos } # ::tk::EntryPreviousWord -- diff --git a/library/spinbox.tcl b/library/spinbox.tcl index 1430800..094be29 100644 --- a/library/spinbox.tcl +++ b/library/spinbox.tcl @@ -153,7 +153,7 @@ bind Spinbox <> { ::tk::EntrySeeInsert %W } bind Spinbox <> { - ::tk::EntryKeySelect %W [::tk::EntryNextWord %W insert] + ::tk::EntryKeySelect %W [::tk::EntrySelectNextWord %W insert] ::tk::EntrySeeInsert %W } bind Spinbox <> { diff --git a/library/ttk/entry.tcl b/library/ttk/entry.tcl index d5170fd..b01e6a2 100644 --- a/library/ttk/entry.tcl +++ b/library/ttk/entry.tcl @@ -104,7 +104,7 @@ 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 } @@ -248,21 +248,17 @@ proc ttk::entry::See {w {index insert}} { } } -## 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. +## 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. # -set ::ttk::entry::State(startNext) \ - [string equal [tk windowingsystem] "win32"] - proc ttk::entry::NextWord {w start} { if {[$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} { @@ -271,6 +267,22 @@ proc ttk::entry::NextWord {w start} { 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} { + if {[$w cget -show] ne ""} { + return end + } + variable State + set pos [tk::endOfWord [$w get] [$w index $start]] + if {$pos < 0} { + return end + } + return $pos +} + ## PrevWord -- Find the previous word position. # proc ttk::entry::PrevWord {w start} { @@ -313,6 +325,7 @@ proc ttk::entry::RelIndex {w where {index insert}} { 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" } -- cgit v0.12 From 331436fe3c1504028557d2b648bbf4cdbf8fa78f Mon Sep 17 00:00:00 2001 From: "jan.nijtmans" Date: Mon, 29 Jan 2024 22:27:52 +0000 Subject: Test <> --- tests/spinbox.test | 11 +++++++++-- tests/ttk/spinbox.test | 11 +++++++++-- 2 files changed, 18 insertions(+), 4 deletions(-) diff --git a/tests/spinbox.test b/tests/spinbox.test index 4187966..6cb52e9 100644 --- a/tests/spinbox.test +++ b/tests/spinbox.test @@ -3892,15 +3892,22 @@ 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, diff --git a/tests/ttk/spinbox.test b/tests/ttk/spinbox.test index 0a3f943..1f32049 100644 --- a/tests/ttk/spinbox.test +++ b/tests/ttk/spinbox.test @@ -291,15 +291,22 @@ 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; -- cgit v0.12