| Ticket UUID: | b461c703993375d4a0498b11b71db814c91ad375 | |||
| Title: | text widget handling of the empty space left from line wrap | |||
| Type: | Bug | Version: | 8.6.11, revised_text | |
| Submitter: | anonymous | Created on: | 2021-04-19 23:55:35 | |
| Subsystem: | 75. wish | Assigned To: | fvogel | |
| Priority: | 5 Medium | Severity: | Important | |
| Status: | Closed | Last Modified: | 2022-12-26 10:05:57 | |
| Resolution: | Fixed | Closed By: | fvogel | |
| Closed on: | 2022-12-26 10:05:57 | |||
| Description: |
The user's intention is to place the insert mark at the end of a wrapped line.
Mousepad, and they all place the insert mark at the end of the last character of the same line, not at the start of the next line. To replicate this behavior: package require Tk
pack [text .t -width 10 -height 3 -font {-size 72} -wrap word] -fill both -expand 1
.t insert end "123456 1234567"
bind .t <ButtonRelease-1> {puts bbox\t[%W bbox [%W index insert]]}
Click in the first line, at the far right side of that line's empty space. The insert mark goes to the start of the next line. Apparently the center-line principle (see this ticket too) is being applied to the empty space now representing the space character where the wrapping occurs, only the choice forced here is clearly not "the closest edge of the character underneath the mouse cursor". More complications from applying the centerline principle to the empty space left from wrapping:
| |||
| User Comments: |
fvogel added on 2022-12-26 10:05:57:
I have merged the bugfix branch bug-b461c70399 into the revised_text branch (only). This changes the behavior when, in a -wrap !none mode, the user clicks in the right half of the blank area at the end of a display line (previously: the cursor got positioned at the beginning of the next display line, now it will be at the end of the current display line which is more in line with what current other editors do). Moreover, an attempt to better document dlineinfo is implemented. After 18 months with no activity I'm closing this ticket now. If someone comes up with better documentation we can always make further commits. Thanks for the discussion! anonymous added on 2021-06-06 15:18:11: Hi fvogel. I'm sorry for my late response. 1. The issue of placing the insert mark in the space left from a wrapped line seems to be solved. 2. The concept of a variable space and the reason why dlineinfo and bbox return different values for the space left by a wrapped line is, in my view, still not explained adequately or solved. But I feel I've been enough of a nuisance on this matter and I'd better stop here. Thank you for looking into this report and for all the work you do for the text widget. dzach fvogel added on 2021-05-15 09:07:21: Revisiting this issue, I think we can change the behavior at clicking on a wrapped line end in the revised_text easily, but less easily in the legacy widget. I did this in [515c759bf5], which also adds a piece of documentation about what dlineinfo returns when -wrap is different from 'none'. Would you be OK with this? If so, I would backport the man page part of the above commit to the legacy widget. anonymous added on 2021-05-03 21:05:04:
Hi fvogel > First thing, the space at the end of line is a single space, it's not a > "regular" space followed by a variable width space that is present of not > depending on the justification setting. There is a single space character (from > the chars inserted in the widget), and it may have variable width depending on > justification, wrapping, location on the line, fixed/not fixed font used, and > whatnot (but not -rmargin, I have checked). When you run the code I posted in the previous post, and vary the width of the window, you will see dlineinfo returning the visible space of the line, including the portion of the fixed space that is visible. As soon as the width extends beyond the fixed space, the behaviors of bbox and dlineinfo deviate; bbox width extends to include the flexible space while dlineinfo does not. This is what I interpreted as the existence of both a fixed and a variable width space at the same time. > Please re-read the man page for bbox, I believe it's clear there. It is clear, provided there exists a notion of a 'flexible space character' and its behavior, which does not. > It is true that when wrapping it does not return the full width of the window but my opinion > is that this is a feature. In that case, there seems to be a need to refine the definition of a display line to include the fixed space and exclude the flexible space left when the line breaks. > [...] It gives a different information than the sum of the bboxes of all chars in that display > line, and it's the only way to get that information. One can get the same information from a dlineinfo which would return a full line's width from left to right, meaning the sum of all character bboxes with the same y coordinate, and then subtract the width of the flexible space returned by its bbox. In this case both bbox and dlineinfo would include a flexible and/or a non flexible space at the end of the line, whether it wraps or not. > Agreed, that could be clarified in the man page, which only says what's happening when > wrapping is "none" but not when it's something else. But I seem to be failing to describe it properly, each time. :-) fvogel added on 2021-05-02 08:18:23: Well, bbox and dline subcommands are two different beasts. First thing, the space at the end of line is a single space, it's not a "regular" space followed by a variable width space that is present of not depending on the justification setting. There is a single space character (from the chars inserted in the widget), and it may have variable width depending on justification, wrapping, location on the line, fixed/not fixed font used, and whatnot (but not -rmargin, I have checked). Second, bbox always measures the area occupied by a character. When you request the bbox of the space character you get its x, y, width and heigth according to all the above mentioned parameters. You get its dimensions as displayed on the screen. Please re-read the man page for bbox, I believe it's clear there. Third, dlineinfo deals with display lines. It measures position and size of the display line containing the index it is been given. It is true that when wrapping it does not return the full width of the window but my opinion is that this is a feature. It gives a different information than the sum of the bboxes of all chars in that display line, and it's the only way to get that information. Agreed, that could be clarified in the man page, which only says what's happening when wrapping is "none" but not when it's something else. anonymous added on 2021-04-25 01:25:32:
I see your point with the patch. However that is true with every long standing buggy behavior, isn't it? But then again, maybe others don't see it as buggy behavior, because they've been accustomed to it. Kind of a chicken and egg situation. Indeed, my definition was not accurate. The thing gets even more involved the more one digs into it. The reason I propose to document the existence of a variable-width space is because it has implications on the measurements returned by dlineinfo and bbox:
package require Tk
pack [text .t -width 6 -height 2 -font {-family monospace -size 72} -wrap word
] -fill both -expand 1
bind .t <Configure> {puts "bbox\t[lindex [.t bbox 1.6] 2]\tdline\t[lindex [.t dline 1.6] 2]"}
.t insert end "012345 67890"
If the widget is expanded horizontally, bbox increases continuously while dlineinfo stops
increasing after the width exceeds that of the regular space.
It seems to me that if both dlineinfo and bbox measured the regular space char,
and the regular space char were the one that got selected upon a selection, then
whether a variable-width space existed or not would have no practical implication
to the user.
As it stands now, and since the description of the variable-width space is not
offering any practical help to the user, then maybe the discrepancies in the
measurements returned by dlineinfo and bbox could be described in the
KNOWN BUGS section?
dzach
fvogel added on 2021-04-24 19:54:40: Thanks for your proposal. Two remarks:
anonymous added on 2021-04-21 15:38:13:
Here is a suggestion for a change in the text of the manual, which includes
anonymous added on 2021-04-21 11:59:31: fvogel, I apologize, I think I misread your reply. I just applied the patch you provided, and it solves points 1 and 2 of my listing. Then, the only remaining issue is documenting the "flexible space" behavior in the text widget man page. Thank you for the patch. anonymous added on 2021-04-21 11:04:31: > what behavior would you like to see when double clicking? It's unclear to me. To answer the question, I would look into what a user reasonably expects when clicking in the empty space left by the line wrap, which extends the same line as the text before the wrap. Approaching it in such a way, I believe that: fvogel added on 2021-04-21 09:06:35: Not sure how to deal with this report, especially since you report yourself that different editors behave differently. There seem to be no standard, therefore I'm not really seeing this report as a bug, except perhaps regarding the location of the insert mark on click at the end of the display line. Also, apart from the insert index at the end of the clicked line, what behavior would you like to see when double clicking? It's unclear to me. The behavior you describe for the Tk text widget is mostly implemented (in Tcl) in the file library/text.tcl. See For instance, here is the start of a patch (against current core-8-6-branch) that might do part of what you want:
Index: library/text.tcl
==================================================================
--- library/text.tcl
+++ library/text.tcl
@@ -536,11 +536,12 @@
set pos [$w index @$x,$y]
set bbox [$w bbox $pos]
if {$bbox eq ""} {
return $pos
}
- if {($x - [lindex $bbox 0]) < ([lindex $bbox 2]/2)} {
+ if {(($x - [lindex $bbox 0]) < ([lindex $bbox 2]/2))
+ || ([$w compare $pos == "$pos display lineend"] == 1)} {
return $pos
}
$w index "$pos + 1 char"
}
| |||
Home
Timeline
Branches
Tags
Forum
Tickets
Download
Wiki