diff options
-rw-r--r-- | library/entry.tcl | 42 | ||||
-rw-r--r-- | library/spinbox.tcl | 14 | ||||
-rw-r--r-- | library/text.tcl | 12 | ||||
-rw-r--r-- | library/tk.tcl | 30 | ||||
-rw-r--r-- | library/ttk/entry.tcl | 29 |
5 files changed, 102 insertions, 25 deletions
diff --git a/library/entry.tcl b/library/entry.tcl index 99f6eb4..3652ebe 100644 --- a/library/entry.tcl +++ b/library/entry.tcl @@ -119,17 +119,17 @@ bind Entry <Control-Button-1> { } bind Entry <<PrevChar>> { - tk::EntrySetCursor %W [expr {[%W index insert]-1}] + tk::EntrySetCursor %W [tk::EntryPreviousChar %W insert] } bind Entry <<NextChar>> { - tk::EntrySetCursor %W [expr {[%W index insert]+1}] + tk::EntrySetCursor %W [tk::EntryNextChar %W insert] } bind Entry <<SelectPrevChar>> { - tk::EntryKeySelect %W [expr {[%W index insert]-1}] + tk::EntryKeySelect %W [tk::EntryPreviousChar %W insert] tk::EntrySeeInsert %W } bind Entry <<SelectNextChar>> { - tk::EntryKeySelect %W [expr {[%W index insert]+1}] + tk::EntryKeySelect %W [tk::EntryNextChar %W insert] tk::EntrySeeInsert %W } bind Entry <<PrevWord>> { @@ -165,7 +165,7 @@ bind Entry <Delete> { if {[%W selection present]} { %W delete sel.first sel.last } else { - %W delete insert + %W delete [::tk::startOfGlyphCluster [%W get] [%W index insert]] [::tk::endOfGlyphCluster [%W get] [%W index insert]] } } bind Entry <BackSpace> { @@ -503,9 +503,10 @@ proc ::tk::EntryBackspace w { if {[$w selection present]} { $w delete sel.first sel.last } else { - set x [$w index insert] - if {$x > 0} { - $w delete [expr {$x-1}] + set x [expr {[$w index insert] - 1}] + if {$x >= 0} { + $w delete [::tk::startOfGlyphCluster [$w get] $x] \ + [::tk::endOfGlyphCluster [$w get] $x] } if {[$w index @0] >= [$w index insert]} { set range [$w xview] @@ -619,6 +620,31 @@ proc ::tk::EntryPreviousWord {w start} { return $pos } +proc ::tk::EntryNextChar {w start} { + set pos [::tk::endOfGlyphCluster [$w get] [$w index $start]] + if {$pos < 0} { + return end + } + return $pos +} + +proc ::tk::EntryPreviousChar {w start} { + set pos [::tk::startOfGlyphCluster [$w get] [expr {[$w index $start]-1}]] + if {$pos < 0} { + return 0 + } + return $pos +} + +proc ::tk::EntryInsertChar {w start} { + set pos [::tk::endOfGlyphCluster [$w get] [$w index $start]] + if {$pos < 0} { + return end + } + return $pos +} + + # ::tk::EntryScanMark -- # # Marks the start of a possible scan drag operation diff --git a/library/spinbox.tcl b/library/spinbox.tcl index ad4aacc..6d740bc 100644 --- a/library/spinbox.tcl +++ b/library/spinbox.tcl @@ -129,18 +129,18 @@ bind Spinbox <<NextLine>> { } bind Spinbox <<PrevChar>> { - ::tk::EntrySetCursor %W [expr {[%W index insert] - 1}] + tk::EntrySetCursor %W [tk::EntryPreviousChar %W insert] } bind Spinbox <<NextChar>> { - ::tk::EntrySetCursor %W [expr {[%W index insert] + 1}] + tk::EntrySetCursor %W [tk::EntryNextChar %W insert] } bind Spinbox <<SelectPrevChar>> { - ::tk::EntryKeySelect %W [expr {[%W index insert] - 1}] - ::tk::EntrySeeInsert %W + tk::EntryKeySelect %W [tk::EntryPreviousChar %W insert] + tk::EntrySeeInsert %W } bind Spinbox <<SelectNextChar>> { - ::tk::EntryKeySelect %W [expr {[%W index insert] + 1}] - ::tk::EntrySeeInsert %W + tk::EntryKeySelect %W [tk::EntryNextChar %W insert] + tk::EntrySeeInsert %W } bind Spinbox <<PrevWord>> { ::tk::EntrySetCursor %W [::tk::EntryPreviousWord %W insert] @@ -175,7 +175,7 @@ bind Spinbox <Delete> { if {[%W selection present]} { %W delete sel.first sel.last } else { - %W delete insert + %W delete [::tk::startOfGlyphCluster [%W get] [%W index insert]] [::tk::endOfGlyphCluster [%W get] [%W index insert]] } } bind Spinbox <BackSpace> { diff --git a/library/text.tcl b/library/text.tcl index aa6c3f5..5db9453 100644 --- a/library/text.tcl +++ b/library/text.tcl @@ -99,10 +99,10 @@ bind Text <Double-Control-Button-1> { # nothing } # stop an accidental movement triggering <B1-Motion> bind Text <Control-B1-Motion> { # nothing } bind Text <<PrevChar>> { - tk::TextSetCursor %W insert-1displayindices + tk::TextSetCursor %W [tk::TextPrevPos %W insert ::tk::startOfGlyphCluster] } bind Text <<NextChar>> { - tk::TextSetCursor %W insert+1displayindices + tk::TextSetCursor %W [tk::TextNextPos %W insert ::tk::endOfGlyphCluster] } bind Text <<PrevLine>> { tk::TextSetCursor %W [tk::TextUpDownLine %W -1] @@ -111,10 +111,10 @@ bind Text <<NextLine>> { tk::TextSetCursor %W [tk::TextUpDownLine %W 1] } bind Text <<SelectPrevChar>> { - tk::TextKeySelect %W [%W index {insert - 1displayindices}] + tk::TextKeySelect %W [tk::TextPrevPos %W insert ::tk::startOfGlyphCluster] } bind Text <<SelectNextChar>> { - tk::TextKeySelect %W [%W index {insert + 1displayindices}] + tk::TextKeySelect %W [tk::TextNextPos %W insert ::tk::endOfGlyphCluster] } bind Text <<SelectPrevLine>> { tk::TextKeySelect %W [tk::TextUpDownLine %W -1] @@ -222,7 +222,7 @@ bind Text <Delete> { %W delete sel.first sel.last } else { if {[%W compare end != insert+1c]} { - %W delete insert + %W delete [tk::TextPrevPos %W insert+1c ::tk::startOfGlyphCluster] [tk::TextNextPos %W insert ::tk::endOfGlyphCluster] } %W see insert } @@ -232,7 +232,7 @@ bind Text <BackSpace> { %W delete sel.first sel.last } else { if {[%W compare insert != 1.0]} { - %W delete insert-1c + %W delete [tk::TextPrevPos %W insert ::tk::startOfGlyphCluster] [tk::TextNextPos %W insert-1c ::tk::endOfGlyphCluster] } %W see insert } diff --git a/library/tk.tcl b/library/tk.tcl index 86956de..b1b7629 100644 --- a/library/tk.tcl +++ b/library/tk.tcl @@ -700,6 +700,36 @@ if {[tk windowingsystem] eq "aqua"} { } } +proc ::tk::endOfGlyphCluster {str start} { + if {$start >= [string length $str]} { + return -1; + } + if {[string length [string index $str $start]] > 1} { + set start [expr {$start+1}] + } + set start [expr {$start+1}] + if {[string index $str $start] eq {^}} { + set start [expr {$start+1}];# For demo purposes only + } + return $start +} + +proc ::tk::startOfGlyphCluster {str start} { + if {$start eq "end"} { + set start [expr {[string length $str]-1}] + } + if {$start < 0} { + return -1; + } + if {[string index $str $start] eq {^}} { + set start [expr {$start-1}];# For demo purposes only + } + if {[string length [string index $str [expr {$start-1}]]] > 1} { + return [expr {$start-1}] + } + return $start +} + # Create a dictionary to store the starting index of the IME marked # text in an Entry or Text widget. diff --git a/library/ttk/entry.tcl b/library/ttk/entry.tcl index 8c89435..16f6108 100644 --- a/library/ttk/entry.tcl +++ b/library/ttk/entry.tcl @@ -268,12 +268,33 @@ proc ttk::entry::PrevWord {w start} { return $pos } +## NextChar -- Find the next char position. +# +proc ttk::entry::NextChar {w start} { + variable State + set pos [::tk::endOfGlyphCluster [$w get] [$w index $start]] + if {$pos < 0} { + return end + } + return $pos +} + +## PrevChar -- Find the previous word position. +# +proc ttk::entry::PrevChar {w start} { + set pos [::tk::startOfGlyphCluster [$w get] [expr {[$w index $start]-1}]] + if {$pos < 0} { + return 0 + } + return $pos +} + ## RelIndex -- Compute character/word/line-relative index. # proc ttk::entry::RelIndex {w where {index insert}} { switch -- $where { - prevchar { expr {[$w index $index] - 1} } - nextchar { expr {[$w index $index] + 1} } + prevchar { PrevChar $w $index } + nextchar { NextChar $w $index } prevword { PrevWord $w $index } nextword { NextWord $w $index } home { return 0 } @@ -604,7 +625,7 @@ proc ttk::entry::Backspace {w} { set x [expr {[$w index insert] - 1}] if {$x < 0} { return } - $w delete $x + $w delete [::tk::startOfGlyphCluster [$w get] $x] [::tk::endOfGlyphCluster [$w get] $x] if {[$w index @0] >= [$w index insert]} { set range [$w xview] @@ -619,7 +640,7 @@ proc ttk::entry::Backspace {w} { # proc ttk::entry::Delete {w} { if {![PendingDelete $w]} { - $w delete insert + $w delete [::tk::startOfGlyphCluster [$w get] [$w index insert]] [::tk::endOfGlyphCluster [$w get] [$w index insert]] } } |