I am trying to count the text selection. I want to count words and lines.
We have been through words. Now let's see lines.
I have this code:
set ::selectionWC 0
set ::selectionlinecount 0
set selectionindices [$::text tag ranges sel]
if {[llength $selectionindices] > 0} {
set ::selection "[$::text get {*}$selectionindices]"
set ::selectionWC [p.wc $::selection]
set ::selectionlinecount [$::text count -lines {*}$selectionindices] }
It doesn't really work. Whether I select nothing, one word, many words
or the entire line, the line count is 0.
If I select two lines, then the line count is 1. That is evidently wrong.
So I added this line to the code:
...
Wait. Should I be doing that?
Pressing Shift+Down again has no effect, but pressing Shift+Right does increase the line count to 6.
I can't agree with that. There is no line 6. The widget only holds
five lines.
The only debugging I did was to print the selection range indices and
after a little thinking I believe that maybe I could do a better job
myself than $::text count -lines by taking the indices and doing some
math with it and maybe other tricks.
But I wonder if that would be trying to invent an unnecessary wheel.
What do you think?
Sysop: | Keyop |
---|---|
Location: | Huddersfield, West Yorkshire, UK |
Users: | 497 |
Nodes: | 16 (2 / 14) |
Uptime: | 68:34:46 |
Calls: | 9,766 |
Calls today: | 7 |
Files: | 13,747 |
Messages: | 6,186,073 |