| Ticket UUID: | 1771594 | |||
| Title: | icursor @x,y fails for non-default scrollregions | |||
| Type: | Bug | Version: | None | |
| Submitter: | nobody | Created on: | 2007-08-10 12:56:53 | |
| Subsystem: | 05. Canvas Items | Assigned To: | fvogel | |
| Priority: | 5 Medium | Severity: | Minor | |
| Status: | Closed | Last Modified: | 2020-01-18 11:28:44 | |
| Resolution: | Fixed | Closed By: | fvogel | |
| Closed on: | 2020-01-18 11:28:44 | |||
| Description: |
The normal method of locating where a button click happens on a canvas TEXT item would be:
set cx [.c canvasx $x]
set cy [.c canvasy $y]
set id [.c find closest $cx $cy]
.c focus $id
.c icursor $id @$cx,$cy
If however the scrollregion is configured as:
.c configure -scrollregion {0 -100 600 800}
Then to position the ibeam in the text widget would require:
.c icursor $id @$cx,[expr {$cy+100}]
That is: If the x1 or y1 coordinate is negative the indexing is wrong by that ammount.
This bug may affect all canvas items as each item type has its own index procedure.
Verified on tk 8.4 and 8.5a6
| |||
| User Comments: |
fvogel added on 2020-01-18 11:28:44:
Merged into core-8-6-branch and trunk. fvogel added on 2019-12-23 14:08:03: Fixed by [89db3604d0]. I have also added a non-regression test canvText-14.7 in [88538c9a44], which failed before the fix and passes after the fix. This problem was in the code for a very long time, possibly since day 1. It was located in the indexProc (GetTextIndex) of the canvas text item. I have checked that the other items having a non-NULL indexProc correctly do not use the scrollregion. The indexProc has nothing to do with the scrollregion. The scrollregion is only used (and useful) in tkCanvas.c. fvogel added on 2019-12-23 13:53:35: Reproduced with core-8-6-branch. Note that the problem is not limited to negative scrollregions. As long as the upper left corner of the scrollregion is not(0,0) the problem is present --> I have changed the ticket title accordingly. Demo script showing the problem:
package require Tk
pack [canvas .c]
.c create text 50 80 -text Hello -anchor nw -font "Arial 30"
proc clicked {x y} {
set cx [.c canvasx $x]
set cy [.c canvasy $y]
set id [.c find closest $cx $cy]
focus -force .c
.c focus $id
.c icursor $id @$cx,$cy
}
.c bind 1 <1> {clicked %x %y}
# test 1
# now click in the test somewhere and watch the cursor being set
# at the place the user expects
# test 2
.c configure -scrollregion {0 -100 600 800}
# now click in the test somewhere and watch the cursor being set at the
# place the user DOESN'T expect (it's always at the start of the text)
# test 3
.c configure -scrollregion {50 50 600 800}
# now click in the test somewhere and watch the cursor being set at the
# place the user DOESN'T expect (it's always at the end of the text)
| |||
Home
Timeline
Branches
Tags
Forum
Tickets
Download
Wiki