Many hyperlinks are disabled.
Use anonymous login
to enable hyperlinks.
Overview
Comment: | Module ntext - update to 1.0b1 |
---|---|
Downloads: | Tarball | ZIP archive | SQL archive |
Timelines: | family | ancestors | descendants | both | trunk |
Files: | files | file ages | folders |
SHA1: |
10d06551a61e619c0bfda3536907f1b1 |
User & Date: | kjnash 2017-03-31 17:13:21 |
Context
2017-04-01
| ||
15:02 | Regenerate Documentation check-in: ae1cf5fefc user: kjnash tags: trunk | |
2017-03-31
| ||
17:13 | Module ntext - update to 1.0b1 check-in: 10d06551a6 user: kjnash tags: trunk | |
2017-03-30
| ||
18:00 | Correct a small bug in the configuration of the plaintext annotations (reported by Nick Matthews) check-in: 63dbc64d55 user: markus tags: trunk | |
Changes
Changes to examples/ntext/ntextDemoBindings.tcl.
|
| | > > | > > | > > | | > > > > > > > > > | | | | | | | | | | | | | | | | | | | | | | | > > > > > | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 | #!/bin/sh # the next line restarts using tclsh \ exec tclsh "$0" "$@" package require Tk # Copyright (c) 2005-2017 Keith Nash. # # See the file "license.terms" for information on usage and redistribution # of this file, and for a DISCLAIMER OF ALL WARRANTIES. ### This demo explores the ntext options ### For a short example, see ntextExample.tcl ### To explore ntext indentation, try ntextDemoIndent.tcl ### To explore vertical scrolling on the Mac, try ntextDemoMacScrolling.tcl # This string defines the text that will be displayed in each widget: set message {QOTW: "C/C++, which is used by 16% of users, is the most popular programming language, but Tcl, used by 0%, seems to be the language of choice for the highest scoring users." example code {alph {bet {b}} {gam {c}}} { # Example code rich in punctuation if {!($alph eq "a" && $bet eq "b")} { puts "$gam $::messages::demo(d)" } } Try editing the text with the keyboard and mouse; compare the bindings for Text (left panel) and Ntext (right panel). Try word-by-word navigation (Control key with left cursor or right cursor key); try word selection (double click); try these for the different word-break detection options (selected below). The classicMouseSelect and classicAnchor options are discussed in the man page for ntextBindings.} # End of string for widget text. package require ntext 1.0 # Whether Shift-Button-1 ignores changes made by the kbd to the insert mark: set ::ntext::classicMouseSelect 0 # Whether Shift-Button-1 has a variable or fixed anchor: set ::ntext::classicAnchor 0 # Whether the traditional "extra" bindings are activated (default is 0): set ::ntext::classicExtras 1 # Whether to use new or classic word boundary detection: set ::ntext::classicWordBreak 0 # Set to 0 to align wrapped display lines with the first display line of the logical line: set ::ntext::classicWrap 1 # Set to 0 to follow Mac Aqua conventions on placement of the insert mark # when a selection is cancelled by keyboard navigation: # Has effect on all platforms. Default value is 0 on Aqua, 1 on other platforms. # set ::ntext::classicSelection 1 set col #e0dfde . configure -bg $col pack [frame .rhf -bg $col] -side right -anchor nw pack [text .rhf.new ] -padx 2 bindtags .rhf.new {.rhf.new Ntext . all} .rhf.new configure -wrap word -undo 1 .rhf.new configure -width 42 -height 29 -font {{Courier} -15} -bg white .rhf.new insert end " I use the Ntext bindings.\n\n$message" .rhf.new edit separator pack [frame .lhf -bg $col] -side left -anchor ne pack [text .lhf.classic ] -padx 2 .lhf.classic configure -width 42 -height 29 -wrap word -undo 1 -font {{Courier} -15} -bg #FFFFCC .lhf.classic insert end " I use the (default) Text bindings.\n\n$message" .lhf.classic edit separator pack [label .lhf.m -bg $col -text "(The radiobutton controls do not\napply to the left-hand text widget)"] pack [frame .rhf.h -bg $col] -fill x pack [radiobutton .rhf.h.on -bg $col -text "On " -variable ::ntext::classicMouseSelect -value 1] -side right pack [radiobutton .rhf.h.off -bg $col -text "Off" -variable ::ntext::classicMouseSelect -value 0] -side right pack [label .rhf.h.l -bg $col -text "classicMouseSelect: "] -side right pack [frame .rhf.g -bg $col] -anchor ne pack [radiobutton .rhf.g.on -bg $col -text "On " -variable ::ntext::classicAnchor -value 1] -side right pack [radiobutton .rhf.g.off -bg $col -text "Off" -variable ::ntext::classicAnchor -value 0] -side right pack [label .rhf.g.l -bg $col -text "classicAnchor: "] -side right pack [frame .rhf.k -bg $col] -anchor ne pack [radiobutton .rhf.k.on -bg $col -text "On " -variable ::ntext::classicExtras -value 1] -side right pack [radiobutton .rhf.k.off -bg $col -text "Off" -variable ::ntext::classicExtras -value 0] -side right pack [label .rhf.k.l -bg $col -text "classicExtras: "] -side right pack [frame .rhf.j -bg $col] -anchor ne set wordBreakChoice new pack [radiobutton .rhf.j.wind -bg $col -text "On (Windows)" -variable wordBreakChoice -value "windows" -command {setPattern}] -side right pack [radiobutton .rhf.j.unix -bg $col -text "On (Unix)" -variable wordBreakChoice -value "unix" -command {setPattern}] -side right pack [radiobutton .rhf.j.off -bg $col -text "Off" -variable wordBreakChoice -value "new" -command {setPattern}] -side right pack [label .rhf.j.l -bg $col -text "classicWordBreak: "] -side right pack [frame .rhf.m -bg $col] -anchor ne pack [radiobutton .rhf.m.on -bg $col -text "On " -variable ::ntext::classicSelection -value 1] -side right pack [radiobutton .rhf.m.off -bg $col -text "Off" -variable ::ntext::classicSelection -value 0] -side right pack [label .rhf.m.l -bg $col -text "classicSelection: "] -side right proc setPattern {} { global wordBreakChoice set platform $::tcl_platform(platform) if {$wordBreakChoice eq "unix"} { set ::tcl_platform(platform) unix |
︙ | ︙ |
Changes to examples/ntext/ntextDemoIndent.tcl.
|
| | > > | > > | > > | | | > > > > | > > | > > > | | | > > > > | | | | | | > | | | | > | | > > | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 | #!/bin/sh # the next line restarts using tclsh \ exec tclsh "$0" "$@" package require Tk # Copyright (c) 2005-2017 Keith Nash. # # See the file "license.terms" for information on usage and redistribution # of this file, and for a DISCLAIMER OF ALL WARRANTIES. ### This demo explores ntext indentation ### For a short example, see ntextExample.tcl ### To explore the ntext options, try ntextDemoBindings.tcl ### To explore vertical scrolling on the Mac, try ntextDemoMacScrolling.tcl ### - Points to note when using ntext's indent facilities are commented and ### numbered (1) to (6). ### - If the text in your widget is manipulated only by the keyboard and mouse, ### then (1), (2) and (3) are all you need to do. ### - If the text or its layout are manipulated by the script, then you also ### need to call the function ::ntext::wrapIndent - see comments (4) to (6), ### and the man page for ntextIndent. # This string defines the text that will be displayed in each widget: set message { This demo shows ntext's indentation facilities. These are switched off by default, but in this demo they have been switched on. To try the demo - place the cursor at the start of a paragraph and change the amount of initial space. The paragraph is a logical line of text; its first display line may have leading whitespace, and ntext indents any subsequent (wrapped) display lines to match the first. This paragraph is indented by a tab. Again, the display lines are all indented to match the first. Try any text-widget operation, and test whether ntext's handling of display line indentation is satisfactory. Ntext is part of Tklib - please report any bugs to: http://core.tcl.tk/tklib/reportlist } # End of string for widget text. package require ntext 1.0 ### (1) Indentation is disabled by default. Set this variable to 0 to enable it: set ::ntext::classicWrap 0 # Activate the traditional "extra" bindings so these can be tested too: set ::ntext::classicExtras 1 set col #e0dfde . configure -bg $col pack [frame .rhf -bg $col] -side right -anchor nw pack [text .rhf.new ] -padx 2 ### (2) Set the widget's binding tags to use 'Ntext' instead of the default 'Text': bindtags .rhf.new {.rhf.new Ntext . all} ### (3) Set the widget to '-wrap word' mode: .rhf.new configure -wrap word -undo 1 .rhf.new configure -width 42 -height 26 -font {{Courier} -15} -bg white .rhf.new insert end " I use the Ntext bindings.\n\n$message" .rhf.new edit separator ### (4) The script (not the keyboard or mouse) has inserted text. Because the ### widget has not yet been drawn, ::ntext::wrapIndent will be called by the ### <Configure> binding, so it is not really necessary to call it here. It ### is necessary in most other cases when the 'insert' command is called by ### the script. ::ntext::wrapIndent .rhf.new pack [frame .lhf -bg $col] -side left -anchor ne pack [text .lhf.classic ] -padx 2 .lhf.classic configure -width 42 -height 26 -wrap word -undo 1 -font {{Courier} -15} -bg #FFFFCC .lhf.classic insert end " I use the (default) Text bindings.\n\n$message" .lhf.classic edit separator pack [label .lhf.m -bg $col -text "(The radiobuttons and tab settings do not\napply to the left-hand text widget)"] pack [frame .rhf.h -bg $col] -fill x ### (5) When indentation is switched on or off, call ::ntext::wrapIndent to ### calculate or clear indentation for the entire widget: pack [radiobutton .rhf.h.off -bg $col -text "Indent Off" -variable ::ntext::classicWrap -value 1 -command {::ntext::wrapIndent .rhf.new}] -side right pack [radiobutton .rhf.h.on -bg $col -text "Indent On" -variable ::ntext::classicWrap -value 0 -command {::ntext::wrapIndent .rhf.new}] -side right pack [label .rhf.h.l -bg $col -text "Switch indentation on/off: "] -side right pack [frame .rhf.g -bg $col] -anchor ne pack [label .rhf.g.l -bg $col -text " "] -side right pack [entry .rhf.g.e -width 3] -side right -padx 5 pack [button .rhf.g.b -bg $col -highlightbackground $col -text "Click to set tab spacing to value in box" -command changeTabs] -side right proc changeTabs {} { set nTabs [.rhf.g.e get] if {[string is integer -strict $nTabs] && $nTabs > 0} { set font [lindex [.rhf.new configure -font] 4] .rhf.new configure -tabs "[expr {$nTabs * [font measure $font 0]}] left" ### (6) Changing the tabs may change the indentation of the first ### display line of a logical line; if so, the indentation of the ### other display lines must be recalculated: ::ntext::wrapIndent .rhf.new } } |
Added examples/ntext/ntextDemoMacScrolling.tcl.
> > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 | #!/bin/sh # the next line restarts using tclsh \ exec tclsh "$0" "$@" package require Tk # Copyright (c) 2005-2017 Keith Nash. # # See the file "license.terms" for information on usage and redistribution # of this file, and for a DISCLAIMER OF ALL WARRANTIES. ### This demo explores vertical scrolling on the Mac ### For a short example, see ntextExample.tcl ### To explore ntext indentation, try ntextDemoIndent.tcl ### To explore the ntext options, try ntextDemoBindings.tcl # This string defines the text that will be displayed in each widget: set message {Ntext tries to offer a user experience that is as close as possible to the native "look and feel" of each platform. This example demonstrates the Mac bindings for keyboard navigation, and in particular the use of the keyboard for vertical scrolling. The description below will not agree with the behavior of the application unless you are running it on a Mac. If you are using a Mac, one of the sets of radiobuttons at the bottom of the window will not be disabled (this set of buttons is not present on non-Mac platforms). These radiobuttons allow you to set the value of ::ntext::classicParagraphs, which controls the response to the keyboard events described in (5) below. The key names are those used in Tk bindings (see the Tk manual page for the bind command). The "modifiers" Shift, Control, Option, or Command are applied to an event if the corresponding "modifier key" is held down while an ordinary key is pressed. The keys that generate each modifier are: Shift - left or right shift key Control - left or right "ctrl" key Option - left or right "alt ⌥" key Command - left or right "⌘" key The ordinary (non-modifier) keys relevant here are Up, Down, Prior, Next, Home, and End. On a full Apple keyboard, these navigation keys are in the block that lies between the main part of the keyboard, and the numeric keypad. The layout of this part of the keyboard is: F14 F15 F16 fn ↖ ⇞ ⌦ ↘ ⇟ ↑ ← ↓ → The "fn" key may instead be labeled "help". The "⌦" key is also labeled "delete". The same layout, but now using the Tk names for the keys, is: F14 F15 F16 Help Home Prior Delete End Next Up Left Down Right On reduced Apple keyboards, the nine keys F14 to Next are absent; the four cursor keys Up, Left, Down, Right are squeezed into the lower right of the keyboard. There are five sets of bindings that use the keyboard for vertical scrolling. (1) Prior and Next keys <Prior> and <Next> scroll the text widget vertically without moving the insert mark (the "cursor"). <Control-Prior> and <Control-Next> scroll the text widget vertically, AND move the insert mark. <Shift-Prior> and <Shift-Next> scroll the text widget vertically, AND move the insert mark, AND extend the selection. <Option-Prior> and <Option-Next> scroll the text widget vertically, AND move the insert mark - the same as <Control-Prior> and <Control-Next> respectively. <Command-Prior> and <Command-Next> do nothing. The Shift modifier has no effect in any cases except <Shift-Prior> and <Shift-Next>. (2) Home and End keys <Home> and <End> scroll to the top and bottom of the text widget respectively, without moving the insert mark. <Shift-Home> and <Shift-End> scroll to the top and bottom of the text widget respectively, AND move the insert mark, AND extend the selection. <Control-Home> and <Control-End> do nothing. <Command-Home> and <Command-End> do nothing. <Option-Home> and <Option-End> do nothing. (3) Up and Down keys, with Command modifier <Command-Up> and <Command-Down> scroll to the top and bottom of the text widget respectively, AND move the insert mark. <Command-Shift-Up> and <Command-Shift-Down> scroll to the top and bottom of the text widget respectively, AND move the insert mark, AND extend the selection. On other platforms these operations are bound to the keys <Control-Home>, <Control-End>, <Control-Shift-Home>, <Control-Shift-End> respectively. (4) Up and Down keys, with Control modifier On recent versions of OS X, these keystrokes are intercepted by the windowing system. To avoid confusion, Ntext defines these keystrokes to have no effect on any version of OS X. (5) Up and Down keys, with Option modifier if {::ntext::classicParagraphs == 0} (the default value) <Option-Up> goes to the previous SLL. <Shift-Option-Up> goes to the previous SLL, AND also extends the selection. <Option-Down> goes to the next ELL. <Shift-Option-Down> goes to the next ELL, AND also extends the selection. where SLL = start of a logical line ELL = end of a logical line and a logical line is a single line of text that may have been wrapped around (when the text widget has option -wrap word or -wrap char) into multiple "display lines" This behavior is the same as for the Mac application TextEdit. if {::ntext::classicParagraphs == 1} The behavior differs from that of other Mac applications. <Option-Up>, <Option-Down> scroll the text widget up and down, AND move the insert mark to the start of the previous/next "paragraph". <Shift-Option-Up>, <Shift-Option-Down> scroll the text widget up and down, AND move the insert mark to the start of the previous/next "paragraph", AND extend the selection. The start of a paragraph is the first non-blank character after a blank line. On non-Mac platforms, these actions are bound in Ntext and Text to the events <Control-Up>, <Control-Down>, <Shift-Control-Up>, <Shift-Control-Down>. The Control- bindings are also defined in the Text binding tag on the Mac, although on recent versions of OS X these keystrokes are intercepted by the windowing system). } # End of string for widget text. package require ntext 1.0 # Whether Shift-Button-1 ignores changes made by the kbd to the insert mark: set ::ntext::classicMouseSelect 0 # Whether Shift-Button-1 has a variable or fixed anchor: set ::ntext::classicAnchor 0 # Whether the traditional "extra" bindings are activated (default is 0): set ::ntext::classicExtras 0 # Whether to use new or classic word boundary detection: set ::ntext::classicWordBreak 0 # Set to 0 to align wrapped display lines with the first display line of the logical line: set ::ntext::classicWrap 0 # Set to 0 to follow Mac Aqua conventions on placement of the insert mark # when a selection is cancelled by keyboard navigation: # Has effect on all platforms. Default value is 0 on Aqua, 1 on other platforms. set ::ntext::classicSelection 0 # Set to 0 to follow Mac Aqua conventions on vertical scrolling with the # Up/Down cursor keys and Option ("Alt") modifier keys. # Has effect only on Aqua. set ::ntext::classicParagraphs 0 set col #e0dfde . configure -bg $col pack [frame .rhf -bg $col] -side right -anchor nw pack [frame .rhf.f -bg $col] pack [scrollbar .rhf.f.scroll -bg $col] -side right -anchor nw -expand 1 -fill y pack [text .rhf.f.new ] -padx 2 -side right -anchor nw bindtags .rhf.f.new {.rhf.f.new Ntext . all} .rhf.f.new configure -wrap word -undo 1 -yscrollcommand {.rhf.f.scroll set} .rhf.f.new configure -width 61 -height 29 -font {{Courier} -15} -bg white .rhf.f.new insert end " I use the Ntext bindings.\n\n$message" .rhf.f.new edit separator .rhf.f.scroll configure -command {.rhf.f.new yview} pack [frame .lhf -bg $col] -side left -anchor ne pack [frame .lhf.f -bg $col] pack [scrollbar .lhf.f.scroll -bg $col] -side left -anchor nw -expand 1 -fill y pack [text .lhf.f.classic ] -padx 2 -side left -anchor nw .lhf.f.classic configure -width 61 -height 29 -wrap word -undo 1 -font {{Courier} -15} -bg #FFFFCC -yscrollcommand {.lhf.f.scroll set} .lhf.f.classic insert end " I use the (default) Text bindings.\n\n$message" .lhf.f.classic edit separator .lhf.f.scroll configure -command {.lhf.f.classic yview} pack [label .lhf.m -bg $col -text "(The radiobutton controls do not\napply to the left-hand text widget)"] pack [frame .rhf.h -bg $col] -fill x pack [radiobutton .rhf.h.on -bg $col -text "On " -variable ::ntext::classicMouseSelect -value 1] -side right pack [radiobutton .rhf.h.off -bg $col -text "Off" -variable ::ntext::classicMouseSelect -value 0] -side right pack [label .rhf.h.l -bg $col -text "classicMouseSelect: "] -side right pack [frame .rhf.g -bg $col] -anchor ne pack [radiobutton .rhf.g.on -bg $col -text "On " -variable ::ntext::classicAnchor -value 1] -side right pack [radiobutton .rhf.g.off -bg $col -text "Off" -variable ::ntext::classicAnchor -value 0] -side right pack [label .rhf.g.l -bg $col -text "classicAnchor: "] -side right pack [frame .rhf.k -bg $col] -anchor ne pack [radiobutton .rhf.k.on -bg $col -text "On " -variable ::ntext::classicExtras -value 1] -side right pack [radiobutton .rhf.k.off -bg $col -text "Off" -variable ::ntext::classicExtras -value 0] -side right pack [label .rhf.k.l -bg $col -text "classicExtras: "] -side right pack [frame .rhf.j -bg $col] -anchor ne set wordBreakChoice new pack [radiobutton .rhf.j.wind -bg $col -text "On (Windows)" -variable wordBreakChoice -value "windows" -command {setPattern}] -side right pack [radiobutton .rhf.j.unix -bg $col -text "On (Unix)" -variable wordBreakChoice -value "unix" -command {setPattern}] -side right pack [radiobutton .rhf.j.off -bg $col -text "Off" -variable wordBreakChoice -value "new" -command {setPattern}] -side right pack [label .rhf.j.l -bg $col -text "classicWordBreak: "] -side right pack [frame .rhf.m -bg $col] -anchor ne pack [radiobutton .rhf.m.on -bg $col -text "On " -variable ::ntext::classicSelection -value 1] -side right pack [radiobutton .rhf.m.off -bg $col -text "Off" -variable ::ntext::classicSelection -value 0] -side right pack [label .rhf.m.l -bg $col -text "classicSelection: "] -side right if {[tk windowingsystem] eq "aqua"} { pack [frame .rhf.n -bg $col -bg $col] -anchor ne -pady {0 10} pack [radiobutton .rhf.n.on -bg $col -text "On " -variable ::ntext::classicParagraphs -value 1] -side right pack [radiobutton .rhf.n.off -bg $col -text "Off" -variable ::ntext::classicParagraphs -value 0] -side right pack [label .rhf.n.l -bg $col -text "classicParagraphs: "] -side right } proc setPattern {} { global wordBreakChoice set platform $::tcl_platform(platform) if {$wordBreakChoice eq "unix"} { set ::tcl_platform(platform) unix set ::ntext::classicWordBreak 1 } elseif {$wordBreakChoice eq "windows"} { set ::tcl_platform(platform) windows set ::ntext::classicWordBreak 1 } else { set ::ntext::classicWordBreak 0 } ::ntext::initializeMatchPatterns set ::tcl_platform(platform) $platform } # Disable all radiobuttons except .rhf.n.on .rhf.n.off which are relevant to this demo: # And all labels except .lhf.m, .rhf.n.l foreach rb { .rhf.h.on .rhf.h.off .rhf.g.on .rhf.g.off .rhf.k.on .rhf.k.off .rhf.j.wind .rhf.j.unix .rhf.j.off .rhf.m.on .rhf.m.off .rhf.h.l .rhf.g.l .rhf.k.l .rhf.j.l .rhf.m.l } { $rb configure -state disabled } foreach term { < > Prior Next Up Down Left Right Home End Help Delete F14 F15 F16 Control Command Option Shift Control- Command- Option- Shift- } { set first 1 set lenny [string length $term] set nextPlace 1.0 while {1} { set place [.rhf.f.new search -- $term $nextPlace end-1c] if {$place eq {}} { break } set nextPlace ${place}+${lenny}c if {$first && $term in {F14 F15 F16}} { # The first use of these terms is not as a binding name. } else { .lhf.f.classic tag add red $place $nextPlace .rhf.f.new tag add red $place $nextPlace } set first 0 } } .lhf.f.classic tag configure red -foreground #A00000 -font {{Courier} -15 bold} .rhf.f.new tag configure red -foreground #A00000 -font {{Courier} -15 bold} |
Changes to examples/ntext/ntextExample.tcl.
|
| | > | | > > > > > < > | < > > < | | | | < > | > > | > > > > > > | > > > > | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 | #!/bin/sh # the next line restarts using tclsh \ exec tclsh "$0" "$@" package require Tk # Copyright (c) 2005-2017 Keith Nash. # # See the file "license.terms" for information on usage and redistribution # of this file, and for a DISCLAIMER OF ALL WARRANTIES. ### This is a short, simple example. It shows the difference ### between a default text widget and one that uses ntext. ### To explore the ntext options, try ntextDemoBindings.tcl ### To explore ntext indentation, try ntextDemoIndent.tcl ### To explore vertical scrolling on the Mac, try ntextDemoMacScrolling.tcl . configure -bg #d0cfce package require ntext 1.0 # This string defines the text that will be displayed in each widget: set message {The source code for this example shows how simple it is to deploy ntext. It is necessary to "package require" the ntext package, and then call the "bindtags" command for any text widget in which you wish to use the Ntext bindings...} # ...and if you do not like the ntext default bindings, you can override some # of them by setting these variables (ntextDemoBindings.tcl has a live demo): # Whether Shift-Button-1 ignores changes made by the kbd to the insert mark: set ::ntext::classicMouseSelect 0 # Whether Shift-Button-1 has a variable or fixed anchor: set ::ntext::classicAnchor 0 # Whether to activate certain traditional "extra" bindings variable classicExtras 1 # Whether to use new or classic word boundary detection: set ::ntext::classicWordBreak 0 # Set to 0 to follow Mac Aqua conventions on placement of the insert mark # when a selection is cancelled by keyboard navigation: set ::ntext::classicSelection 1 # Create two identical text widgets: pack [text .left ] -side left -padx 2 -pady 2 pack [text .right] -side left -padx 2 -pady 2 .left configure -width 28 -height 14 -wrap word -undo 1 -font {{Courier} -15} .right configure -width 28 -height 14 -wrap word -undo 1 -font {{Courier} -15} # Give them different background colors: .left configure -bg #FFFFCC .right configure -bg white # Write slightly different text to each one: .left insert end " I use the (default) Text bindings.\n\n$message" .right insert end " I use the Ntext bindings.\n\n\n$message" # Finally, enable Ntext for the right-hand widget: bindtags .right {.right Ntext . all} |
Changes to modules/ntext/ChangeLog.
|
| | | > > > > > > > > > > > > > > > | < | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 | 2017-03-31 Keith Nash <kjnash@users.sourceforge.net> * Update to correspond to current tk8.x/text.tcl -- core-8-6-branch 2015-10-09 artifact [e9c33ef1] check-in [553899e9] core-8-5-branch 2015-10-04 artifact [6af61544] check-in [55133bde] trunk 2016-09-27 artifact [530d3c1b] check-in [6b21cc27] * Don't call private commands from tk8.x/text.tcl (for compatibility with all versions of Tk 8.5.x, 8.6.x). * Adapt bindings to have Mac-like behaviour on the Mac. * Show correct cursor for insert/overwrite when there are multiple widgets. * Fix "Smart End" to handle trailing whitespace. * Different behaviour for "Smart Home" in corner case with wrapped leading whitespace. * Bugfixes for separator boundaries in Undo/Redo. * Bugfixes for extending the selection. * Add a new example for Mac scrolling. * Update docs and examples. * Increase version to 1.0b1 2009-01-21 Andreas Kupries <[email protected]> * * Released and tagged Tklib 0.5 ======================== * |
︙ | ︙ |
Changes to modules/ntext/NtextBindings.html.
︙ | ︙ | |||
47 48 49 50 51 52 53 54 55 56 57 58 59 60 | <tr> <td valign="top"> </td> <td valign="top" width="100%"><div> <div class="text-body"> <h4>Bindings in the Ntext Binding Tag</h4> <p><font class="red">Red</font> indicates differences from Text; <font class="grey">grey</font> indicates things removed from Text </p> <p>The <a href="TkTextBindings.html">page on the Text bindings</A> is more reliable; this page has the same information about "Text", but might need a little more grey and red ink to properly describe the Ntext bindings. Also, the <a href="TkTextBindings.html">page on the Text bindings</A> has Tables 2,3,5,6, which are the same for both classes. </p> | > > > | 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 | <tr> <td valign="top"> </td> <td valign="top" width="100%"><div> <div class="text-body"> <h4>Bindings in the Ntext Binding Tag</h4> <p>This document is out of date: it applies to ntext 0.81, and early versions of Tk 8.5. </p> <p><font class="red">Red</font> indicates differences from Text; <font class="grey">grey</font> indicates things removed from Text </p> <p>The <a href="TkTextBindings.html">page on the Text bindings</A> is more reliable; this page has the same information about "Text", but might need a little more grey and red ink to properly describe the Ntext bindings. Also, the <a href="TkTextBindings.html">page on the Text bindings</A> has Tables 2,3,5,6, which are the same for both classes. </p> |
︙ | ︙ |
Changes to modules/ntext/TkTextBindings.html.
︙ | ︙ | |||
47 48 49 50 51 52 53 54 55 56 57 58 59 60 | <tr> <td valign="top" width="50"> </td> <td valign="top" width="100%"><div> <div> <h4>Bindings in the Text Binding Tag</h4> <p>The "Text" binding tag has 92 bindings in X11, 103 in OS X, 90 in Windows (Table 1). In addition, several "real events" are mapped to "virtual events" that are bound in the "Text" binding tag (Table 2). </p> | > > > | 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 | <tr> <td valign="top" width="50"> </td> <td valign="top" width="100%"><div> <div> <h4>Bindings in the Text Binding Tag</h4> <p>This document is out of date: it applies to early versions of Tk 8.5. </p> <p>The "Text" binding tag has 92 bindings in X11, 103 in OS X, 90 in Windows (Table 1). In addition, several "real events" are mapped to "virtual events" that are bound in the "Text" binding tag (Table 2). </p> |
︙ | ︙ | |||
1697 1698 1699 1700 1701 1702 1703 | <td>Keyboard</td> <td><<Cut>> </td> <td>X-- </td> <td> </td> </tr> </tbody></table> | < | | < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < | 1700 1701 1702 1703 1704 1705 1706 1707 1708 1709 1710 1711 1712 1713 1714 1715 1716 1717 1718 | <td>Keyboard</td> <td><<Cut>> </td> <td>X-- </td> <td> </td> </tr> </tbody></table> <p><strong>Table 3: Keyboard Modifiers</strong> </p> <p>This information has been moved to the Tclers Wiki (<a href="http://wiki.tcl.tk/28331">Modifier Keys</a>). </p> <p><strong>Table 4: Actions that modify the text contents of the widget</strong> </p> <p><em>File: lib/tk8.5/text.tcl</em> - data extracted from Table 1. </p> |
︙ | ︙ |
Changes to modules/ntext/ntext.man.
1 | [comment {-*- tcl -*- ntext manpage}] | | < < < < < < < < < < < | | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 | [comment {-*- tcl -*- ntext manpage}] [manpage_begin ntext n 1.0] [moddesc {Alternative Bindings for the Text Widget}] [titledesc {Alternative Bindings for the Text Widget}] [require Tcl 8.5] [require Tk 8.5] [require ntext [opt 1.0]] [description] The purpose of the [package ntext] package is to make the text widget behave more like other text-editing applications. It makes the text widget more useful for implementing a text editor, and makes it behave in a way that will be more familiar to most users. [para] The package provides a binding tag named [emph Ntext] for use by text widgets in place of the default [emph Text] binding tag. [para] |
︙ | ︙ | |||
42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 | [list_end] The remainder of this page describes the basic use and configuration of all three aspects of [emph Ntext]. For more detailed information on the different facilities of [emph Ntext], see the pages [term ntextBindings], [term ntextIndent], and [term ntextWordBreak]. [para] See Section [sectref EXAMPLE] for how to apply the [emph Ntext] binding tag in place of the [emph Text] binding tag. [section {CONFIGURATION OPTIONS}] [emph Ntext] provides alternatives to a number of behaviours of the classic [emph Text] binding tag. Where there is an option, the [emph Ntext] behaviour (except for display-line indentation) is switched on by default. [para] The behaviour of [emph Ntext] may be configured application-wide by setting the values of a number of namespace variables: [para] [var ::ntext::classicAnchor] [list_begin itemized] [item] [const 0] - (default value) selects [emph Ntext] behaviour, i.e. the anchor point is fixed [item] [const 1] - selects classic [emph Text] behaviour, i.e. the anchor point is variable [list_end] [para] [var ::ntext::classicExtras] [list_begin itemized] [item] [const 0] - (default value) selects [emph Ntext] behaviour, i.e. several traditional [emph Text] bindings are de-activated [item] [const 1] - selects classic [emph Text] behaviour, i.e. all [emph Text] bindings are activated [list_end] [para] [var ::ntext::classicMouseSelect] [list_begin itemized] [item] [const 0] - (default value) selects [emph Ntext] behaviour, i.e. the anchor point for mouse selection operations is moved by keyboard navigation [item] [const 1] - selects classic [emph Text] behaviour [list_end] [para] [var ::ntext::classicWordBreak] [list_begin itemized] [item] [const 0] - (default value) selects [emph Ntext] behaviour, i.e. platform-independent, two classes of word characters and one class of non-word characters. [item] [const 1] - selects classic [emph Text] behaviour, i.e. platform-dependent, one class of word characters and one class of non-word characters [item] After changing this value, the matching patterns should be recalculated. See [term ntextWordBreak] for details and advanced configuration options. [list_end] [para] [var ::ntext::classicWrap] [list_begin itemized] [item] [const 0] - selects [emph Ntext] behaviour, i.e. display lines of text widgets in [arg -wrap] [arg word] mode are indented to match the initial whitespace of the first display line of a logical line. If the widget already holds text when this value is set, a function call may be necessary. See [term ntextIndent] for detailed instructions on the use of [emph Ntext] 's indentation. [item] [const 1] - (default value) selects classic [emph Text] behaviour, i.e. no indentation [list_end] [para] [var ::ntext::overwrite] [list_begin itemized] [item] [const 0] - (initial value) text typed at the keyboard is inserted into the widget [item] [const 1] - text typed at the keyboard overwrites text already in the widget [item] | > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > | > > > > > > > > > > > > > > > > | | > | 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 | [list_end] The remainder of this page describes the basic use and configuration of all three aspects of [emph Ntext]. For more detailed information on the different facilities of [emph Ntext], see the pages [term ntextBindings], [term ntextIndent], and [term ntextWordBreak]. [para] See Section [sectref EXAMPLE] for how to apply the [emph Ntext] binding tag in place of the [emph Text] binding tag. [section COMMANDS] [list_begin definitions] [call [cmd ::ntext::new_textCopy] [arg pathName]] Replacement for ::tk_textCopy. [call [cmd ::ntext::new_textCut] [arg pathName]] Replacement for ::tk_textCut that also maintains [emph Ntext] indentation (see [term ntextIndent]). [call [cmd ::ntext::new_textPaste] [arg pathName]] Replacement for ::tk_textPaste that also maintains [emph Ntext] indentation (see [term ntextIndent]). [list_end] [section {CONFIGURATION OPTIONS}] [emph Ntext] provides alternatives to a number of behaviours of the classic [emph Text] binding tag. Where there is an option, the [emph Ntext] behaviour (except for display-line indentation) is switched on by default. [para] The behaviour of [emph Ntext] may be configured application-wide by setting the values of a number of namespace variables: [para] [var ::ntext::classicAnchor] [list_begin itemized] [item] [const 0] - (default value) selects [emph Ntext] behaviour, i.e. the anchor point is fixed [item] [const 1] - selects classic [emph Text] behaviour, i.e. the anchor point is variable [item] For more information see [term ntextBindings] [list_end] [para] [var ::ntext::classicExtras] [list_begin itemized] [item] [const 0] - (default value) selects [emph Ntext] behaviour, i.e. several traditional [emph Text] bindings are de-activated [item] [const 1] - selects classic [emph Text] behaviour, i.e. all [emph Text] bindings are activated [item] For more information see [term ntextBindings] [list_end] [para] [var ::ntext::classicMouseSelect] [list_begin itemized] [item] [const 0] - (default value) selects [emph Ntext] behaviour, i.e. the anchor point for mouse selection operations is moved by keyboard navigation [item] [const 1] - selects classic [emph Text] behaviour [item] For more information see [term ntextBindings] [list_end] [para] [var ::ntext::classicSelection] [list_begin itemized] [item] [const 0] - (default value on macOS Aqua) selects Mac-like behaviour, i.e. when a navigation keystroke cancels a selection, the insert mark first moves to the end of the selection determined by the navigation direction of the keystroke, and then the keystroke is applied. [item] [const 1] - (default value except on macOS Aqua) selects PC-like behaviour (the same as classic [emph Text]), i.e. when a navigation keystroke cancels a selection, the insert mark is not moved before the keystroke is applied. [item] For more information see [term ntextBindings] [list_end] [para] [var ::ntext::classicWordBreak] [list_begin itemized] [item] [const 0] - (default value) selects [emph Ntext] behaviour, i.e. platform-independent, two classes of word characters and one class of non-word characters. [item] [const 1] - selects classic [emph Text] behaviour, i.e. platform-dependent, one class of word characters and one class of non-word characters [item] After changing this value, the matching patterns should be recalculated. See [term ntextWordBreak] for details and advanced configuration options. [list_end] [para] [var ::ntext::classicWrap] [list_begin itemized] [item] [const 0] - selects [emph Ntext] behaviour, i.e. display lines of text widgets in [arg -wrap] [arg word] mode are indented to match the initial whitespace of the first display line of a logical line. If the widget already holds text when this value is set, a function call may be necessary. See [term ntextIndent] for detailed instructions on the use of [emph Ntext] 's indentation. [item] [const 1] - (default value) selects classic [emph Text] behaviour, i.e. no indentation [item] For more information see [term ntextIndent] [list_end] [para] [var ::ntext::overwrite] [list_begin itemized] [item] [const 0] - (initial value) text typed at the keyboard is inserted into the widget [item] [const 1] - text typed at the keyboard overwrites text already in the widget [item] The value is toggled by the [emph Insert] key (except on macOS Aqua where there is no such key). [item] For more information see [term ntextBindings] [list_end] [para] [var ::ntext::classicParagraphs] [list_begin itemized] [item] [const 0] - (default value) on macOS Aqua, certain keyboard bindings are made to behave in the same way as the Mac application TextEdit. The bindings involve vertical scrolling of the screen and are <?Shift-?Option-(Up|Down)>. [item] [const 1] - on macOS Aqua, certain keyboard bindings are made to behave in the same way as classic [emph Text], ignoring the conventions of Aqua. The bindings involve vertical scrolling of the screen and are <?Shift-?Option-(Up|Down)>. [item] For more information see [term ntextBindings] [list_end] [section BUGS] This version of [package ntext] is intended to be compatible with all releases of [package Tk] 8.5 and 8.6, and with the branches [emph core-8-5-branch], [emph core-8-6-branch], and [emph trunk] in the source code repository for [package Tk]. Any incompatibility with any of these versions, for any [package Tk] windowing system, should be reported as a bug. Please report such in the category [emph ntext] of the [uri http://core.tcl.tk/tklib/reportlist {Tklib Trackers}]. [section EXAMPLE] To create a text widget .t and use the [emph Ntext] bindings: [example { package require ntext text .t bindtags .t {.t Ntext . all} }] See bindtags for more information. [see_also ntextWordBreak ntextIndent ntextBindings] [see_also text bindtags regexp re_syntax] [keywords text bindtags regexp re_syntax] [manpage_end] |
Changes to modules/ntext/ntext.sed.
|
| | > > | > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > | > > > > > > > > > > > > > > > > > < | < > > > > > > > > < | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 | # Apply this sed script to text.tcl, as the first step in comparing with ntext.tcl # Rename binding tag "Text" s/bind[[:space:]]\+Text[[:space:]]/bind Ntext /g # Rename some virtual events used in tk8.*/text.tcl (defined in tk8.*/tk.tcl) s/<<LineEnd>>/<<NtextLineEnd>>/g s/<<LineStart>>/<<NtextLineStart>>/g s/<<NextChar>>/<<NtextNextChar>>/g s/<<NextLine>>/<<NtextNextLine>>/g s/<<NextPara>>/<<NtextNextPara>>/g s/<<NextWord>>/<<NtextNextWord>>/g s/<<PrevChar>>/<<NtextPrevChar>>/g s/<<PrevLine>>/<<NtextPrevLine>>/g s/<<PrevPara>>/<<NtextPrevPara>>/g s/<<PrevWord>>/<<NtextPrevWord>>/g s/<<SelectAll>>/<<NtextSelectAll>>/g s/<<SelectLineEnd>>/<<NtextSelectLineEnd>>/g s/<<SelectLineStart>>/<<NtextSelectLineStart>>/g s/<<SelectNextChar>>/<<NtextSelectNextChar>>/g s/<<SelectNextLine>>/<<NtextSelectNextLine>>/g s/<<SelectNextPara>>/<<NtextSelectNextPara>>/g s/<<SelectNextWord>>/<<NtextSelectNextWord>>/g s/<<SelectNone>>/<<NtextSelectNone>>/g s/<<SelectPrevChar>>/<<NtextSelectPrevChar>>/g s/<<SelectPrevLine>>/<<NtextSelectPrevLine>>/g s/<<SelectPrevPara>>/<<NtextSelectPrevPara>>/g s/<<SelectPrevWord>>/<<NtextSelectPrevWord>>/g # Do not rename: # <<Clear>> # <<Copy>> # <<Cut>> # <<Paste>> # <<PasteSelection>> # <<Redo>> # <<Undo>> # Procs ::tk::* defined in tk8.*/text.tcl s/tk::TextAnchor/ntext::TextAnchor/g s/tk::TextAutoScan/ntext::TextAutoScan/g s/tk::TextButton1/ntext::TextButton1/g s/tk::TextClosestGap/ntext::TextClosestGap/g s/tk::TextCursorInSelection/ntext::TextCursorInSelection/g s/tk::TextInsert/ntext::TextInsert/g s/tk::TextKeyExtend/ntext::TextKeyExtend/g s/tk::TextKeySelect/ntext::TextKeySelect/g s/tk::TextNextPara/ntext::TextNextPara/g s/tk::TextNextPos/ntext::TextNextPos/g s/tk::TextNextWord/ntext::TextNextWord/g s/tk::TextPasteSelection/ntext::TextPasteSelection/g s/tk::TextPrevPara/ntext::TextPrevPara/g s/tk::TextPrevPos/ntext::TextPrevPos/g s/tk::TextResetAnchor/ntext::TextResetAnchor/g s/tk::TextScanDrag/ntext::TextScanDrag/g s/tk::TextScanMark/ntext::TextScanMark/g s/tk::TextScrollPages/ntext::TextScrollPages/g s/tk::TextSelectTo/ntext::TextSelectTo/g s/tk::TextSetCursor/ntext::TextSetCursor/g s/tk::TextTranspose/ntext::TextTranspose/g s/tk::TextUpDownLine/ntext::TextUpDownLine/g # Procs ::* defined in tk8.*/text.tcl s/tk_textCopy/ntext::new_textCopy/g s/tk_textCut/ntext::new_textCut/g s/tk_textPaste/ntext::new_textPaste/g # Procs ::* defined in tcl8.*/word.tcl s/tcl_wordBreakAfter/ntext::new_wordBreakAfter/g s/tcl_wordBreakBefore/ntext::new_wordBreakBefore/g s/tcl_endOfWord/ntext::new_endOfWord/g s/tcl_startOfNextWord/ntext::new_startOfNextWord/g s/tcl_startOfPreviousWord/ntext::new_startOfPreviousWord/g |
Changes to modules/ntext/ntext.tcl.
1 2 3 4 5 6 | # ntext.tcl -- # derived from text.tcl # # This file defines the Ntext bindings for Tk text widgets and provides # procedures that help in implementing the bindings. # | < < | | > > > > > > > > > | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 | # ntext.tcl -- # derived from text.tcl # # This file defines the Ntext bindings for Tk text widgets and provides # procedures that help in implementing the bindings. # # Copyright (c) 1992-1994 The Regents of the University of California. # Copyright (c) 1994-1997 Sun Microsystems, Inc. # Copyright (c) 1998 by Scriptics Corporation. # Copyright (c) 2005-2017 additions by Keith Nash. # # See the file "license.terms" for information on usage and redistribution # of this file, and for a DISCLAIMER OF ALL WARRANTIES. # ##### START OF CODE THAT IS MODIFIED from the following versions of text.tcl: # # branch core-8-6-branch # 2015-10-09 artifact [e9c33ef1] part of check-in [553899e9] # branch core-8-5-branch # 2015-10-04 artifact [6af61544] part of check-in [55133bde] # trunk # 2016-09-27 artifact [530d3c1b] part of check-in [6b21cc27] # # Not yet adapted to revised text widget by Gregor Cramer, or to Androwish. #------------------------------------------------------------------------- # Elements of ::tk::Priv that are used in this file: # # afterId - If non-null, it means that auto-scanning is underway # and it gives the "after" id for the next auto-scan # command to be executed. |
︙ | ︙ | |||
34 35 36 37 38 39 40 41 42 43 44 45 | # we can distinguish a series of ups and downs, all # in a row, from a new up or down. # selectMode - The style of selection currently underway: # char, word, or line. # x, y - Last known mouse coordinates for scanning # and auto-scanning. #------------------------------------------------------------------------- #------------------------------------------------------------------------- # The code below creates the Ntext class bindings for text widgets. #------------------------------------------------------------------------- | > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > < < < | 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 | # we can distinguish a series of ups and downs, all # in a row, from a new up or down. # selectMode - The style of selection currently underway: # char, word, or line. # x, y - Last known mouse coordinates for scanning # and auto-scanning. #------------------------------------------------------------------------- #------------------------------------------------------------------------------- # ntext no longer uses private commands ::tk::* from tk8.x/text.tcl. Any # necessary commands are defined below in the ::ntext namespace, even if the # corresponding ::tk::* command from tk8.x/text.tcl is identical. This makes # ntext less likely to break in future if tk8.x/text.tcl is modified. # # ntext still uses the private array ::tk::Priv (shared with text.tcl etc) and # the private command ::tk::GetSelection (from tk.tcl). There is a small risk # of breakage if one of these private items is altered in Tk. #------------------------------------------------------------------------------- package require Tcl 8.5 package require Tk 8.5 # ------------------------------------------------------------------------------ # Define the set of common virtual events. # ------------------------------------------------------------------------------ # These events are the ones from tk8.6/tk.tcl that are relevant to text widget # bindings, renamed with the "Ntext" prefix, and modified as noted in comments. # # On macOS/Aqua: # - the Control key is modifier "Control" # - the Alt key is modifier "Option" # For discussion of Modifier Keys, see http://wiki.tcl.tk/28331 # ------------------------------------------------------------------------------ switch -exact -- [tk windowingsystem] { "x11" { # With the exception of points (1) to (3) below, the events <<Ntext*>> # are defined the same way as <<*>> in tk.tcl. event add <<NtextCut>> <Control-Key-x> <Key-F20> <Control-Lock-Key-X> event add <<NtextCopy>> <Control-Key-c> <Key-F16> <Control-Lock-Key-C> event add <<NtextPaste>> <Control-Key-v> <Key-F18> <Control-Lock-Key-V> # (1) Use tk.tcl events for these: # event add <<PasteSelection>> # event add <<Undo>> # event add <<Redo>> # event add <<ContextMenu>> event add <<NtextSelectAll>> <Control-Key-slash> event add <<NtextSelectNone>> <Control-Key-backslash> event add <<NtextNextChar>> <Right> event add <<NtextSelectNextChar>> <Shift-Right> event add <<NtextPrevChar>> <Left> event add <<NtextSelectPrevChar>> <Shift-Left> event add <<NtextNextWord>> <Control-Right> event add <<NtextSelectNextWord>> <Control-Shift-Right> event add <<NtextPrevWord>> <Control-Left> event add <<NtextSelectPrevWord>> <Control-Shift-Left> event add <<NtextLineStart>> <Home> event add <<NtextSelectLineStart>> <Shift-Home> event add <<NtextLineEnd>> <End> event add <<NtextSelectLineEnd>> <Shift-End> event add <<NtextPrevLine>> <Up> event add <<NtextNextLine>> <Down> event add <<NtextSelectPrevLine>> <Shift-Up> event add <<NtextSelectNextLine>> <Shift-Down> event add <<NtextPrevPara>> <Control-Up> event add <<NtextNextPara>> <Control-Down> event add <<NtextSelectPrevPara>> <Control-Shift-Up> event add <<NtextSelectNextPara>> <Control-Shift-Down> # (2) Use tk.tcl events for these: # event add <<PrevWindow>> # event add <<ToggleSelection>> # (3) Define Emacs bindings in ::ntext::EmacsBindings the same way as in # tk.tcl. } "win32" { # With the exception of points (1) to (4) below, the events <<Ntext*>> # are defined the same way as <<*>> in tk.tcl. event add <<NtextCut>> <Control-Key-x> <Shift-Key-Delete> <Control-Lock-Key-X> event add <<NtextCopy>> <Control-Key-c> <Control-Key-Insert> <Control-Lock-Key-C> event add <<NtextPaste>> <Control-Key-v> <Shift-Key-Insert> <Control-Lock-Key-V> # (1) Use tk.tcl events for these: # event add <<PasteSelection>> # event add <<Undo>> # event add <<Redo>> # event add <<ContextMenu>> # (2) Tk 8.6 also adds <Control-Key-a> <Control-Lock-Key-A> to # <<SelectAll>>, adding this usage to win32 for the first time, # and removing all the "Emacs-like bindings" from win32 in order to # avoid conflict. # event add <<NtextSelectAll>> <Control-Key-a> <Control-Lock-Key-A> event add <<NtextSelectAll>> <Control-Key-slash> event add <<NtextSelectNone>> <Control-Key-backslash> event add <<NtextNextChar>> <Right> event add <<NtextSelectNextChar>> <Shift-Right> event add <<NtextPrevChar>> <Left> event add <<NtextSelectPrevChar>> <Shift-Left> event add <<NtextNextWord>> <Control-Right> event add <<NtextSelectNextWord>> <Control-Shift-Right> event add <<NtextPrevWord>> <Control-Left> event add <<NtextSelectPrevWord>> <Control-Shift-Left> event add <<NtextLineStart>> <Home> event add <<NtextSelectLineStart>> <Shift-Home> event add <<NtextLineEnd>> <End> event add <<NtextSelectLineEnd>> <Shift-End> event add <<NtextPrevLine>> <Up> event add <<NtextNextLine>> <Down> event add <<NtextSelectPrevLine>> <Shift-Up> event add <<NtextSelectNextLine>> <Shift-Down> event add <<NtextPrevPara>> <Control-Up> event add <<NtextNextPara>> <Control-Down> event add <<NtextSelectPrevPara>> <Control-Shift-Up> event add <<NtextSelectNextPara>> <Control-Shift-Down> # (3) Use tk.tcl events for these: # event add <<ToggleSelection>> # (4) Define Emacs bindings in ::ntext::EmacsBindings the same way as in # tk.tcl, but make them optional not omitted. } "aqua" { # With the exception of points (1) to (5) below, the events <<Ntext*>> # are defined the same way as <<*>> in tk.tcl. event add <<NtextCut>> <Command-Key-x> <Key-F2> <Command-Lock-Key-X> event add <<NtextCopy>> <Command-Key-c> <Key-F3> <Command-Lock-Key-C> event add <<NtextPaste>> <Command-Key-v> <Key-F4> <Command-Lock-Key-V> # <Shift-Key-Delete>, <Control-Key-Insert>, <Shift-Key-Insert> are not # standard bindings for Cut/Copy/Paste on macOS/Aqua - even with "Help" # in place of the non-existent "Insert" key. # # Official bindings # See http://support.apple.com/kb/HT1343 # The traditional Tk <Control-Key-slash>, <Control-Key-backslash> will # no longer work on macOS/Aqua. # (1) Use the tk.tcl events for these: # event add <<PasteSelection>> # event add <<Clear>> # event add <<ContextMenu>> # event add <<Undo>> # event add <<Redo>> # (2) Allow the "Lock" modifier in the first two events (not done in tk.tcl). # (3) Define Emacs bindings in ::ntext::EmacsBindings the same way as in # tk.tcl, but make them optional not mandatory. # For aqua the optional Emacs bindings are compatible with these "a" # commands because the Emacs bindings do not use the "Command" modifier. event add <<NtextSelectAll>> <Command-Key-a> <Command-Lock-Key-A> event add <<NtextSelectNone>> <Option-Command-Key-a> <Option-Command-Lock-Key-A> event add <<NtextNextChar>> <Right> event add <<NtextSelectNextChar>> <Shift-Right> event add <<NtextPrevChar>> <Left> event add <<NtextSelectPrevChar>> <Shift-Left> event add <<NtextNextWord>> <Option-Right> event add <<NtextSelectNextWord>> <Shift-Option-Right> event add <<NtextPrevWord>> <Option-Left> event add <<NtextSelectPrevWord>> <Shift-Option-Left> event add <<NtextLineStart>> <Command-Left> event add <<NtextSelectLineStart>> <Shift-Command-Left> event add <<NtextLineEnd>> <Command-Right> event add <<NtextSelectLineEnd>> <Shift-Command-Right> event add <<NtextPrevLine>> <Up> event add <<NtextSelectPrevLine>> <Shift-Up> event add <<NtextNextLine>> <Down> event add <<NtextSelectNextLine>> <Shift-Down> # (4) Omit these bindings which tk.tcl describes as "Not official, but # logical extensions of above. Also derived from bindings present # in MS Word on [macOS]." # # - Ntext does not define these virtual events on macOS/Aqua. # - Keyboard navigation works differently on macOS/Aqua from other # platforms ("Option-Down" operations on macOS/Aqua move the insert # mark to the next paragraph end, but on other platforms # <<NtextNextPara>> moves the mark to the next paragraph start). # - It is unhelpful use the same virtual-event name to implement # different behavior on different platforms. # - On the macOS/Aqua platform, we implement bindings to raw events, and # leave these virtual events undefined. # - The boolean ::ntext::classicParagraphs allows the developer to # choose either standard macOS/Aqua behavior (value 0, the default), # or the same behavior as other platforms (value 1). # # event add <<NtextPrevPara>> <Option-Up> # event add <<NtextNextPara>> <Option-Down> # event add <<NtextSelectPrevPara>> <Shift-Option-Up> # event add <<NtextSelectNextPara>> <Shift-Option-Down> # Unwanted bindings on Aqua: # (5) In tk.tcl these are listed as "Official bindings"; however, # macOS/Aqua applications typically do not behave this way. # # We implement the macOS/Aqua-specific behavior using raw events, not # virtual events. # event add <<NtextLineStart>> <Home> # event add <<NtextSelectLineStart>> <Shift-Home> # event add <<NtextLineEnd>> <End> # event add <<NtextSelectLineEnd>> <Shift-End> } } # ------------------------------------------------------------------------------ # Clipboard events and tk_strictMotif # ------------------------------------------------------------------------------ # event add <<Cut>> <Shift-Key-Delete> # event add <<Copy>> <Control-Key-Insert> # event add <<Paste>> <Shift-Key-Insert> # 8.5 does this only for win32, and it is unaffected by tk_strictMotif -- # cf. 8.5.11, core-8.5-branch at 2013-01-14 # 8.6 adds and removes these events for X11 using a trace on tk_strictMotif -- # the trace exists only for X11; 8.6 adds events for win32 irrespective of # the value of tk_strictMotif # # We want the extra bindings for X11 on 8.5, so it is most sensible to create # NtextCut etc. # ------------------------------------------------------------------------------ # In tk.tcl, the "Emacs bindings" are added here, for the aqua case only - # they are not included for win32, and in x11 they are optional, applied with a # trace. # In ntext the Emacs bindings are optional for all windowingsystems. # ------------------------------------------------------------------------------ # "Emacs-like bindings" # ------------------------------------------------------------------------------ # These "Emacs-like bindings" (to characters "abefnp") are used in the Text # binding tag. In tk.tcl in Tk 8.6 they were removed for the win32 # windowingsystem, and they were added to the definitions of the virtual events # <<NtextNextChar>> etc for the other windowing systems. # Later versions of tk.tcl also removed the Emacs bindings # from the virtual-event definitions for x11, and for that windowingsystem only # they used a write trace on ::tk_strictMotif to add or remove the bindings by # calling the command ::tk::EventMotifBindings. I.e. the Emacs bindings are # always on for aqua, always off for win32, and optional for x11. # # Ntext makes all these events optional, including for win32. The events are # managed by a write trace on the variables ::ntext::classicExtras and # ::tk_strictMotif which calls the command ::ntext::EmacsBindings. # # The loss of the "Emacs-like bindings" from Text for win32 allows the use of # <Control-a> for <<NtextSelectAll>>; however this usage is also common in X11 # applications, and illustrates why the "Emacs-like bindings" are often a bad # idea: they often conflict with bindings used by win32/x11 applications, # e.g. <Control-n> for "New Document", <Control-p> for "Print". # # In Ntext the "Emacs-like bindings" are switched off by default. # # Binding to virtual events instead of real events give a small saving in # repeated code, but at the expense of tracing variables to maintain # the effects of ::tk_strictMotif and ::ntext::classicExtras. # # event add <<NtextNextChar>> <Control-Key-f> <Control-Lock-Key-F> # event add <<NtextSelectNextChar>> <Control-Key-F> <Control-Lock-Key-f> # event add <<NtextPrevChar>> <Control-Key-b> <Control-Lock-Key-B> # event add <<NtextSelectPrevChar>> <Control-Key-B> <Control-Lock-Key-b> # event add <<NtextLineStart>> <Control-Key-a> <Control-Lock-Key-A> # event add <<NtextSelectLineStart>> <Control-Key-A> <Control-Lock-Key-a> # event add <<NtextLineEnd>> <Control-Key-e> <Control-Lock-Key-E> # event add <<NtextSelectLineEnd>> <Control-Key-E> <Control-Lock-Key-e> # event add <<NtextPrevLine>> <Control-Key-p> <Control-Lock-Key-P> # event add <<NtextSelectPrevLine>> <Control-Key-P> <Control-Lock-Key-p> # event add <<NtextNextLine>> <Control-Key-n> <Control-Lock-Key-N> # event add <<NtextSelectNextLine>> <Control-Key-N> <Control-Lock-Key-n> # (For Aqua, the real events may also have a "Shift" modifier.) # # Other "Emacs-like bindings" (to characters "dkot") are not associated with # virtual events and are defined in the code below. # ------------------------------------------------------------------------------ #------------------------------------------------------------------------- # The code below creates the Ntext class bindings for text widgets. #------------------------------------------------------------------------- # Mouse bindings: use ::ntext::Bcount to deal with out-of-order multiple # clicks. This permits the bindings to be simplified bind Ntext <1> { set ::ntext::Bcount 1 ntext::TextButton1 %W %x %y %W tag remove sel 0.0 end |
︙ | ︙ | |||
70 71 72 73 74 75 76 | set ::ntext::Bcount 1 ntext::TextButton1 %W %x %y %W tag remove sel 0.0 end } set ::ntext::Bcount 2 set tk::Priv(selectMode) word ntext::TextSelectTo %W %x %y | | > > | > > | | | | | | | | | 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 | set ::ntext::Bcount 1 ntext::TextButton1 %W %x %y %W tag remove sel 0.0 end } set ::ntext::Bcount 2 set tk::Priv(selectMode) word ntext::TextSelectTo %W %x %y catch {%W mark set insert sel.last} catch {%W mark set [ntext::TextAnchor %W] sel.first} catch {%W mark gravity [ntext::TextAnchor %W] right} } # ignore an out-of-order triple click. This has no adverse consequences. bind Ntext <Triple-1> { if {$::ntext::Bcount != 2} { continue } set ::ntext::Bcount 3 set tk::Priv(selectMode) line ntext::TextSelectTo %W %x %y catch {%W mark set insert sel.last} catch {%W mark set [ntext::TextAnchor %W] sel.first} catch {%W mark gravity [ntext::TextAnchor %W] right} } # don't care if a quadruple click is out-of-order (i.e. follows a quadruple # click, not a triple click). bind Ntext <Quadruple-1> { set ::ntext::Bcount 4 } bind Ntext <Shift-1> { set ::ntext::Bcount 1 if {(!$::ntext::classicMouseSelect) && ([%W tag ranges sel] eq "")} { # Move the selection anchor mark to the old insert mark. # The anchor mark's gravity will be set by TextSelectTo. %W mark set [ntext::TextAnchor %W] insert } if {$::ntext::classicAnchor} { ntext::TextResetAnchor %W @%x,%y # if sel exists, sets anchor to end furthest from x,y # changes anchor only, not insert } set tk::Priv(selectMode) char ntext::TextSelectTo %W %x %y } # Inside the outer if: # The previous Button-1 event was not a single-click, but a double, triple, # or quadruple. # We can simplify the bindings if we ensure that a double-click is # *always* preceded by a single-click. # So in this case run the same code as <Shift-1> before doing <Double-Shift-1> bind Ntext <Double-Shift-1> { if {$::ntext::Bcount != 1} { set ::ntext::Bcount 1 if {(!$::ntext::classicMouseSelect) && ([%W tag ranges sel] eq "")} { # Move the selection anchor mark to the old insert mark. # The anchor mark's gravity will be set by TextSelectTo. %W mark set [ntext::TextAnchor %W] insert } if {$::ntext::classicAnchor} { ntext::TextResetAnchor %W @%x,%y # if sel exists, sets anchor to end furthest from x,y # changes anchor only, not insert } set tk::Priv(selectMode) char ntext::TextSelectTo %W %x %y } set ::ntext::Bcount 2 |
︙ | ︙ | |||
155 156 157 158 159 160 161 162 163 164 165 166 167 | tk::CancelRepeat } bind Ntext <ButtonRelease-1> { tk::CancelRepeat } bind Ntext <Control-1> { %W mark set insert @%x,%y if {[%W cget -autoseparators]} { %W edit separator } } bind Ntext <Double-Control-1> { # nothing } bind Ntext <Control-B1-Motion> { # nothing } | > > > > > | > | > | > | | > | | > | | | | | | | | | | > | | | > | | > | | > | | | | | | | | | | > | | > | | | > | | | | > | | | > | | > | | | 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 | tk::CancelRepeat } bind Ntext <ButtonRelease-1> { tk::CancelRepeat } bind Ntext <Control-1> { %W mark set insert @%x,%y # An operation that moves the insert mark without making it # one end of the selection must insert an autoseparator if {[%W cget -autoseparators]} { %W edit separator } } # stop an accidental double click triggering <Double-Button-1> bind Ntext <Double-Control-1> { # nothing } # stop an accidental movement triggering <B1-Motion> bind Ntext <Control-B1-Motion> { # nothing } bind Ntext <<NtextPrevChar>> { ntext::AdjustInsert %W left ntext::TextSetCursor %W insert-1displayindices } bind Ntext <<NtextNextChar>> { ntext::AdjustInsert %W right ntext::TextSetCursor %W insert+1displayindices } bind Ntext <<NtextPrevLine>> { ntext::AdjustInsert %W left ntext::TextSetCursor %W [ntext::TextUpDownLine %W -1] } bind Ntext <<NtextNextLine>> { ntext::AdjustInsert %W right ntext::TextSetCursor %W [ntext::TextUpDownLine %W 1] } bind Ntext <<NtextSelectPrevChar>> { ntext::TextKeySelect %W [%W index {insert - 1displayindices}] } bind Ntext <<NtextSelectNextChar>> { ntext::TextKeySelect %W [%W index {insert + 1displayindices}] } bind Ntext <<NtextSelectPrevLine>> { ntext::TextKeySelect %W [ntext::TextUpDownLine %W -1] } bind Ntext <<NtextSelectNextLine>> { ntext::TextKeySelect %W [ntext::TextUpDownLine %W 1] } bind Ntext <<NtextPrevWord>> { ntext::AdjustInsert %W left ntext::TextSetCursor %W \ [ntext::TextPrevPos %W insert ntext::new_startOfPreviousWord] } bind Ntext <<NtextNextWord>> { ntext::AdjustInsert %W right ntext::TextSetCursor %W [ntext::TextNextWord %W insert] } bind Ntext <<NtextPrevPara>> { ntext::AdjustInsert %W left ntext::TextSetCursor %W [ntext::TextPrevPara %W insert] } bind Ntext <<NtextNextPara>> { ntext::AdjustInsert %W right ntext::TextSetCursor %W [ntext::TextNextPara %W insert] } bind Ntext <<NtextSelectPrevWord>> { ntext::TextKeySelect %W \ [ntext::TextPrevPos %W insert ntext::new_startOfPreviousWord] } bind Ntext <<NtextSelectNextWord>> { ntext::TextKeySelect %W [ntext::TextNextWord %W insert] } bind Ntext <<NtextSelectPrevPara>> { ntext::TextKeySelect %W [ntext::TextPrevPara %W insert] } bind Ntext <<NtextSelectNextPara>> { ntext::TextKeySelect %W [ntext::TextNextPara %W insert] } bind Ntext <Prior> { ntext::AdjustInsert %W left ntext::TextSetCursor %W [ntext::TextScrollPages %W -1 preScroll] } bind Ntext <Shift-Prior> { ntext::TextKeySelect %W [ntext::TextScrollPages %W -1 preScroll] } bind Ntext <Next> { ntext::AdjustInsert %W right ntext::TextSetCursor %W [ntext::TextScrollPages %W 1 preScroll] } bind Ntext <Shift-Next> { ntext::TextKeySelect %W [ntext::TextScrollPages %W 1 preScroll] } bind Ntext <Control-Prior> { %W xview scroll -1 page } bind Ntext <Control-Next> { %W xview scroll 1 page } bind Ntext <<NtextLineStart>> { ntext::AdjustInsert %W left ntext::TextSetCursor %W [::ntext::HomeIndex %W insert] } bind Ntext <<NtextSelectLineStart>> { ntext::TextKeySelect %W [::ntext::HomeIndex %W insert] } bind Ntext <<NtextLineEnd>> { ntext::AdjustInsert %W right ntext::TextSetCursor %W [::ntext::EndIndex %W insert] } bind Ntext <<NtextSelectLineEnd>> { ntext::TextKeySelect %W [::ntext::EndIndex %W insert] } bind Ntext <Control-Home> { #ntext::AdjustInsert %W left ntext::TextSetCursor %W 1.0 } bind Ntext <Control-Shift-Home> { ntext::TextKeySelect %W 1.0 } bind Ntext <Control-End> { #ntext::AdjustInsert %W right ntext::TextSetCursor %W {end - 1 indices} } bind Ntext <Control-Shift-End> { ntext::TextKeySelect %W {end - 1 indices} } bind Ntext <Tab> { if {[%W cget -state] eq "normal"} { ntext::TextInsert %W \t focus %W break |
︙ | ︙ | |||
285 286 287 288 289 290 291 | bind Ntext <Return> { ntext::TextInsert %W \n if {[%W cget -autoseparators]} { %W edit separator } } bind Ntext <Delete> { | > > > | > > > > > | > > > | | > > > > > > > > | > > > > > | | > | | < | > | > | | | | > > | | | | > > > > > > > > | 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 | bind Ntext <Return> { ntext::TextInsert %W \n if {[%W cget -autoseparators]} { %W edit separator } } bind Ntext <Delete> { if {[ntext::TextCursorInSelection %W]} { # When deleting the selection, make this an atomic operation on the Undo # stack, i.e. separate it from other delete operations on either side. if {[%W cget -autoseparators]} { %W edit separator } else { } set ::ntext::OldFirst [%W index sel.first] %W delete sel.first sel.last ntext::AdjustIndentOneLine %W $::ntext::OldFirst if {[%W cget -autoseparators]} { %W edit separator } else { } } elseif {[%W compare end != insert+1c]} { %W delete insert ntext::AdjustIndentOneLine %W insert } %W see insert } bind Ntext <BackSpace> { if {[ntext::TextCursorInSelection %W]} { set ::ntext::OldFirst [%W index sel.first] %W delete sel.first sel.last ntext::AdjustIndentOneLine %W $::ntext::OldFirst } elseif {[%W compare insert != 1.0]} { %W delete insert-1c ntext::AdjustIndentOneLine %W insert } %W see insert } # This is present in early versions of # 8.5 and intercepts the Shift-Backspace event. catch {bind Ntext <Terminate_Server> { if {[ntext::TextCursorInSelection %W]} { set ::ntext::OldFirst [%W index sel.first] %W delete sel.first sel.last ntext::AdjustIndentOneLine %W $::ntext::OldFirst } elseif {[%W compare insert != 1.0]} { %W delete insert-1c ntext::AdjustIndentOneLine %W insert } %W see insert }} bind Ntext <Control-space> { if {$::ntext::classicExtras} { %W mark set [ntext::TextAnchor %W] insert %W mark gravity [ntext::TextAnchor %W] right } } bind Ntext <Select> { %W mark set [ntext::TextAnchor %W] insert %W mark gravity [ntext::TextAnchor %W] right } bind Ntext <Control-Shift-space> { if {$::ntext::classicExtras} { set tk::Priv(selectMode) char ntext::TextKeyExtend %W insert } } bind Ntext <Shift-Select> { set tk::Priv(selectMode) char ntext::TextKeyExtend %W insert } bind Ntext <<NtextSelectAll>> { %W tag add sel 1.0 end } bind Ntext <<NtextSelectNone>> { %W tag remove sel 1.0 end # An operation that clears the selection must insert an autoseparator, # because the selection operation may have moved the insert mark if {[%W cget -autoseparators]} { %W edit separator } } bind Ntext <<NtextCut>> { ntext::new_textCut %W } bind Ntext <<NtextCopy>> { ntext::new_textCopy %W } bind Ntext <<NtextPaste>> { ntext::new_textPaste %W } bind Ntext <<Clear>> { # Make <<Clear>> an atomic operation on the Undo stack, # i.e. separate it from other delete operations on either side if {[%W tag nextrange sel 1.0 end] ne ""} { if {[%W cget -autoseparators]} { %W edit separator } set ::ntext::OldFirst [%W index sel.first] %W delete sel.first sel.last ntext::AdjustIndentOneLine %W $::ntext::OldFirst if {[%W cget -autoseparators]} { %W edit separator } } } bind Ntext <<PasteSelection>> { if {$tk_strictMotif || ![info exists tk::Priv(mouseMoved)] || !$tk::Priv(mouseMoved)} { ntext::TextPasteSelection %W %x %y } |
︙ | ︙ | |||
391 392 393 394 395 396 397 | } } bind Ntext <KP_Enter> {# nothing} if {[tk windowingsystem] eq "aqua"} { bind Ntext <Command-KeyPress> {# nothing} } | | | | | < < < < < | < < < < | | < < < < < | < < < < < < < < < < < < < < < | > > > | < > > | > > > > | | | < | > > | > | > | | > | > > > > > > > > > > > > > > > > > > | > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > | > > > > > | > | > > > | > > > > > > > > > > > > > > > > > > > > > > > > > > > > > | > > > > > > > > > > > > > > > > > > > > | > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > | > > > > | > > > > | > > > > | < < < | > > | > > > | < < > > | > > > | < < < < < < < < > > > > > > > > > > > > > > > > > > > > > > | | > > > > > > > > > > > > > | | | | | | | | | | > | | | | | > > > > > > > > > > > > > > > > > > > | | > > > > > > | | | | | | | | | | | | | | | | | | | | | | | | > > > > > > > > > > > > > | | | | | | < | | | | > > > > > > > > > > > > > > > > | > > > > > > > > > > > > > > | > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > | | 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 | } } bind Ntext <KP_Enter> {# nothing} if {[tk windowingsystem] eq "aqua"} { bind Ntext <Command-KeyPress> {# nothing} } # Additional Emacs-like bindings: # cf. <Delete>, but not fixed for TextCursorInSelection and no see bind Ntext <Control-d> { if {$::ntext::classicExtras && !$tk_strictMotif && [%W compare end != insert+1c]} { %W delete insert ntext::AdjustIndentOneLine %W insert } } bind Ntext <Control-k> { if {$::ntext::classicExtras && !$tk_strictMotif && [%W compare end != insert+1c]} { if {[%W compare insert == {insert lineend}]} { %W delete insert } else { %W delete insert {insert lineend} } ntext::AdjustIndentOneLine %W insert } } bind Ntext <Control-o> { if {$::ntext::classicExtras && !$tk_strictMotif} { %W insert insert \n %W mark set insert insert-1c ntext::AdjustIndentOneLine %W "insert + 1 line" } } bind Ntext <Control-t> { if {$::ntext::classicExtras && !$tk_strictMotif} { ntext::TextTranspose %W } } bind Ntext <<Undo>> { # An Undo operation may remove the separator at the top of the Undo stack. # Then the item at the top of the stack gets merged with the subsequent # changes. # Place separators before and after Undo to prevent this. if {[%W cget -autoseparators]} { %W edit separator } if {![catch { %W edit undo }]} { # Cancel the selection so that Undo does not mess it up. %W tag remove sel 0.0 end # The undo stack does not record tags - so we need to reapply them. ntext::AdjustIndentMultipleLines %W 1.0 end } if {[%W cget -autoseparators]} { %W edit separator } } bind Ntext <<Redo>> { if {![catch { %W edit redo }]} { # Cancel the selection so that Redo does not mess it up. %W tag remove sel 0.0 end # The redo stack does not record tags - so we need to reapply them. ntext::AdjustIndentMultipleLines %W 1.0 end } } # Which platforms use the Meta modifier? # Not macOS/Aqua, PC/Windows or PC/Linux with standard keyboard. # If you know, please give details at http://wiki.tcl.tk/28331 bind Ntext <Meta-b> { if {!$tk_strictMotif} { ntext::AdjustInsert %W left ntext::TextSetCursor %W \ [ntext::TextPrevPos %W insert ntext::new_startOfPreviousWord] } } bind Ntext <Meta-d> { if {!$tk_strictMotif && [%W compare end != insert+1c]} { %W delete insert [ntext::TextNextWord %W insert] ntext::AdjustIndentOneLine %W insert } } bind Ntext <Meta-f> { if {!$tk_strictMotif} { ntext::AdjustInsert %W right ntext::TextSetCursor %W [ntext::TextNextWord %W insert] } } bind Ntext <Meta-less> { if {!$tk_strictMotif} { #ntext::AdjustInsert %W left ntext::TextSetCursor %W 1.0 } } bind Ntext <Meta-greater> { if {!$tk_strictMotif} { #ntext::AdjustInsert %W right ntext::TextSetCursor %W end-1c } } bind Ntext <Meta-BackSpace> { if {!$tk_strictMotif} { %W delete \ [ntext::TextPrevPos %W insert ntext::new_startOfPreviousWord] \ insert } ntext::AdjustIndentOneLine %W insert } bind Ntext <Meta-Delete> { if {!$tk_strictMotif} { %W delete \ [ntext::TextPrevPos %W insert ntext::new_startOfPreviousWord] \ insert } ntext::AdjustIndentOneLine %W insert } # Non-macOS/Aqua bindings: if {[tk windowingsystem] eq "aqua"} { # There is no insert/overwrite switch. The widget is always in insert mode. } else { # The <Insert> key is the insert/overwrite switch. # The cursor color indicates the insert/overwrite state. # Make sure it is in sync with the all-widgets value of ::ntext::overwrite. bind Ntext <FocusIn> { if {$ntext::overwrite} { %W configure -insertbackground red } else { %W configure -insertbackground black } } } # macOS/Aqua only bindings: # # The following virtual events are not defined on the macOS/Aqua platform: # <<NtextPrevPara>> # <<NtextNextPara>> # <<NtextSelectPrevPara>> # <<NtextSelectNextPara>> # Ntext uses the raw events <Option-Up>, <Option-Down>, <Shift-Option-Up>, # <Shift-Option-Down> instead. # # In contrast, tk.tcl, text.tcl, and the Text binding tag use virtual events. # For discussion, see the virtual event definitions above. if {[tk windowingsystem] eq "aqua"} { # Some of the bindings above for non-virtual events must be replaced. # Other macOS/Aqua-specific bindings must be added. # (0) Non-Printing Keypresses # On Aqua versions where non-printing keypresses emit a character, those events # use the Mod4 modifier. The binding below prevents binding to <KeyPress>, but # not to a more specific binding, if it exists. E.g. <KeyPress-F5> etc are # deemed more specific. catch {bind Ntext <Mod4-KeyPress> {# nothing}} # (1) Prior/Next with/without Modifier Keys. # In non-Aqua, <Prior>, <Next> and modifications with Shift move the insert # mark - they behave like <Up>/<<NtextPrevLine>>, <Down>/<<NtextNextLine>> # but with a larger increment. With the Control modifier, scrolling is # horizontal and does NOT move the insert mark. # In Aqua, <Prior>, <Next> DO NOT move the insert mark; The Control modifier # DOES move the insert mark, and the Shift modifier DOES move the insert mark # AND also extends the selection. # # In Tk, if <Control-Shift-Prior> is undefined it does same as <Control-Prior>, # not the same as <Shift-Prior>. # This behavior agrees with other macOS/Aqua applications, and it leaves # macOS/Aqua (unlike other windowing systems) with no keyboard bindings for # horizontal scrolling. bind Ntext <Control-Prior> { ntext::AdjustInsert %W left ntext::TextSetCursor %W [ntext::TextScrollPages %W -1 preScroll] } bind Ntext <Shift-Prior> { ntext::TextKeySelect %W [ntext::TextScrollPages %W -1 preScroll] } bind Ntext <Control-Next> { ntext::AdjustInsert %W right ntext::TextSetCursor %W [ntext::TextScrollPages %W 1 preScroll] } bind Ntext <Shift-Next> { ntext::TextKeySelect %W [ntext::TextScrollPages %W 1 preScroll] } bind Ntext <Prior> { %W yview scroll -1 page } bind Ntext <Next> { %W yview scroll 1 page } # Extra Bindings: # Option-Prior, Option-Next do the same as Control-Prior, Control-Next; # the Shift modifier has no effect. bind Ntext <Option-Prior> { ntext::AdjustInsert %W left ntext::TextSetCursor %W [ntext::TextScrollPages %W -1 preScroll] } bind Ntext <Option-Next> { ntext::AdjustInsert %W right ntext::TextSetCursor %W [ntext::TextScrollPages %W 1 preScroll] } # Stop these firing as <Prior>, <Next>: bind Ntext <Command-Prior> {# nothing} bind Ntext <Command-Next> {# nothing} # (2) Home/End with/without Modifier Keys. # This usage is conventional macOS/Aqua behavior; note that tk.tcl makes # these events do <<?Select?Line(Start|End)>> like on other platforms. bind Ntext <Home> { %W see 1.0 } bind Ntext <End> { %W see {end - 1 indices} } bind Ntext <Shift-Home> { ntext::TextKeySelect %W 1.0 } bind Ntext <Shift-End> { ntext::TextKeySelect %W {end - 1 indices} } # Stop these firing as <Home>: bind Ntext <Control-Home> {# nothing} bind Ntext <Control-Shift-Home> {# nothing} bind Ntext <Command-Home> {# nothing} bind Ntext <Option-Home> {# nothing} # Stop these firing as <End>: bind Ntext <Control-End> {# nothing} bind Ntext <Control-Shift-End> {# nothing} bind Ntext <Command-End> {# nothing} bind Ntext <Option-End> {# nothing} ### # <Up>, <Down>, <Shift-Up>, <Shift-Down> (move by 1 line) # Wrapped as <<NtextPrevLine>>, <<NtextNextLine>>, <<NtextSelectPrevLine>>, # <<NtextSelectNextLine>>. # Same for all platforms, no changes needed for macOS/Aqua. ### # (3) Command-Up, Command-Down, with/without Shift Modifier. # <Command-Up>, <Command-Down>, <Command-Shift-Up>, <Command-Shift-Down> are # implemented below, and are the macOS/Aqua equivalents of # <Control-Home>, <Control-Shift-Home>, <Control-End>, <Control-Shift-End> # respectively. We could define some events - # <<NtextTop>>, <<NtextSelectTop>>, <<NtextBottom>>, <<NtextSelectBottom>> bind Ntext <Command-Up> { #ntext::AdjustInsert %W left ntext::TextSetCursor %W 1.0 } bind Ntext <Command-Shift-Up> { ntext::TextKeySelect %W 1.0 } bind Ntext <Command-Down> { #ntext::AdjustInsert %W right ntext::TextSetCursor %W {end - 1 indices} } bind Ntext <Command-Shift-Down> { ntext::TextKeySelect %W {end - 1 indices} } # (4) Control-(Left|Right|Up|Down), with/without Shift Modifier. # # In recent versions of macOS/Aqua, these keyboard events are intercepted by the # windowing system, and are not delivered to the application. # # These null bindings ensure that these events are not interpreted as # <(Up|Down|Left|Right)> on older versions of macOS/Aqua that do not # intercept these events. bind Ntext <Control-Left> {# nothing} bind Ntext <Control-Right> {# nothing} bind Ntext <Control-Up> {# nothing} bind Ntext <Control-Down> {# nothing} # (5) Option-Up, Option-Down, with/without Shift Modifier # These Option (Alt key) bindings are not provided on other platforms. # The outcome depends on the value of classicParagraphs. # if {$::ntext::classicParagraphs} # Do what non-macOS/Aqua Tk applications do (for Control-Up etc): navigate between # paragraph starts, with movement of the insert mark. The start of a paragraph # is the first non-blank character after a blank line. # # This behavior differs from that of other Aqua applications. # if {!$::ntext::classicParagraphs} # Do what other macOS/Aqua applications do: logical line navigation, with # movement of the insert mark. # # - Option-Up goes to the previous {start of a logical line}. # - Option-Down goes to the next {end of a logical line}. # - Shift-Option-(Up|Down) allow selection. bind Ntext <Option-Up> { if {$::ntext::classicParagraphs} { # Like Tk Text on Aqua. ntext::AdjustInsert %W left ntext::TextSetCursor %W [ntext::TextPrevPara %W insert] } else { # Like Aqua's TextEdit ntext::AdjustInsert %W left ntext::TextSetCursor %W [::ntext::MacHomeIndex %W insert] } } bind Ntext <Option-Down> { if {$::ntext::classicParagraphs} { # Like Tk Text on Aqua. ntext::AdjustInsert %W right ntext::TextSetCursor %W [ntext::TextNextPara %W insert] } else { # Like Aqua's TextEdit ntext::AdjustInsert %W right ntext::TextSetCursor %W [::ntext::MacEndIndex %W insert] } } bind Ntext <Shift-Option-Up> { if {$::ntext::classicParagraphs} { # Like Tk Text on Aqua. ntext::TextKeySelect %W [ntext::TextPrevPara %W insert] } else { # Like Aqua's TextEdit ntext::TextKeySelect %W [::ntext::MacHomeIndex %W insert] } } bind Ntext <Shift-Option-Down> { if {$::ntext::classicParagraphs} { # Like Tk Text on Aqua. ntext::TextKeySelect %W [ntext::TextNextPara %W insert] } else { # Like Aqua's TextEdit ntext::TextKeySelect %W [::ntext::MacEndIndex %W insert] } } # (6) Control-v - a macOS/Aqua-only binding to scroll down a page. # # macOS/Aqua TextEdit and Xcode move the insert mark as well as scrolling. # Do the same here, using ntext::TextScrollPages. In contrast, Text's # tk::TextScrollPages only scrolls, and does not move the insert mark. # Does the same as macOS/Aqua's <Control-Next>. # # N.B. There seems to be no counterpart binding for scrolling up. Don't Mac # users need to scroll up as well as down? Feedback from Mac users please. # # Remove this binding. #bind Ntext <Control-v> { ### tk::TextScrollPages %W 1 ## %W yview scroll 1 pages # ntext::AdjustInsert %W right # ntext::TextSetCursor %W [ntext::TextScrollPages %W +1 preScroll] #} # bind Ntext <Control-Shift-v> {# nothing} # End of macOS/Aqua-only bindings } # A few additional bindings of my own. # cf. <BackSpace>, but not fixed for TextCursorInSelection bind Ntext <Control-h> { if {$::ntext::classicExtras && (!$tk_strictMotif) && [%W compare insert != 1.0]} { %W delete insert-1c %W see insert ntext::AdjustIndentOneLine %W insert } } if {[tk windowingsystem] eq "aqua"} { bind Ntext <3> { if {!$tk_strictMotif} { ntext::TextScanMark %W %x %y } } bind Ntext <B3-Motion> { if {!$tk_strictMotif} { ntext::TextScanDrag %W %x %y } } } else { bind Ntext <2> { if {!$tk_strictMotif} { ntext::TextScanMark %W %x %y } } bind Ntext <B2-Motion> { if {!$tk_strictMotif} { ntext::TextScanDrag %W %x %y } } } set ::tk::Priv(prevPos) {} # The MouseWheel will typically only fire on Windows and macOS/Aqua. # However, someone could use the "event generate" command to produce one # on other platforms. We must be careful not to round -ve values of %D # down to zero. if {[tk windowingsystem] eq "aqua"} { bind Ntext <MouseWheel> { %W yview scroll [expr {-15 * (%D)}] pixels } bind Ntext <Option-MouseWheel> { %W yview scroll [expr {-150 * (%D)}] pixels } bind Ntext <Shift-MouseWheel> { %W xview scroll [expr {-15 * (%D)}] pixels } bind Ntext <Shift-Option-MouseWheel> { %W xview scroll [expr {-150 * (%D)}] pixels } } else { # We must make sure that positive and negative movements are rounded # equally to integers, avoiding the problem that # (int)1/3 = 0, # but # (int)-1/3 = -1 # The following code ensure equal +/- behaviour. bind Ntext <MouseWheel> { if {%D >= 0} { %W yview scroll [expr {-%D/3}] pixels } else { %W yview scroll [expr {(2-%D)/3}] pixels } } bind Ntext <Shift-MouseWheel> { if {%D >= 0} { %W xview scroll [expr {-%D/3}] pixels } else { %W xview scroll [expr {(2-%D)/3}] pixels } } } if {"x11" eq [tk windowingsystem]} { # Support for mousewheels on Linux/Unix commonly comes through mapping # the wheel to the extended buttons. If you have a mousewheel, find # Linux configuration info at: # http://www.inria.fr/koala/colas/mouse-wheel-scroll/ bind Ntext <4> { if {!$tk_strictMotif} { %W yview scroll -50 pixels } } bind Ntext <5> { if {!$tk_strictMotif} { %W yview scroll 50 pixels } } bind Ntext <Shift-4> { if {!$tk_strictMotif} { %W xview scroll -50 pixels } } bind Ntext <Shift-5> { if {!$tk_strictMotif} { %W xview scroll 50 pixels } } } bind Ntext <Configure> { ::ntext::AdjustIndentMultipleLines %W 1.0 end } bind Ntext <Destroy> { unset -nocomplain ::ntext::OldSelectMode(%W) } ##### End of bindings. Now define the namespace and its variables. namespace eval ::ntext { namespace export createMatchPatterns initializeMatchPatterns namespace export new_endOfWord new_textCopy new_textCut new_textPaste namespace export new_startOfNextWord new_startOfPreviousWord namespace export new_wordBreakAfter new_wordBreakBefore wrapIndent # Variables that control the behaviour of certain bindings and may be # changed by the user's script # Set to 1 for "classic Text" style (the Tk defaults), 0 for "Ntext" style # Whether Shift-Button-1 has a variable or fixed anchor variable classicAnchor 0 # Whether to activate certain traditional "extra" bindings variable classicExtras 0 # Whether Shift-Button-1 ignores changes made by the keyboard to the insert # mark variable classicMouseSelect 0 # Type of word-boundary search variable classicWordBreak 0 # Whether to use -lmargin2 to align the wrapped display lines with their # own first display line variable classicWrap 1 # Advanced use (see man page): align to this character on the first display # line variable newWrapRegexp {[^[:space:]]} # Variable that sets overwrite/insert mode: may be changed by the user's # script but is normally controlled by a binding to <KeyPress-Insert> variable overwrite 0 # Debugging aid for developers: sets the background color for each logical # line according to the magnitude of its hanging (-lmargin2) indent. variable lm2IndentDebug 0 # When a keystroke cancels a selection, is the position of the insert mark # preserved, or does it jump to the "appropriate" end of the selection? if {[tk windowingsystem] eq "aqua"} { variable classicSelection 0 } else { variable classicSelection 1 } # Whether or not the macOS/Aqua bindings <?Shift-?Option-(Up|Down)> should use # classic Tk paragraphs rather than trying to emulate those of other macOS/Aqua # applications: variable classicParagraphs 0 # Variables that will hold regexp's for word boundary detection variable tcl_match_wordBreakAfter variable tcl_match_wordBreakBefore variable tcl_match_endOfWord variable tcl_match_startOfNextWord variable tcl_match_startOfPreviousWord # These variables are for internal use by ntext only. They should not be # modified by the user's script. variable Bcount 0 variable OldFirst {} variable OldSelectMode # array if {[tk windowingsystem] eq "aqua"} { variable EmacsEvents { <<NtextNextChar>> <Control-Key-f> <Control-Lock-Key-F> <<NtextSelectNextChar>> <Control-Shift-Key-F> <Control-Shift-Lock-Key-F> <<NtextPrevChar>> <Control-Key-b> <Control-Lock-Key-B> <<NtextSelectPrevChar>> <Control-Shift-Key-B> <Control-Shift-Lock-Key-B> <<NtextLineStart>> <Control-Key-a> <Control-Lock-Key-A> <<NtextSelectLineStart>> <Control-Shift-Key-A> <Control-Shift-Lock-Key-A> <<NtextLineEnd>> <Control-Key-e> <Control-Lock-Key-E> <<NtextSelectLineEnd>> <Control-Shift-Key-E> <Control-Shift-Lock-Key-E> <<NtextPrevLine>> <Control-Key-p> <Control-Lock-Key-P> <<NtextSelectPrevLine>> <Control-Shift-Key-P> <Control-Shift-Lock-Key-P> <<NtextNextLine>> <Control-Key-n> <Control-Lock-Key-N> <<NtextSelectNextLine>> <Control-Shift-Key-N> <Control-Shift-Lock-Key-N> } } else { variable EmacsEvents { <<NtextNextChar>> <Control-Key-f> <Control-Lock-Key-F> <<NtextSelectNextChar>> <Control-Key-F> <Control-Lock-Key-f> <<NtextPrevChar>> <Control-Key-b> <Control-Lock-Key-B> <<NtextSelectPrevChar>> <Control-Key-B> <Control-Lock-Key-b> <<NtextLineStart>> <Control-Key-a> <Control-Lock-Key-A> <<NtextSelectLineStart>> <Control-Key-A> <Control-Lock-Key-a> <<NtextLineEnd>> <Control-Key-e> <Control-Lock-Key-E> <<NtextSelectLineEnd>> <Control-Key-E> <Control-Lock-Key-e> <<NtextPrevLine>> <Control-Key-p> <Control-Lock-Key-P> <<NtextSelectPrevLine>> <Control-Key-P> <Control-Lock-Key-p> <<NtextNextLine>> <Control-Key-n> <Control-Lock-Key-N> <<NtextSelectNextLine>> <Control-Key-N> <Control-Lock-Key-n> } } trace add variable ::ntext::classicExtras write ::ntext::EmacsBindings trace add variable ::tk_strictMotif write ::ntext::EmacsBindings } ##### End of namespace definition. Now define the procs. # ::ntext::EmacsBindings -- # Command bound to traces on variables ::ntext::classicExtras and # ::tk_strictMotif, to add or remove the "Emacs bindings" whenever the values # of these variables change. proc ::ntext::EmacsBindings {argVarName var2 action} { variable EmacsEvents variable classicExtras if {$::ntext::classicExtras && !$::tk_strictMotif} { set op add } else { set op delete } foreach {virtual real1 real2} $EmacsEvents { event $op $virtual $real1 $real2 } if {[tk windowingsystem] eq "x11"} { if {!$::tk_strictMotif} { set op2 add } else { set op2 delete } event $op2 <<NtextCut>> <Control-Key-w> <Control-Lock-Key-W> <Shift-Key-Delete> event $op2 <<NtextCopy>> <Meta-Key-w> <Meta-Lock-Key-W> <Control-Key-Insert> event $op2 <<NtextPaste>> <Control-Key-y> <Control-Lock-Key-Y> <Shift-Key-Insert> } return } # Trigger the trace, to call ::ntext::EmacsBindings for the first time. set ::tk_strictMotif $::tk_strictMotif # ::tk::TextClosestGap -- # Given x and y coordinates, this procedure finds the closest boundary # between characters to the given coordinates and returns the index # of the character just after the boundary. # # Arguments: # w - The text window. # x - X-coordinate within the window. # y - Y-coordinate within the window. # ::ntext::TextClosestGap -- # modified to fix the jump-to-next-line issue. proc ::ntext::TextClosestGap {w x y} { set pos [$w index @$x,$y] set bbox [$w bbox $pos] if {$bbox eq ""} { return $pos |
︙ | ︙ | |||
741 742 743 744 745 746 747 | # and claims the input focus. # # Arguments: # w - The text window in which the button was pressed. # x - The x-coordinate of the button press. # y - The x-coordinate of the button press. | | | > | | | | | > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > | | > > > > > > > > | > > > > | > > > > | > > > > > > > > > > > > > > > > > < > > | | > > > | | > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > | | | | > > > > > > > > > > > > | | | | | | > > > > > > > > > > > > > > > > > > > > > > > > | > > > > > > > > > < < < | < | < < | < < < < < < < < < < < < | | < | | | > > > > > > > > > > > > > > | | | > > > > | | > > > > > > > > | > > > > | > > > > > > > > > > > > | > > > > > > > > > > > | > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > | | 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 1548 1549 1550 1551 1552 1553 1554 1555 1556 1557 1558 1559 1560 1561 1562 1563 1564 1565 1566 1567 1568 1569 1570 1571 1572 1573 1574 1575 1576 1577 1578 1579 1580 1581 1582 1583 1584 1585 1586 1587 1588 1589 1590 1591 1592 1593 1594 1595 1596 1597 1598 1599 1600 1601 1602 1603 1604 1605 1606 1607 1608 1609 1610 1611 1612 1613 1614 1615 1616 1617 1618 1619 1620 1621 1622 1623 1624 1625 1626 1627 1628 1629 1630 1631 1632 1633 1634 1635 1636 1637 1638 1639 1640 1641 1642 1643 1644 1645 1646 1647 1648 1649 1650 1651 1652 1653 1654 1655 1656 1657 1658 1659 1660 1661 1662 1663 1664 1665 1666 1667 1668 1669 1670 1671 1672 1673 1674 1675 1676 1677 1678 1679 1680 1681 1682 1683 1684 1685 1686 1687 1688 1689 1690 1691 1692 1693 1694 1695 1696 1697 1698 1699 1700 1701 1702 1703 1704 1705 1706 1707 1708 1709 1710 1711 1712 1713 1714 1715 1716 1717 1718 1719 1720 1721 1722 1723 1724 1725 1726 1727 1728 1729 1730 1731 1732 1733 1734 1735 1736 1737 1738 1739 1740 1741 1742 1743 1744 1745 1746 1747 1748 1749 1750 1751 1752 1753 1754 1755 1756 1757 1758 1759 1760 1761 1762 1763 1764 1765 1766 1767 1768 1769 1770 1771 1772 1773 1774 1775 1776 1777 1778 1779 1780 1781 1782 1783 1784 1785 1786 1787 1788 1789 1790 1791 1792 1793 1794 1795 1796 1797 1798 1799 1800 1801 1802 1803 1804 1805 1806 1807 1808 1809 1810 1811 1812 1813 1814 1815 1816 1817 1818 1819 1820 1821 1822 1823 1824 1825 1826 1827 1828 1829 1830 1831 1832 1833 1834 1835 1836 1837 1838 1839 1840 1841 1842 1843 1844 1845 1846 | # and claims the input focus. # # Arguments: # w - The text window in which the button was pressed. # x - The x-coordinate of the button press. # y - The x-coordinate of the button press. # ::ntext::TextButton1 -- # Modified to call TextAnchor not tk::TextAnchor. proc ::ntext::TextButton1 {w x y} { variable ::tk::Priv set Priv(selectMode) char set Priv(mouseMoved) 0 set Priv(pressX) $x set anchorname [TextAnchor $w] $w mark set insert [TextClosestGap $w $x $y] $w mark set $anchorname insert # Set the anchor mark's gravity depending on the click position # relative to the gap set bbox [$w bbox [$w index $anchorname]] if {$x > [lindex $bbox 0]} { $w mark gravity $anchorname right } else { $w mark gravity $anchorname left } # Allow focus in any case on Windows, because that will let the # selection be displayed even for state disabled text widgets. if {[tk windowingsystem] eq "win32" \ || [$w cget -state] eq "normal"} { focus $w } if {[$w cget -autoseparators]} { $w edit separator } } # If text.tcl is sufficiently recent to have ::tk::Priv(textanchoruid), this # forces it to be initialized. catch {::tk::TextAnchor} if {[info exists ::tk::Priv(textanchoruid)]} { # Variable has been initialized and possibly incremented by text.tcl. # Don't change its value. } else { set ::tk::Priv(textanchoruid) 0 # text.tcl may increment this variable but will not re-initialize it. } # ::ntext::TextAnchor -- # Modified to use ::tk::Priv despite change of namespace. proc ::ntext::TextAnchor {w} { variable ::tk::Priv if {![info exists Priv(textanchor,$w)]} { set Priv(textanchor,$w) tk::anchor[incr Priv(textanchoruid)] } return $Priv(textanchor,$w) } # ::ntext::RepelAnchor -- # Command to move the anchor to the end of the "recorded selection" that # is furthest from $idx. proc ::ntext::RepelAnchor {w idx} { set anchorname [TextAnchor $w] set distFirst [$w count -displaychars ntext::left::$anchorname $idx] set distLast [$w count -displaychars ntext::right::$anchorname $idx] if {abs($distFirst) < abs($distLast)} { $w mark set $anchorname [$w index ntext::right::$anchorname] $w mark gravity $anchorname left } else { $w mark set $anchorname [$w index ntext::left::$anchorname] $w mark gravity $anchorname right } return } # ::ntext::WordBounds -- # Command abstracted from ::ntext::TextSelectTo because it is now called twice. # Extend first/last to word boundaries, but do not allow a "word" to straddle # a display line boundary (or, in -wrap char mode, a logical line boundary). proc ::ntext::WordBounds {w lineType first last} { # Now find word boundaries set first1 [$w index "$first + 1c"] set last1 [$w index "$last - 1c"] if {[$w count -$lineType $first $first1] != 0} { set first1 [$w index $first] } else { } if {[$w count -$lineType $last $last1] != 0} { set last1 [$w index $last] } else { } set first2 [TextPrevPos $w "$first1" ntext::new_wordBreakBefore] set last2 [TextNextPos $w "$last1" ntext::new_wordBreakAfter] # Don't allow a "word" to straddle a display line boundary (or, # in -wrap char mode, a logical line boundary). # WARNING This is not the right result if -wrap word has been # forced into -wrap char because a word is too long - but it is hard to # produce sensible results in this case. if {[$w count -$lineType $first2 $first] != 0} { set first [$w index "$first display linestart"] } else { set first $first2 } if {[$w count -$lineType $last2 $last] != 0} { set last [$w index "$last display lineend"] } else { set last $last2 } return [list $first $last] } # ::tk::TextSelectTo -- # This procedure is invoked to extend the selection, typically when # dragging it with the mouse*. Depending on the selection mode (character, # word, line) it selects in different-sized units. This procedure # ignores mouse motions initially until the mouse has moved from # one character to another or until there have been multiple clicks. # # Note that the 'anchor' is implemented programmatically using # a text widget mark, and uses a name that will be unique for each # text widget (even when there are multiple peers). Currently the # anchor is considered private to Tk, hence the name 'tk::anchor$i'. # # Arguments: # w - The text window in which the button was pressed. # x - Mouse x position. # y - Mouse y position. # extend - Unused # * Such mouse drag operations are <B1-Motion>, <B1-Leave> (TextSelectTo # called via TextAutoScan). # TextSelectTo is also called by the bindings to <Double-1>, <Triple-1>, # <Shift-1>, <Double-Shift-1>, <Triple-Shift-1>. # # The command changes the selection and the insert mark. # ::ntext::TextSelectTo -- # This extensively modified command also sets the anchor mark (unlike # tk::TextSelectTo which does not set the anchor mark unless it is undefined). # # Modifications: # - prevent word selection from crossing a line end. # - improve repeated selection by word and line - to stop # expansion/contraction of the selection at the "wrong" end, in operations # that are intended to alter the selection ar the cursor end. # - set the anchor and insert marks for each call. # # - The command sets the insert mark to the end of the selection that is closest # to the mouse position $cur. It sets the anchor to the other end of the # selection. # - The gravity of the anchor is set so it is facing the selection. # - Internally the command sometimes uses its own anchor marks, # ntext::left::$anchorname and ntext::right::$anchorname. These delimit a # "recorded selection". When the user performs a sequence of pointer # operations on the selection, using selectMode "word" or "line", the # "recorded selection" (the first selection of the sequence) is used to # constrain the end of the selection that is furthest from the pointer. # - These marks are set and used only by TextSelectTo and by RepelAnchor (which # is called only from TextSelectTo). # - The command also uses the array ::ntext::OldSelectMode to record state. # The Ntext binding to <Destroy> garbage-collects the array. # - When changing the selection, rearrange operations so that the selection is # never full, then empty, then full. proc ::ntext::TextSelectTo {w x y {extend 0}} { variable ::tk::Priv variable OldSelectMode set anchorname [TextAnchor $w] set cur [TextClosestGap $w $x $y] if {[catch {$w index $anchorname}]} { $w mark set $anchorname $cur # Right gravity is set by default. # Could set gravity as in TextButton1, but the value in this case is # not important. } if {[$w compare $cur != $anchorname] || (abs($Priv(pressX) - $x) >= 3)} { set Priv(mouseMoved) 1 } set selectionExists [expr {[$w tag ranges sel] ne ""}] if {[catch {$w index ntext::left::$anchorname}]} { $w mark set ntext::left::$anchorname $cur # Right gravity is set by default. # The gravity value is irrelevant. } if {[catch {$w index ntext::right::$anchorname}]} { $w mark set ntext::right::$anchorname $cur # Right gravity is set by default. # The gravity value is irrelevant. } if {(![info exists OldSelectMode($w)]) || (!$selectionExists)} { set OldSelectMode($w) char } if {(!$selectionExists) || ($OldSelectMode($w) eq "char")} { $w mark set ntext::left::$anchorname $anchorname $w mark set ntext::right::$anchorname $anchorname } switch -- $Priv(selectMode) { char { if {$selectionExists && $OldSelectMode($w) ne "char"} { # Move the anchor to the end of the "recorded selection" # that is furthest from $cur. (If oldSelectMode is char, keep # the existing anchor.) RepelAnchor $w $cur } else { $w mark set ntext::left::$anchorname $anchorname $w mark set ntext::right::$anchorname $anchorname } if {[$w compare $cur < $anchorname]} { set first $cur set last [$w index $anchorname] } else { set first [$w index $anchorname] set last $cur } } word { # Set initial range based only on the anchor (1 char min width - # MOD - unless this straddles a display line end) if {[$w cget -wrap] eq "word"} { set lineType displaylines } else { set lineType lines } # The gravity of the "selection anchor" mark. # - The anchor's gravity is explicitly used only here. # - In text.tcl the anchor mark's gravity is set by # ::tk::TextButton1 depending on the click position relative to # the gap. # - In ntext.tcl, the anchor mark's gravity is also set in other # places, to prevent inappropriate growth of the selection when # the value is tested here. When the anchor is at an end of the # selection, its gravity always faces the selected text. # - The gravity of the insert mark, and of the ntext::* "recorded # selection" marks, are never explicitly used, and their values # are always "right". if {[$w mark gravity $anchorname] eq "right"} { set first $anchorname set last "$anchorname + 1c" if {[$w count -$lineType $first $last] != 0} { set last $first } else { } } else { set first "$anchorname - 1c" set last $anchorname if {[$w count -$lineType $first $last] != 0} { set first $last } else { } } if {[$w compare $last == $first] && [$w compare $cur == $first]} { # Use $first and $last as above; further extension will straddle # a display line. Better to have no selection than a bad one. set StoreAnchors 1 } else { set first0 $first set last0 $last if {$selectionExists && $OldSelectMode($w) eq "char"} { # Do WordBounds calc but without cur. This computes the # ntext::* anchor marks. This code is necessary if the user # has used character selection to extend the selection, and # then come here by using word selection. # Compute ntext::* anchor marks on the transition from # "char" to "word" selection. lassign [WordBounds $w $lineType $first $last] first last # The new selection will be a single word. $w mark set ntext::left::$anchorname $first $w mark set ntext::right::$anchorname $last set OldSelectMode($w) word set StoreAnchors 0 } else { set StoreAnchors 1 } # Now do the conventional/text.tcl WordBounds calc with cur. set first $first0 set last $last0 set extend 0 # Extend range (if necessary) to include the current point if {[$w compare $cur < $first]} { set first $cur if { ($OldSelectMode($w) eq "line") && [$w compare $last == "$last linestart"] } { # This kludge stops the selection growing by one word in # the wrong direction. set last "$last-1c" set extend 1 } else { } } elseif {[$w compare $cur > $last]} { set last $cur } lassign [WordBounds $w $lineType $first $last] first last if {$extend} { set last [$w index $last+1c] } else { } } if { (!$selectionExists) && ($OldSelectMode($w) eq "char") && $StoreAnchors } { # Compute ntext::* anchor marks on the transition from "char" # to "word" selection. # The new selection will be a single word. $w mark set ntext::left::$anchorname $first $w mark set ntext::right::$anchorname $last set OldSelectMode($w) word } } line { if {$selectionExists && $OldSelectMode($w) eq "line"} { # Use saved values. Take care to avoid "creep" by one line # per call due to "lineend+1c". set first "ntext::left::$anchorname" set last "ntext::right::$anchorname" } else { # Compute ntext::* anchor marks if OldSelectMode is not "line" # or (unlikely) if there is no existing selection. # The "recorded selection" is based only on the anchor. set first "$anchorname linestart" set last "$anchorname lineend+1c" $w mark set ntext::left::$anchorname $first $w mark set ntext::right::$anchorname $last set OldSelectMode($w) line } # Extend range (if necessary) based on the current point if {[$w compare $cur < $first]} { set first "$cur linestart" } elseif {[$w compare $cur > $last]} { set last "$cur lineend+1c" } set first [$w index $first] set last [$w index $last] } } if {$Priv(mouseMoved) || ($Priv(selectMode) ne "char")} { # Set the insert mark and anchor to the ends of the selection. # The insert mark is the end that is closest to the mouse position $cur. set distFirst [$w count -displaychars $first $cur] set distLast [$w count -displaychars $last $cur] if {abs($distFirst) < abs($distLast)} { set newInsert $first set newAnchor $last set newGrav left } else { set newInsert $last set newAnchor $first set newGrav right } # $w mark set insert $cur $w mark set insert $newInsert $w mark set $anchorname $newAnchor $w mark gravity $anchorname $newGrav # Rearrange operations so that selection is never full-empty-full. # $w tag remove sel 0.0 end $w tag add sel $first $last $w tag remove sel 1.0 $first $w tag remove sel $last end update idletasks } return } # ::tk::TextKeyExtend -- # This procedure handles extending the selection from the keyboard, # where the point to extend to is really the boundary between two # characters rather than a particular character. # # Arguments: # w - The text window. # index - The point to which the selection is to be extended. # Called only by bindings to <Control-Shift-space> and <Shift-Select>. # Extends the selection from the anchor to the index (the actual argument is # the insert mark). # # Changes the selection. Does not set the anchor mark unless # it is undefined. Does not set the insert mark. # ::ntext::TextKeyExtend -- # - Call TextAnchor not tk::TextAnchor. # - Set the gravity of the anchor. # - When changing the selection, rearrange operations so that the selection is # never full, then empty, then full. proc ::ntext::TextKeyExtend {w index} { set anchorname [TextAnchor $w] set cur [$w index $index] if {[catch {$w index $anchorname}]} { $w mark set $anchorname $cur # Right gravity is set by default. } if {[$w compare $cur < $anchorname]} { set first $cur set last $anchorname set grav left } else { set first $anchorname set last $cur set grav right } # Rearrange operations so that selection is never full-empty-full. # $w tag remove sel 0.0 $first $w tag add sel $first $last $w tag remove sel 0.0 $first $w tag remove sel $last end $w mark gravity $anchorname $grav return } # ::tk::TextPasteSelection -- # This procedure sets the insertion cursor to the mouse position, # inserts the selection, and sets the focus to the window. # # Arguments: # w - The text window. # x, y - Position of the mouse. # ::ntext::TextPasteSelection -- # modified to set oldInsert and call AdjustIndentMultipleLines. proc ::ntext::TextPasteSelection {w x y} { $w mark set insert [TextClosestGap $w $x $y] set oldInsert [$w index insert] if {![catch {::tk::GetSelection $w PRIMARY} sel]} { set oldSeparator [$w cget -autoseparators] |
︙ | ︙ | |||
937 938 939 940 941 942 943 | } } if {[$w cget -state] eq "normal"} { focus $w } } | < | < | | 1856 1857 1858 1859 1860 1861 1862 1863 1864 1865 1866 1867 1868 1869 1870 1871 1872 1873 1874 1875 1876 1877 1878 1879 1880 1881 1882 | } } if {[$w cget -state] eq "normal"} { focus $w } } # ::tk::TextAutoScan -- # This procedure is invoked when the mouse leaves a text window # with button 1 down. It scrolls the window up, down, left, or right, # depending on where the mouse is (this information was saved in # ::tk::Priv(x) and ::tk::Priv(y)), and reschedules itself as an "after" # command so that the window continues to scroll until the mouse # moves back into the window or the mouse button is released. # # Arguments: # w - The text window. # ::ntext::TextAutoScan -- # Modified so it calls itself and not ::tk::TextAutoScan. proc ::ntext::TextAutoScan {w} { variable ::tk::Priv if {![winfo exists $w]} { return } if {$Priv(y) >= [winfo height $w]} { |
︙ | ︙ | |||
973 974 975 976 977 978 979 | } else { return } TextSelectTo $w $Priv(x) $Priv(y) set Priv(afterId) [after 50 [list ntext::TextAutoScan $w]] } | | > > > > | > > > > > > > > > > > > > > > > | > > > | > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > | > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > | | | | < < < | | | | | | | < > | | > > > > > > | > > > > > > > > > > > > > > > > > > > > > > > | > > > | > > > > > > > > > > > > > > > > > > > > > | > > > > > > > > > > > > > > > > > > > > > > > > > > > > | > | > | | 1890 1891 1892 1893 1894 1895 1896 1897 1898 1899 1900 1901 1902 1903 1904 1905 1906 1907 1908 1909 1910 1911 1912 1913 1914 1915 1916 1917 1918 1919 1920 1921 1922 1923 1924 1925 1926 1927 1928 1929 1930 1931 1932 1933 1934 1935 1936 1937 1938 1939 1940 1941 1942 1943 1944 1945 1946 1947 1948 1949 1950 1951 1952 1953 1954 1955 1956 1957 1958 1959 1960 1961 1962 1963 1964 1965 1966 1967 1968 1969 1970 1971 1972 1973 1974 1975 1976 1977 1978 1979 1980 1981 1982 1983 1984 1985 1986 1987 1988 1989 1990 1991 1992 1993 1994 1995 1996 1997 1998 1999 2000 2001 2002 2003 2004 2005 2006 2007 2008 2009 2010 2011 2012 2013 2014 2015 2016 2017 2018 2019 2020 2021 2022 2023 2024 2025 2026 2027 2028 2029 2030 2031 2032 2033 2034 2035 2036 2037 2038 2039 2040 2041 2042 2043 2044 2045 2046 2047 2048 2049 2050 2051 2052 2053 2054 2055 2056 2057 2058 2059 2060 2061 2062 2063 2064 2065 2066 2067 2068 2069 2070 2071 2072 2073 2074 2075 2076 2077 2078 2079 2080 2081 2082 2083 2084 2085 2086 2087 2088 2089 2090 2091 2092 2093 2094 2095 2096 2097 2098 2099 2100 2101 2102 2103 2104 2105 2106 2107 2108 2109 2110 2111 2112 2113 2114 2115 2116 2117 2118 2119 2120 2121 2122 2123 2124 2125 2126 2127 2128 2129 2130 2131 2132 2133 2134 2135 2136 2137 2138 2139 2140 2141 2142 2143 2144 2145 2146 2147 2148 2149 2150 2151 2152 2153 2154 2155 2156 2157 2158 2159 2160 2161 2162 2163 2164 2165 2166 2167 2168 2169 2170 2171 2172 2173 2174 2175 2176 2177 2178 2179 2180 2181 2182 2183 2184 2185 2186 2187 2188 2189 2190 2191 2192 2193 2194 2195 2196 2197 2198 2199 2200 2201 2202 2203 2204 2205 2206 2207 2208 2209 2210 2211 2212 2213 2214 2215 2216 2217 2218 2219 2220 2221 2222 2223 2224 2225 2226 2227 2228 2229 | } else { return } TextSelectTo $w $Priv(x) $Priv(y) set Priv(afterId) [after 50 [list ntext::TextAutoScan $w]] } # ::tk::TextSetCursor # Move the insertion cursor to a given position in a text. Also # clears the selection, if there is one in the text, and makes sure # that the insertion cursor is visible. Also, don't let the insertion # cursor appear on the dummy last line of the text. # # Arguments: # w - The text window. # pos - The desired new position for the cursor in the window. proc ::ntext::TextSetCursor {w pos} { if {[$w compare $pos == end]} { set pos {end - 1 chars} } $w mark set insert $pos $w tag remove sel 1.0 end $w see insert if {[$w cget -autoseparators]} { $w edit separator } } # ::tk::TextKeySelect -- # This procedure is invoked when stroking out selections using the # keyboard. It moves the cursor to a new position, then extends # the selection to that position. # # Arguments: # w - The text window. # new - A new position for the insertion cursor (the cursor hasn't # actually been moved to this position yet). # ::ntext::TextKeySelect -- # - Call TextAnchor not tk::TextAnchor. # - Set the gravity of the anchor. # - When changing the selection, rearrange operations so that the selection is # never full, then empty, then full. proc ::ntext::TextKeySelect {w new} { set anchorname [TextAnchor $w] if {[$w tag nextrange sel 1.0 end] eq ""} { if {[$w compare $new < insert]} { $w tag add sel $new insert $w mark set $anchorname insert $w mark gravity $anchorname left } else { $w tag add sel insert $new $w mark set $anchorname insert $w mark gravity $anchorname right } } else { if {[$w compare $new < $anchorname]} { set first $new set last $anchorname set grav left } else { set first $anchorname set last $new set grav right } # Rearrange operations so that selection is never full-empty-full. $w tag add sel $first $last $w tag remove sel 1.0 $first $w tag remove sel $last end $w mark gravity $anchorname $grav } $w mark set insert $new $w see insert update idletasks } # ::tk::TextResetAnchor -- # Set the selection anchor to whichever end is farthest from the # index argument. One special trick: if the selection has two or # fewer characters, just leave the anchor where it is. In this # case it doesn't matter which point gets chosen for the anchor, # and for the things like Shift-Left and Shift-Right this produces # better behavior when the cursor moves back and forth across the # anchor. # # Arguments: # w - The text widget. # index - Position at which mouse button was pressed, which determines # which end of selection should be used as anchor point. # Called by <Shift-1>, <Double-Shift-1> iff ($::ntext::classicAnchor). # ::ntext::TextResetAnchor -- # - Call TextAnchor not tk::TextAnchor. # - Set the gravity of the anchor. proc ::ntext::TextResetAnchor {w index} { if {[$w tag ranges sel] eq ""} { # Don't move the anchor if there is no selection now; this # makes the widget behave "correctly" when the user clicks # once, then shift-clicks somewhere -- ie, the area between # the two clicks will be selected. [Bug: 5929]. return } set anchorname [TextAnchor $w] set a [$w index $index] set b [$w index sel.first] set c [$w index sel.last] if {[$w compare $a < $b]} { $w mark set $anchorname sel.last $w mark gravity $anchorname left return } if {[$w compare $a > $c]} { $w mark set $anchorname sel.first $w mark gravity $anchorname right return } scan $a "%d.%d" lineA chA scan $b "%d.%d" lineB chB scan $c "%d.%d" lineC chC if {$lineB < $lineC+2} { set total [string length [$w get $b $c]] if {$total <= 2} { return } if {[string length [$w get $b $a]] < ($total/2)} { $w mark set $anchorname sel.last $w mark gravity $anchorname left } else { $w mark set $anchorname sel.first $w mark gravity $anchorname right } return } if {($lineA-$lineB) < ($lineC-$lineA)} { $w mark set $anchorname sel.last $w mark gravity $anchorname left } else { $w mark set $anchorname sel.first $w mark gravity $anchorname right } } # ::tk::TextCursorInSelection -- # Check whether the selection exists and contains the insertion cursor. Note # that it assumes that the selection is contiguous. # # Arguments: # w - The text widget whose selection is to be checked proc ::ntext::TextCursorInSelection {w} { expr { [llength [$w tag ranges sel]] && [$w compare sel.first <= insert] && [$w compare sel.last >= insert] } } # ::tk::TextInsert -- # Insert a string into a text at the point of the insertion cursor. # If there is a selection in the text, and it covers the point of the # insertion cursor, then delete the selection before inserting. # # Arguments: # w - The text window in which to insert the string # s - The string to insert (usually just a single character) # ::ntext::TextInsert -- # - implement Insert/Overwrite # - call AdjustIndentOneLine proc ::ntext::TextInsert {w s} { if {$s eq "" || [$w cget -state] eq "disabled"} { return } set compound 0 if {[TextCursorInSelection $w]} { set compound [$w cget -autoseparators] if {$compound} { $w configure -autoseparators 0 $w edit separator } else { } $w delete sel.first sel.last } elseif {$::ntext::overwrite && ($s ne "\n") && ($s ne "\t") && ([$w get insert] ne "\n")} { set compound [$w cget -autoseparators] if {$compound} { $w configure -autoseparators 0 $w edit separator # When undoing an overwrite, the insert mark is left # in the "wrong" place - after and not before the change. # Some non-Tk editors do this too. } else { } $w delete insert } $w insert insert $s AdjustIndentOneLine $w insert $w see insert if {$compound} { $w edit separator $w configure -autoseparators 1 } } # ::tk::TextUpDownLine -- # Returns the index of the character one display line above or below the # insertion cursor. There are two tricky things here. First, we want to # maintain the original x position across repeated operations, even though # some lines that will get passed through don't have enough characters to # cover the original column. Second, don't try to scroll past the # beginning or end of the text. # # Arguments: # w - The text window in which the cursor is to move. # n - The number of display lines to move: -1 for up one line, # +1 for down one line. proc ::ntext::TextUpDownLine {w n} { variable ::tk::Priv set i [$w index insert] if {$Priv(prevPos) ne $i} { set Priv(textPosOrig) $i } set lines [$w count -displaylines $Priv(textPosOrig) $i] set new [$w index \ "$Priv(textPosOrig) + [expr {$lines + $n}] displaylines"] if {[$w compare $new == end] \ || [$w compare $new == "insert display linestart"]} { set new $i } set Priv(prevPos) $new return $new } # ::tk::TextPrevPara -- # Returns the index of the beginning of the paragraph just before a given # position in the text (the beginning of a paragraph is the first non-blank # character after a blank line). # # Arguments: # w - The text window in which the cursor is to move. # pos - Position at which to start search. proc ::ntext::TextPrevPara {w pos} { set pos [$w index "$pos linestart"] while {1} { if {([$w get "$pos - 1 line"] eq "\n" && ([$w get $pos] ne "\n")) \ || $pos eq "1.0"} { if {[regexp -indices -- {^[ \t]+(.)} \ [$w get $pos "$pos lineend"] -> index]} { set pos [$w index "$pos + [lindex $index 0] chars"] } if {[$w compare $pos != insert] || [lindex [split $pos .] 0]==1} { return $pos } } set pos [$w index "$pos - 1 line"] } } # ::tk::TextNextPara -- # Returns the index of the beginning of the paragraph just after a given # position in the text (the beginning of a paragraph is the first non-blank # character after a blank line). # # Arguments: # w - The text window in which the cursor is to move. # start - Position at which to start search. proc ::ntext::TextNextPara {w start} { set pos [$w index "$start linestart + 1 line"] while {[$w get $pos] ne "\n"} { if {[$w compare $pos == end]} { return [$w index "end - 1c"] } set pos [$w index "$pos + 1 line"] } while {[$w get $pos] eq "\n"} { set pos [$w index "$pos + 1 line"] if {[$w compare $pos == end]} { return [$w index "end - 1c"] } } if {[regexp -indices -- {^[ \t]+(.)} \ [$w get $pos "$pos lineend"] -> index]} { return [$w index "$pos + [lindex $index 0] chars"] } return $pos } # ::tk::TextScrollPages -- # This is a utility procedure used in bindings for moving up and down # pages and possibly extending the selection along the way. It scrolls # the view in the widget by the number of pages, and it returns the # index of the character that is at the same position in the new view # as the insertion cursor used to be in the old view. # # Arguments: # w - The text window in which the cursor is to move. # count - Number of pages forward to scroll; may be negative # to scroll backwards. # ::ntext::TextScrollPages -- # - This command is called like ::tk::TextScrollPages, but it is completely # rewritten, and behaves differently. # - It has an additional optional argument, "help". # # ::tk::TextScrollPages scrolls the widget, and returns an index (a new value # for the insert mark); if the mark was on-screen before the scroll, # ::tk::TextScrollPages tries to return an index that keeps it in the same # screen position. # # ::ntext::TextScrollPages takes a slightly different approach: # like ::tk::TextScrollPages, it returns an index (a new value for the insert # mark), and lets the calling code decide whether to move the mark. # Unlike ::tk::TextScrollPages, when called with two arguments it does no # scrolling - it relies on the calling code to do the scrolling, which in # practice is usually when it tries to 'see' the returned index value. # # By focussing on the insert mark, ::ntext::TextScrollPages has the # following useful features: # - When the slack is less than one page, it "moves" the insert mark as far # as possible. # - When there is no slack, it "moves" the insert mark to the start/end of # the widget. # - It uses ::ntext::TextUpDownLine to remember the initial x-value. # # When called with three arguments, 3rd argument = "preScroll", then, if the # new position of the insert mark is off-screen, ::ntext::TextScrollPages # will scroll the widget, to try to make the calling code's "see" move the # returned index value to the middle, not the edge, of the widget. This # feature is most useful in widgets with only a few visible lines, where it # prevents successive calls from moving the insert mark between the middle and |
︙ | ︙ | |||
1093 1094 1095 1096 1097 1098 1099 | } set visibleLines [$w count -displaylines @0,0 @0,20000] if {$visibleLines > $spareLines} { set pageLines [expr {$visibleLines - $spareLines}] } else { set pageLines 1 } | | | 2239 2240 2241 2242 2243 2244 2245 2246 2247 2248 2249 2250 2251 2252 2253 | } set visibleLines [$w count -displaylines @0,0 @0,20000] if {$visibleLines > $spareLines} { set pageLines [expr {$visibleLines - $spareLines}] } else { set pageLines 1 } set newInsert [TextUpDownLine $w [expr {$pageLines * $count}]] if {[$w compare $oldInsert != $newInsert]} { set finalInsert $newInsert } elseif {$count < 0} { set finalInsert 1.0 } else { set finalInsert [$w index "end -1 char"] } |
︙ | ︙ | |||
1124 1125 1126 1127 1128 1129 1130 | # unless the cursor is at the end of the line. In this case it # transposes the two characters to the left of the cursor. In either # case, the cursor ends up to the right of the transposed characters. # # Arguments: # w - Text window in which to transpose. | | | | | 2270 2271 2272 2273 2274 2275 2276 2277 2278 2279 2280 2281 2282 2283 2284 2285 2286 | # unless the cursor is at the end of the line. In this case it # transposes the two characters to the left of the cursor. In either # case, the cursor ends up to the right of the transposed characters. # # Arguments: # w - Text window in which to transpose. # ::ntext::TextTranspose -- # - calls AdjustIndentOneLine. # - renames local variable autosep to oldSeparator, as in other procs proc ::ntext::TextTranspose w { set pos insert if {[$w compare $pos != "$pos lineend"]} { set pos [$w index "$pos + 1 char"] } set new [$w get "$pos - 1 char"][$w get "$pos - 2 char"] |
︙ | ︙ | |||
1158 1159 1160 1161 1162 1163 1164 | $w see insert if {$oldSeparator} { $w edit separator $w configure -autoseparators 1 } } | | > > > > > > > > > > > > | | | | | > > | 2304 2305 2306 2307 2308 2309 2310 2311 2312 2313 2314 2315 2316 2317 2318 2319 2320 2321 2322 2323 2324 2325 2326 2327 2328 2329 2330 2331 2332 2333 2334 2335 2336 2337 2338 2339 2340 2341 2342 2343 2344 2345 2346 2347 2348 2349 | $w see insert if {$oldSeparator} { $w edit separator $w configure -autoseparators 1 } } # ::tk_textCopy -- # This procedure copies the selection from a text widget into the # clipboard. # # Arguments: # w - Name of a text widget. proc ::ntext::new_textCopy w { if {![catch {set data [$w get sel.first sel.last]}]} { clipboard clear -displayof $w clipboard append -displayof $w $data } } # ::tk_textCut -- # This procedure copies the selection from a text widget into the # clipboard, then deletes the selection (if it exists in the given # widget). # # Arguments: # w - Name of a text widget. # ::ntext::new_textCut -- # - set LocalOldFirst and call AdjustIndentOneLine. # - configure autoseparators 0|1 (might not be necessary) # - LocalOldFirst is never off by one: the final newline of the widget cannot # be deleted. proc ::ntext::new_textCut w { if {![catch {set data [$w get sel.first sel.last]}]} { # make <<Cut>> an atomic operation on the Undo stack, # i.e. separate it from other delete operations on either side set oldSeparator [$w cget -autoseparators] if {$oldSeparator} { $w configure -autoseparators 0 $w edit separator } set LocalOldFirst [$w index sel.first] clipboard clear -displayof $w |
︙ | ︙ | |||
1201 1202 1203 1204 1205 1206 1207 | # ::tk_textPaste -- # This procedure pastes the contents of the clipboard to the insertion # point in a text widget. # # Arguments: # w - Name of a text widget. | | | | | | < < > | 2361 2362 2363 2364 2365 2366 2367 2368 2369 2370 2371 2372 2373 2374 2375 2376 2377 2378 2379 2380 2381 2382 2383 2384 2385 2386 2387 2388 2389 2390 2391 2392 2393 2394 | # ::tk_textPaste -- # This procedure pastes the contents of the clipboard to the insertion # point in a text widget. # # Arguments: # w - Name of a text widget. # ::ntext::new_textPaste -- # - set oldInsert, LocalOldFirst and ntextIndentMark, and call # AdjustIndentMultipleLines # - behave the same way for X11 as for other windowing systems # - overwrite the selection (if it exists), even if the insert mark is elsewhere proc ::ntext::new_textPaste w { set oldInsert [$w index insert] if {![catch {::tk::GetSelection $w CLIPBOARD} sel]} { set oldSeparator [$w cget -autoseparators] if {$oldSeparator} { $w configure -autoseparators 0 $w edit separator } if {([tk windowingsystem] ne "x11TheOldFashionedWay") && \ ([$w tag nextrange sel 1.0 end] ne "")} { set LocalOldFirst [$w index sel.first] $w mark set ntextIndentMark sel.last # right gravity mark, survives deletion $w delete sel.first sel.last $w insert $LocalOldFirst $sel AdjustIndentMultipleLines $w $LocalOldFirst ntextIndentMark } else { $w insert insert $sel AdjustIndentMultipleLines $w $oldInsert insert } |
︙ | ︙ | |||
1247 1248 1249 1250 1251 1252 1253 | # end-of-word position or the next start-of-word position after the next # end-of-word position. # # Arguments: # w - The text window in which the cursor is to move. # start - Position at which to start search. | | | | | | > > > > > > > > > > > > > > > > > > > > > > | > > > > > > > > > > > > > > > > > > > > > > | > > > > > > > > > > > > > > > > | > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > < < < | < < | < | | > | | < | < < | < | | < | | | | | | | > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > | > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > | > > > > > > > > > > > > > > > | > > > > > | | > > > > > > > > > > > > > > > > > > > > > > > > > > > < < | 2406 2407 2408 2409 2410 2411 2412 2413 2414 2415 2416 2417 2418 2419 2420 2421 2422 2423 2424 2425 2426 2427 2428 2429 2430 2431 2432 2433 2434 2435 2436 2437 2438 2439 2440 2441 2442 2443 2444 2445 2446 2447 2448 2449 2450 2451 2452 2453 2454 2455 2456 2457 2458 2459 2460 2461 2462 2463 2464 2465 2466 2467 2468 2469 2470 2471 2472 2473 2474 2475 2476 2477 2478 2479 2480 2481 2482 2483 2484 2485 2486 2487 2488 2489 2490 2491 2492 2493 2494 2495 2496 2497 2498 2499 2500 2501 2502 2503 2504 2505 2506 2507 2508 2509 2510 2511 2512 2513 2514 2515 2516 2517 2518 2519 2520 2521 2522 2523 2524 2525 2526 2527 2528 2529 2530 2531 2532 2533 2534 2535 2536 2537 2538 2539 2540 2541 2542 2543 2544 2545 2546 2547 2548 2549 2550 2551 2552 2553 2554 2555 2556 2557 2558 2559 2560 2561 2562 2563 2564 2565 2566 2567 2568 2569 2570 2571 2572 2573 2574 2575 2576 2577 2578 2579 2580 2581 2582 2583 2584 2585 2586 2587 2588 2589 2590 2591 2592 2593 2594 2595 2596 2597 2598 2599 2600 2601 2602 2603 2604 2605 2606 2607 2608 2609 2610 2611 2612 2613 2614 2615 2616 2617 2618 2619 2620 2621 2622 2623 2624 2625 2626 2627 2628 2629 2630 2631 2632 2633 2634 2635 2636 2637 2638 2639 2640 2641 2642 2643 2644 2645 2646 2647 2648 2649 2650 2651 2652 2653 2654 2655 2656 2657 2658 2659 2660 2661 2662 2663 2664 2665 2666 2667 2668 2669 2670 2671 2672 2673 2674 2675 2676 2677 2678 2679 2680 2681 2682 2683 2684 2685 2686 2687 2688 2689 2690 2691 2692 2693 2694 2695 2696 2697 2698 2699 2700 2701 2702 2703 2704 2705 2706 2707 2708 2709 2710 2711 2712 2713 | # end-of-word position or the next start-of-word position after the next # end-of-word position. # # Arguments: # w - The text window in which the cursor is to move. # start - Position at which to start search. # ::ntext::TextNextWord -- # - use a platform-independent definition: always goes to the start of the next # word. proc ::ntext::TextNextWord {w start} { TextNextPos $w $start ntext::new_startOfNextWord } # ::tk::TextNextPos -- # Returns the index of the next position after the given starting # position in the text as computed by a specified function. # # Arguments: # w - The text window in which the cursor is to move. # start - Position at which to start search. # op - Function to use to find next position. proc ::ntext::TextNextPos {w start op} { set text "" set cur $start while {[$w compare $cur < end]} { set text $text[$w get -displaychars $cur "$cur lineend + 1c"] set pos [$op $text 0] if {$pos >= 0} { return [$w index "$start + $pos display chars"] } set cur [$w index "$cur lineend +1c"] } return end } # ::tk::TextPrevPos -- # Returns the index of the previous position before the given starting # position in the text as computed by a specified function. # # Arguments: # w - The text window in which the cursor is to move. # start - Position at which to start search. # op - Function to use to find next position. proc ::ntext::TextPrevPos {w start op} { set text "" set cur $start while {[$w compare $cur > 0.0]} { set text [$w get -displaychars "$cur linestart - 1c" $cur]$text set pos [$op $text end] if {$pos >= 0} { return [$w index "$cur linestart - 1c + $pos display chars"] } set cur [$w index "$cur linestart - 1c"] } return 0.0 } # ::tk::TextScanMark -- # # Marks the start of a possible scan drag operation # # Arguments: # w - The text window from which the text to get # x - x location on screen # y - y location on screen proc ::ntext::TextScanMark {w x y} { variable ::tk::Priv $w scan mark $x $y set Priv(x) $x set Priv(y) $y set Priv(mouseMoved) 0 } # ::tk::TextScanDrag -- # # Marks the start of a possible scan drag operation # # Arguments: # w - The text window from which the text to get # x - x location on screen # y - y location on screen proc ::ntext::TextScanDrag {w x y} { variable ::tk::Priv # Make sure these exist, as some weird situations can trigger the # motion binding without the initial press. [Bug #220269] if {![info exists Priv(x)]} { set Priv(x) $x } if {![info exists Priv(y)]} { set Priv(y) $y } if {($x != $Priv(x)) || ($y != $Priv(y))} { set Priv(mouseMoved) 1 } if {[info exists Priv(mouseMoved)] && $Priv(mouseMoved)} { $w scan dragto $x $y } } ##### END OF CODE THAT IS MODIFIED from the file text.tcl. ##### THE CODE ABOVE ALSO USES THE PROCS DEFINED BELOW. ##### Further procs for bindings: # Two new functions, HomeIndex and EndIndex, that can be used for "smart" Home # and End operations # ::ntext::HomeIndex -- # # Return the index to jump to (from $index) as "Smart Home" # Some corner cases (e.g. lots of leading whitespace, wrapped around) # probably have a better solution; but there's no consensus on how a # text editor should behave in such cases. # # Arguments: # w - Name of a text widget. # index - an index in the widget proc ::ntext::HomeIndex {w index} { set index [$w index $index] set lls [$w index "$index linestart"] set dls [$w index "$index display linestart"] set llnext [$w index "$lls + 1 line"] # Set firstNonSpace to the index of the first non-space character on the # logical line. set firstNonSpace [$w search -regexp -- {[^[:space:]]} $lls $llnext] # Ensure that $firstNonSpace is a valid index: if {$firstNonSpace eq {}} { # No regexp match: no non-whitespace characters on the line. set firstNonSpace $lls } # If there is leading whitespace on more than one display line, then in the # comments below, the "first display line" is defined to mean all display # lines up to and including the first non-whitespace character. if {[$w count -displaylines $index $firstNonSpace] >= 0} { # $index is on the first display line. if {$index eq $firstNonSpace} { # $index is at the first non-whitespace of the first display line. set home $lls } else { # $index is on the first display line, but not at the first # non-whitespace. set home $firstNonSpace } } else { if {$dls eq $index} { # $index is at the start of a display line other than the first. set home $firstNonSpace } else { # $index is not on the first display line, and we're not at our # display line's start. set home $dls } } return $home } # ::ntext::EndIndex -- # # Return the index to jump to (from $index) as "Smart End" # # Arguments: # w - Name of a text widget. # index - an index in the widget proc ::ntext::EndIndex {w index} { set index [$w index $index] set lls [$w index "$index linestart"] set dle [$w index "$index display lineend"] set lle [$w index "$index lineend"] set llnext [$w index "$lls + 1 line"] set lastNonSpace \ [$w search -regexp -- {[^[:space:]][[:space:]]*$} $lls $llnext] # Set firstTrailing to the position of the first trailing whitespace # character. if {$lastNonSpace eq {}} { # No regexp match: no non-whitespace characters on the line, or # no trailing whitespace. set firstTrailing $lle } else { set firstTrailing [$w index "$lastNonSpace + 1 indices"] } # If there is trailing whitespace on more than one display line, then in the # comments below, "last display line" is redefined to mean all display lines # from the first trailing whitespace character to the logical line end. if {[$w count -displaylines $index $firstTrailing] <= 0} { # We're on the last display line if {$index eq $lle} { # $index is at the logical line end. set end $firstTrailing } else { # $index is on the last display line, but not at the logical line # end. set end $lle } } else { if {$dle eq $index} { # $index is at the end of a display line other than the last. set end $lle } else { # $index is not on the last display line, and is not at its display # line's end. set end $dle } } return $end } # Extra procs for macOS/Aqua: # ::ntext::MacHomeIndex -- # # Return the index to which the insert mark should be moved by an # <Option-Up> event in Aqua. # # Arguments: # w - Name of a text widget. # index - an index in the widget proc ::ntext::MacHomeIndex {w index} { set index [$w index $index] set lls [$w index "$index linestart"] if {$lls eq $index} { # We're at the start of a logical line: return the start of the previous # logical line: return [$w index "$lls -1 indices linestart"] } else { # Return the logical line start: return $lls } } # ::ntext::MacEndIndex -- # # Return the index to which the insert mark should be moved by an # <Option-Down> event in Aqua. # # Arguments: # w - Name of a text widget. # index - an index in the widget proc ::ntext::MacEndIndex {w index} { set index [$w index $index] set lle [$w index "$index lineend"] if {$lle eq $index} { # We're at the end of a logical line: return the end of the next logical # line: return [$w index "$lle +1 indices lineend"] } else { # Return the logical line end: return $lle } } # ::ntext::AdjustInsert -- # # If there is a selection, and ::ntext::classicSelection has not been set, # move the insert mark to the left or right boundary of the selection # according to the argument dir. Used only in Aqua. # # Arguments: # w - Name of a text widget. # dir - The string "left" or "right", representing the direction # of navigation. proc ::ntext::AdjustInsert {w dir} { set ranges [$w tag ranges sel] if {$::ntext::classicSelection} { # Nothing to do } elseif {$ranges eq {}} { # Nothing to do } elseif {$dir eq "left"} { $w mark set insert [lindex $ranges 0] } elseif {$dir eq "right"} { $w mark set insert [lindex $ranges end] } else { return -code error {Argument "dir" should be "left" or "right".} } return } ##### START OF CODE FOR WORD BOUNDARY DETECTION # We define ::ntext counterparts for the functions in lib/tcl8.5/word.tcl # such as ::tcl_wordBreakAfter # See man page for discussion of the variables ::tcl_wordchars # and ::tcl_nonwordchars defined in word.tcl |
︙ | ︙ | |||
1393 1394 1395 1396 1397 1398 1399 | # new_nonwordchars - regexp expression for non-word characters # (e.g. whitespace) # new_word1chars - regexp expression for first set of word # characters (e.g. alphanumerics) # new_word2chars - (optional) regexp expression for second set # of word characters (e.g. punctuation) | | > | 2744 2745 2746 2747 2748 2749 2750 2751 2752 2753 2754 2755 2756 2757 2758 2759 | # new_nonwordchars - regexp expression for non-word characters # (e.g. whitespace) # new_word1chars - regexp expression for first set of word # characters (e.g. alphanumerics) # new_word2chars - (optional) regexp expression for second set # of word characters (e.g. punctuation) proc ::ntext::createMatchPatterns {new_nonwordchars new_word1chars \ {new_word2chars {}}} { variable tcl_match_wordBreakAfter variable tcl_match_wordBreakBefore variable tcl_match_endOfWord variable tcl_match_startOfNextWord variable tcl_match_startOfPreviousWord |
︙ | ︙ | |||
1456 1457 1458 1459 1460 1461 1462 | if {!$classicWordBreak} { # ntext style: two classes of word character set punct {]`|.,:;/~!%&*_+='~[{}^"?()} ;#" keep \ as a word char set space {[:space:]} set tcl_punctchars "\[${punct}-\]" set tcl_spacechars "\[${space}\]" set tcl_word1chars "\[^${punct}${space}-\]" | | | 2808 2809 2810 2811 2812 2813 2814 2815 2816 2817 2818 2819 2820 2821 2822 | if {!$classicWordBreak} { # ntext style: two classes of word character set punct {]`|.,:;/~!%&*_+='~[{}^"?()} ;#" keep \ as a word char set space {[:space:]} set tcl_punctchars "\[${punct}-\]" set tcl_spacechars "\[${space}\]" set tcl_word1chars "\[^${punct}${space}-\]" } elseif {[tk windowingsystem] eq "win32"} { # Windows style - any but a unicode space char set tcl_word1chars "\\S" set tcl_spacechars "\\s" set tcl_punctchars {} } else { # Motif style - any unicode word char (number, letter, or underscore) set tcl_word1chars "\\w" |
︙ | ︙ | |||
1647 1648 1649 1650 1651 1652 1653 | if {([$textWidget cget -wrap] eq "word") && !$classicWrap} { if {[llength $args] == 0} { AdjustIndentMultipleLines $textWidget 1.0 end } elseif {[llength $args] == 1} { AdjustIndentOneLine $textWidget [lindex $args 0] } else { AdjustIndentMultipleLines $textWidget \ | | | | 2999 3000 3001 3002 3003 3004 3005 3006 3007 3008 3009 3010 3011 3012 3013 3014 3015 3016 3017 3018 3019 3020 3021 3022 | if {([$textWidget cget -wrap] eq "word") && !$classicWrap} { if {[llength $args] == 0} { AdjustIndentMultipleLines $textWidget 1.0 end } elseif {[llength $args] == 1} { AdjustIndentOneLine $textWidget [lindex $args 0] } else { AdjustIndentMultipleLines $textWidget \ [lindex $args 0] [lindex $args 1] } } else { if {[llength $args] == 0} { RemoveIndentMultipleLines $textWidget 1.0 end } elseif {[llength $args] == 1} { RemoveIndentOneLine $textWidget [lindex $args 0] } else { RemoveIndentMultipleLines $textWidget \ [lindex $args 0] [lindex $args 1] } } return } # ::ntext::AdjustIndentMultipleLines -- # |
︙ | ︙ | |||
1825 1826 1827 1828 1829 1830 1831 | # tagNames now holds all tags on this logical line # Remove the ones that ntext has previously used to set -lmargin2 # These tags' names all begin with the same string. foreach tag $tagNames { if {[string range $tag 0 19] eq "ntextAlignLM2Indent="} { | < | 3177 3178 3179 3180 3181 3182 3183 3184 3185 3186 3187 3188 3189 3190 | # tagNames now holds all tags on this logical line # Remove the ones that ntext has previously used to set -lmargin2 # These tags' names all begin with the same string. foreach tag $tagNames { if {[string range $tag 0 19] eq "ntextAlignLM2Indent="} { $textWidget tag remove $tag $lineStart $nextLineStart } } return } # ::ntext::RemoveIndentMultipleLines -- |
︙ | ︙ | |||
1855 1856 1857 1858 1859 1860 1861 | if {[$textWidget count -lines $index1 $index2] < 0} { set index3 $index1 set index1 $index2 set index2 $index3 } else { } | | | < | 3206 3207 3208 3209 3210 3211 3212 3213 3214 3215 3216 3217 3218 3219 3220 3221 3222 3223 3224 3225 3226 3227 3228 3229 3230 3231 3232 3233 3234 | if {[$textWidget count -lines $index1 $index2] < 0} { set index3 $index1 set index1 $index2 set index2 $index3 } else { } if { ([$textWidget compare $index1 == 1.0]) && ([$textWidget compare $index2 == end])} { # shortcut if whole widget needs processing # Remove -lmargin2 indentation, by removing each tag in the # widget whose name begins "ntextAlignLM2Indent=" set tagNames [$textWidget tag names] # tagNames now holds all tags in the widget # Remove the ones that ntext has previously used to set -lmargin2 # These tags' names all begin with the same string. foreach tag $tagNames { if {[string range $tag 0 19] eq "ntextAlignLM2Indent="} { $textWidget tag remove $tag 1.0 end } } } else { # go through the widget line-by-line set index1 [$textWidget index "$index1 linestart"] set index2 [$textWidget index "$index2 linestart"] |
︙ | ︙ | |||
1916 1917 1918 1919 1920 1921 1922 | ##### End of procs. # Initialize match patterns for word boundary detection - ::ntext::initializeMatchPatterns | | | 3266 3267 3268 3269 3270 3271 3272 3273 | ##### End of procs. # Initialize match patterns for word boundary detection - ::ntext::initializeMatchPatterns package provide ntext 1.0b1 |
Changes to modules/ntext/ntextBindings.man.
1 | [comment {-*- tcl -*- ntextBindings manpage}] | | < < < < < < | | | | | > > > > | | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 | [comment {-*- tcl -*- ntextBindings manpage}] [manpage_begin ntextBindings n 1.0] [moddesc {Alternative Bindings for the Text Widget}] [titledesc {Alternative Bindings for the Text Widget}] [require Tcl 8.5] [require Tk 8.5] [require ntext [opt 1.0]] [description] The [package ntext] package provides a binding tag named [emph Ntext] for use by text widgets in place of the default [emph Text] binding tag. [para] The [emph Text] binding tag provides around one hundred bindings to the text widget (the exact number is platform-dependent). A few of these behave in a way that is different from most contemporary text-editing applications. [emph Ntext] aims to provide more familiar behaviour. [para] Features of the [emph Ntext] bindings that differ from the default [emph Text] bindings: [list_begin itemized] [item] Clicking near the end of a (logical) line moves the cursor to the end of that line [emph {(not the start of the next line)}]. If the widget is in [arg -wrap] [arg word] mode, the same rule applies to display lines. [item] Double-clicking or dragging near the end of a (logical) line will highlight/select characters from the end of that line [emph {(not the next line, or the region at the end of the line where there are no characters)}]. If the widget is in [arg -wrap] [arg word] mode, the same rule applies to display lines. [item] On windowing systems other than macOS Aqua, the [emph Home] key implements "Smart Home" (successive keypresses move the cursor to the start of the display line, then to the first non-whitespace character at the start of the logical line, then toggles between the beginning and end of leading whitespace); the [emph End] key implements "Smart End" (which is similar to "Smart Home"). On macOS Aqua, this functionality is provided by the operations <Command-Left> and <Command-Right>. [item] When a selection exists, a "Paste" operation (e.g. <Control-v>) overwrites the selection (as most editors do), and does so on all platforms. [item] On windowing systems other than macOS Aqua, the [emph Insert] key toggles between "Insert" and "Overwrite" modes for keyboard input. [emph {(In contrast, the Text binding tag uses}] Insert [emph {as a method to paste the "primary selection", a task that can be accomplished instead by mouse middle-click.)}] [item] The [emph Escape] key clears the selection. [item] On the macOS Aqua windowing system, [emph Ntext] follows Aqua conventions for keyboard navigation. Certain bindings related to vertical scrolling can be forced to behave in the same way as for the Windows and X11 windowing systems, by setting [var ::ntext::classicParagraphs] to [const 1] (see Section [sectref {CONFIGURATION OPTIONS}]). [item] On the macOS Aqua windowing system, [emph Ntext] follows Aqua conventions for placement of the insert mark when keyboard navigation cancels a selection. This behavior can be switched off by setting [var ::ntext::classicSelection] to [const 1] (see Section [sectref {CONFIGURATION OPTIONS}]). [item] Selecting with <Shift-Button1> selects from the previous position of the insertion cursor. [emph {(In the Text binding tag, the selection anchor may be the position of the previous mouse click.)}] [item] <Shift-Button1> operations do not alter the selection anchor. [emph {(In the Text binding tag, they do.)}] [item] By default, the [emph Ntext] binding tag does not provide several of the Control-key bindings supplied by the [emph Text] binding tag. Modern keyboards offer alternatives, such as cursor keys for navigation; modern applications often use the Control-key bindings for other purposes (e.g. <Control-p> for "print"). [list_end] In the last three cases, the behavior of [emph Text] is often useful, so [emph Ntext] gives you the option of retaining it, by setting variables defined in the ::ntext namespace to 1 (instead of their default 0). Explaining these features in more detail: [list_begin itemized] [item] If the mouse is clicked at position A, then the keyboard is used to move the cursor to B, then shift is held down, and the mouse is clicked at C: the [emph Text] binding tag gives a selection from A to C; the [emph Ntext] gives a selection from B to C. If you want [emph Ntext] to behave like [emph Text] in this respect, set [var ::ntext::classicMouseSelect] to 1. [item] The [emph Text] binding tag allows successive <Shift-Button-1> events to change both ends of the selection, by moving the selection anchor to the end of the selection furthest from the mouse click. Instead, the [emph Ntext] binding tag fixes the anchor, and multiple Shift-Button-1 events can only move the non-anchored end of the selection. If you want [emph Ntext] to behave like [emph Text] in this respect, set [var ::ntext::classicAnchor] to 1. In both [emph Text] and [emph Ntext], keyboard navigation with the Shift key held down alters the selection and keeps the selection anchor fixed. [item] The following "extra" [emph Text] bindings are switched off by default, but can be activated in [emph Ntext] by setting [var ::ntext::classicExtras] to 1: <Control-a>, <Control-b>, <Control-d>, <Control-e>, <Control-f>, <Control-h>, <Control-i>, <Control-k>, <Control-n>, <Control-o>, <Control-p>, <Control-t>, <Control-space>, <Control-Shift-space>. |
︙ | ︙ | |||
81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 | [var ::ntext::classicMouseSelect] [list_begin itemized] [item] [const 0] - (default value) selects [emph Ntext] behaviour, i.e. the anchor point for mouse selection operations is moved by keyboard navigation [item] [const 1] - selects classic [emph Text] behaviour [list_end] [para] [var ::ntext::overwrite] [list_begin itemized] [item] [const 0] - (initial value) text typed at the keyboard is inserted into the widget [item] [const 1] - text typed at the keyboard overwrites text already in the widget [item] The value is toggled by the [emph Insert] key. [list_end] [section EXAMPLE] To use [emph Ntext] but keep classic [emph Text] 's variable-anchor feature: [example { package require ntext text .t set ::ntext::classicAnchor 1 bindtags .t {.t Ntext . all} }] | > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > | | > > > > | 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 | [var ::ntext::classicMouseSelect] [list_begin itemized] [item] [const 0] - (default value) selects [emph Ntext] behaviour, i.e. the anchor point for mouse selection operations is moved by keyboard navigation [item] [const 1] - selects classic [emph Text] behaviour [list_end] [para] [var ::ntext::classicSelection] [list_begin itemized] [item] [const 0] - (default value on macOS Aqua) selects Mac-like behaviour, i.e. when a navigation keystroke cancels a selection, the insert mark first moves to the end of the selection determined by the navigation direction of the keystroke, and then the keystroke is applied. [item] [const 1] - (default value except on macOS Aqua) selects PC-like behaviour (the same as classic [emph Text]), i.e. when a navigation keystroke cancels a selection, the insert mark is not moved before the keystroke is applied. [list_end] [para] [var ::ntext::overwrite] [list_begin itemized] [item] [const 0] - (initial value) text typed at the keyboard is inserted into the widget [item] [const 1] - text typed at the keyboard overwrites text already in the widget [item] The value is toggled by the [emph Insert] key. [list_end] [para] [var ::ntext::classicParagraphs] [list_begin itemized] [item] [const 0] - (default value) on macOS Aqua, certain keyboard bindings are made to behave in the same way as the Mac application TextEdit. The bindings involve vertical scrolling of the screen and are <?Shift-?Option-(Up|Down)>. [item] [const 1] - on macOS Aqua, certain keyboard bindings are made to behave in the same way as for the Windows and X11 windowing systems and the classic [emph Text], ignoring the conventions of Aqua. The bindings involve vertical scrolling of the screen and are <?Shift-?Option-(Up|Down)>. [list_end] [section INTERNALS] In order to remain independent of the version of [package Tk] (8.5 or 8.6), [package ntext] defines its own virtual events. These new virtual events are used only in the [emph Ntext] binding tag, and therefore do not interfere with the real or virtual events used in other code. [para] These events include <<NtextCut>>, <<NtextCopy>>, <<NtextPaste>> which are used in place of <<Cut>>, <<Copy>>, <<Paste>> respectively. [para] The definition of the virtual event <<NtextCut>> (etc) is similar to that of <<Cut>> (etc) in [package Tk] 8.6. [section BUGS] This version of [package ntext] is intended to be compatible with all releases of [package Tk] 8.5 and 8.6, and with the branches [emph core-8-5-branch], [emph core-8-6-branch], and [emph trunk] in the source code repository for [package Tk]. Any incompatibility with any of these versions, for any [package Tk] windowing system, should be reported as a bug. Please report such in the category [emph ntext] of the [uri http://core.tcl.tk/tklib/reportlist {Tklib Trackers}]. [section EXAMPLE] To use [emph Ntext] but keep classic [emph Text] 's variable-anchor feature: [example { package require ntext text .t set ::ntext::classicAnchor 1 bindtags .t {.t Ntext . all} }] [see_also ntext] [see_also ntextIndent] [see_also text bindtags] [keywords text bindtags] [manpage_end] |
Changes to modules/ntext/ntextIndent.man.
1 | [comment {-*- tcl -*- ntextIndent manpage}] | | < < < < < < < < < | > > > > > > > > > > > > > > > > > > | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 | [comment {-*- tcl -*- ntextIndent manpage}] [manpage_begin ntextIndent n 1.0] [moddesc {ntext Indentation for the Text Widget}] [titledesc {ntext Indentation for the Text Widget}] [require Tcl 8.5] [require Tk 8.5] [require ntext [opt 1.0]] [description] The [package ntext] package provides a binding tag named [emph Ntext] for use by text widgets in place of the default [emph Text] binding tag. [para] Tk's text widget may be configured to wrap lines of text that are longer than the width of the text area, a feature that is familiar from text editors and word processors. A complete line of text (delimited by newlines, or by the beginning or end of the document) is called a "logical line". When a logical line is wrapped onto more than one line of the display area, these fragments of the logical line are called "display lines". [para] If a logical line begins with whitespace, then wrapped display lines begin further to the left than the first display line, which can make the text layout untidy and difficult to read. The [emph Ntext] binding tag provides facilities so that a text widget in [arg -wrap] [arg word] mode will automatically indent display lines (other than the first) to match the initial whitespace of the first display line. [para] This indentation is available to text widgets only in [arg -wrap] [arg word] mode. [section COMMANDS] [list_begin definitions] [call [cmd ::ntext::new_textCopy] [arg pathName]] Replacement for ::tk_textCopy. [call [cmd ::ntext::new_textCut] [arg pathName]] Replacement for ::tk_textCut that also maintains [emph Ntext] indentation (see [term ntextIndent]). [call [cmd ::ntext::new_textPaste] [arg pathName]] Replacement for ::tk_textPaste that also maintains [emph Ntext] indentation (see [term ntextIndent]). [list_end] [section {CONFIGURATION OPTIONS}] The behavior of [emph Ntext] may be configured application-wide by setting the values of a number of namespace variables: [para] [var ::ntext::classicWrap] |
︙ | ︙ | |||
101 102 103 104 105 106 107 108 109 110 111 112 113 114 | [item] A call of the form [fun ::ntext::wrapIndent] [arg textWidget] will always suffice, but if changes are needed only to certain lines, it is more efficient to specify those lines with the optional arguments [opt index1], [opt index2]. [item] If the widget is in [arg -word] [arg wrap] mode, and if [var ::ntext::classicWrap] is set to [const 0], [fun ::ntext::wrapIndent] will apply indentation to the logical lines within the range specified by the function's arguments. [item] In other cases, i.e. if the widget is in [arg -word] [arg char] or [arg -word] [arg none] mode, or if [var ::ntext::classicWrap] is set to [const 1], [fun ::ntext::wrapIndent] will remove the indentation of the logical lines within the range specified by the function's arguments. [list_end] [section EXAMPLES] To switch on [emph Ntext] 's indentation and use it in widget .t: [example { package require ntext set ::ntext::classicWrap 0 | > > > > | 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 | [item] A call of the form [fun ::ntext::wrapIndent] [arg textWidget] will always suffice, but if changes are needed only to certain lines, it is more efficient to specify those lines with the optional arguments [opt index1], [opt index2]. [item] If the widget is in [arg -word] [arg wrap] mode, and if [var ::ntext::classicWrap] is set to [const 0], [fun ::ntext::wrapIndent] will apply indentation to the logical lines within the range specified by the function's arguments. [item] In other cases, i.e. if the widget is in [arg -word] [arg char] or [arg -word] [arg none] mode, or if [var ::ntext::classicWrap] is set to [const 1], [fun ::ntext::wrapIndent] will remove the indentation of the logical lines within the range specified by the function's arguments. [list_end] [section BUGS] This version of [package ntext] is intended to be compatible with all releases of [package Tk] 8.5 and 8.6, and with the branches [emph core-8-5-branch], [emph core-8-6-branch], and [emph trunk] in the source code repository for [package Tk]. Any incompatibility with any of these versions, for any [package Tk] windowing system, should be reported as a bug. Please report such in the category [emph ntext] of the [uri http://core.tcl.tk/tklib/reportlist {Tklib Trackers}]. [section EXAMPLES] To switch on [emph Ntext] 's indentation and use it in widget .t: [example { package require ntext set ::ntext::classicWrap 0 |
︙ | ︙ | |||
140 141 142 143 144 145 146 | To switch to [arg -wrap] [arg char] mode: [example { .t configure -wrap char ::ntext::wrapIndent .t }] | | | > > > > > | 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 | To switch to [arg -wrap] [arg char] mode: [example { .t configure -wrap char ::ntext::wrapIndent .t }] [see_also ntext] [see_also text bindtags regexp re_syntax] [keywords text bindtags regexp re_syntax] [manpage_end] |
Changes to modules/ntext/ntextWordBreak.man.
1 | [comment {-*- tcl -*- ntextWordBreak manpage}] | | < < < < < < < < < | | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 | [comment {-*- tcl -*- ntextWordBreak manpage}] [manpage_begin ntextWordBreak n 1.0] [moddesc {ntext Word Boundary Detection for the Text Widget}] [titledesc {ntext Word Boundary Detection for the Text Widget}] [require Tcl 8.5] [require Tk 8.5] [require ntext [opt 1.0]] [description] The [package ntext] package provides a binding tag named [emph Ntext] for use by text widgets in place of the default [emph Text] binding tag. [comment {use emph instead of term, because term creates a hyperlink, and ntext, Ntext and Text occur in almost every sentence: the page would be covered with the same hyperlinks many times}] [para] |
︙ | ︙ | |||
35 36 37 38 39 40 41 42 43 44 45 46 47 48 | [const 0] - (default value) selects [emph Ntext] behaviour, i.e. platform-independent, two classes of word characters and one class of non-word characters. [item] [const 1] - selects classic [emph Text] behaviour, i.e. platform-dependent, one class of word characters and one class of non-word characters [item] After changing this value, [emph Ntext] 's regexp matching patterns should be recalculated. See [sectref FUNCTIONS] for details and advanced configuration options. [list_end] [para] [section {Advanced Use}] [comment {no subsection in my dtp kit}] [section {Variables (Advanced Use)}] [var ::ntext::tcl_match_wordBreakAfter] [para] [var ::ntext::tcl_match_wordBreakBefore] | > | 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 | [const 0] - (default value) selects [emph Ntext] behaviour, i.e. platform-independent, two classes of word characters and one class of non-word characters. [item] [const 1] - selects classic [emph Text] behaviour, i.e. platform-dependent, one class of word characters and one class of non-word characters [item] After changing this value, [emph Ntext] 's regexp matching patterns should be recalculated. See [sectref FUNCTIONS] for details and advanced configuration options. [list_end] [para] [section {Advanced Use}] [comment {no subsection in my dtp kit}] [section {Variables (Advanced Use)}] [var ::ntext::tcl_match_wordBreakAfter] [para] [var ::ntext::tcl_match_wordBreakBefore] |
︙ | ︙ | |||
104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 | [para] Traditionally Tcl has defined only one word class and one non-word class: on Windows, the non-word class is whitespace, and so alphanumerics and punctuation belong to the same class. On other platforms, punctuation is bundled with whitespace as "non-word" characters. In either case, the navigation and selection of text are unnecessarily coarse-grained, and sometimes give unhelpful results. [para] The use of three classes of characters might make selection too fine-grained; but in this case, holding down the [emph Shift] key and double-clicking another word is an excellent way to select a longer range of text (a useful binding that Tcl/Tk has long provided but which is missing in other systems). [para] As well as its defaults, [emph Ntext] permits the developer to define their own classes of characters, or to revert to the classic [emph Text] definitions, or to specify their own regexp matching patterns. [section EXAMPLE] To use [emph Ntext] with Tcl/Tk's usual word-boundary detection rules: [example { package require ntext text .t bindtags .t {.t Ntext . all} set ::ntext::classicWordBreak 1 ::ntext::initializeMatchPatterns }] See bindtags for more information. [para] To define a different set of word-boundary detection rules: [example { package require ntext text .t bindtags .t {.t Ntext . all} | > > > > | | | > > | 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 | [para] Traditionally Tcl has defined only one word class and one non-word class: on Windows, the non-word class is whitespace, and so alphanumerics and punctuation belong to the same class. On other platforms, punctuation is bundled with whitespace as "non-word" characters. In either case, the navigation and selection of text are unnecessarily coarse-grained, and sometimes give unhelpful results. [para] The use of three classes of characters might make selection too fine-grained; but in this case, holding down the [emph Shift] key and double-clicking another word is an excellent way to select a longer range of text (a useful binding that Tcl/Tk has long provided but which is missing in other systems). [para] As well as its defaults, [emph Ntext] permits the developer to define their own classes of characters, or to revert to the classic [emph Text] definitions, or to specify their own regexp matching patterns. [section BUGS] This version of [package ntext] is intended to be compatible with all releases of [package Tk] 8.5 and 8.6, and with the branches [emph core-8-5-branch], [emph core-8-6-branch], and [emph trunk] in the source code repository for [package Tk]. Any incompatibility with any of these versions, for any [package Tk] windowing system, should be reported as a bug. Please report such in the category [emph ntext] of the [uri http://core.tcl.tk/tklib/reportlist {Tklib Trackers}]. [section EXAMPLE] To use [emph Ntext] with Tcl/Tk's usual word-boundary detection rules: [example { package require ntext text .t bindtags .t {.t Ntext . all} set ::ntext::classicWordBreak 1 ::ntext::initializeMatchPatterns }] See bindtags for more information. [para] To define a different set of word-boundary detection rules: [example { package require ntext text .t bindtags .t {.t Ntext . all} ::ntext::createMatchPatterns \ {[[:space:][:cntrl:]]} {[[:punct:]]} {[^[:punct:][:space:][:cntrl:]]} }] See regexp, re_syntax for more information. [see_also ntext] [see_also text bindtags regexp re_syntax] [keywords text bindtags regexp re_syntax] [manpage_end] |
Changes to modules/ntext/pkgIndex.tcl.
|
| | | 1 | package ifneeded ntext 1.0b1 [list source [file join $dir ntext.tcl]] |