Tk Source Code

View Ticket
Login
Ticket UUID: 1669632
Title: text widget: autoseparator placement, <Control-1> cleanup
Type: Bug Version: obsolete: 8.5a5
Submitter: kjnash Created on: 2007-02-27 02:58:31
Subsystem: 18. [text] Assigned To: fvogel
Priority: 7 High Severity: Minor
Status: Closed Last Modified: 2015-10-27 22:20:11
Resolution: Fixed Closed By: fvogel
    Closed on: 2015-10-27 22:20:11
Description:
LIST OF BUGS/FEATURES FIXED BY THE PATCH

A patch to lib/tk8.5/text.tcl is supplied, and each fix in the patch file is commented.  The bugs/features are labeled here by the binding, followed by a short description of how to demonstrate the bug/feature.

(i), (iv) and (vii) are bugfixes to autoseparator placement
(ii), (iii) fix apparent bugs where the real problem is a shaky hand; since they don't break any intended behavior they could be considered improvements
(v), (vi) make <<Clear>> and <<Cut>> atomic operations on the Undo stack.

(i) <Control-1>
Insert text at position 'A'; use <Control-1> to click at 'B'; insert text at 'B'; <<Undo>>
The insertions at both 'A' and 'B' are removed together.
The patch inserts an autoseparator.

General rule (obeyed elsewhere in text.tcl): an operation that moves the insert mark without making it one end of the selection must insert an autoseparator.

(ii) <Double-Control-1>
The patch prevents <Control-1> from becoming <Double-Button-1> if the user accidentally double clicks.

(iii) <Control-B1-Motion>
The patch prevents <Control-1> from becoming <B1-Motion> if the user accidentally makes a slight movement of the mouse.

(iv) <Control-backslash>
Insert text at position 'A'; use <Shift-Right> to create a selection to position 'B'; use <Control-backslash> to clear the selection, leaving the insert mark at 'B'; insert text at 'B'; <<Undo>>
The insertions at both 'A' and 'B' are removed together.
The patch inserts an autoseparator.

General rule (obeyed elsewhere in text.tcl): an operation that clears the selection must insert an autoseparator, because the selection operation may have moved the insert mark.

(v) <<Clear>>
<Delete> a character at position 'A'; use <Shift-Right> to create a selection to position 'B'; use <<Clear>> to delete the selection; <Delete> another character; <<Undo>>
All three deletions are undone.
It might be preferable to make <<Clear>> atomic.  The patch does this.

(For testing on non-Mac systems, use
    event add <<Clear>> <Key-F6>
to map this binding to the F6 key)

(vi) <<Cut>> (proc ::tk_textCut)
Similar to <<Clear>> above: the patch makes <<Cut>> atomic.

(vii) <<Undo>>
(a) create a widget with -undo 1, and enter some text
(b) click somewhere in the text.  Delete a character; type a few characters, without deleting anything or navigating away (i.e. only insert text).
(c) click somewhere else in the text. Insert another character there.

At this point the top operation in the Undo stack is the single inserted character, the operation before that is the group of inserted characters.

(d) <<Undo>> - correctly undoes the last operation, but also removes the separator from the top of the Undo stack
(e) type a character
(f) <<Undo>> - undoes the character (e) _and_ the previous item on the Undo stack.
User Comments: fvogel added on 2015-10-27 22:20:11:

Point 2. was known in the past, despite closed without fix: see [222027].

Regarding the present ticket, the original problems it raises have been addressed. The remaining issue is that one of the tests newly introduced to test the fixes, specificly text-25.20, does not succeed on at least one platform (mine) because event generate .t <Control-backslash> does not work as expected. This remaining problem being followed in [222027] I close the present ticket.


fvogel added on 2015-10-27 21:19:28:

Point 1 is now [297442da29]

Point 2: no idea, help welcome.


fvogel added on 2015-10-26 22:09:28:
Simple standalone test case:

    pack [text .t -undo 1]
    .t insert end "This is an example text"
    .t edit reset
    .t mark set insert 1.5
    .t insert 1.5 HELLO
    .t tag add sel 1.10 1.12
    update
    focus -force .t
    event generate .t <Control-backslash>
    .t insert insert " WORLD "
    .t edit undo
    .t get 1.5 1.10    ; # shall return "HELLO"


Analysis:

    event generate .t <Control-backslash>

actually triggers the virtual event <<Undo>> (checked with puts there), but not the <Control-backslash> binding defined in text.tcl.

This seems to be because on my (French) keyboard the backslash key and the underscore key are the same physical key, and 
    event info <<Undo>>
returns:
    <Control-Key-z> <Control-Lock-Key-Z> <Control-Key-underscore>

Now there are two things I don't understand:

1. 'set tk_strictMotif' returns false, therefore according to the text widget documentation (item 32 in section BINDINGS), <Control-Key-underscore> should NOT be associated with the virtual event <<Undo>>. But the variable trace mechanism in tk.tcl does the opposite in proc ::tk::EventMotifBindings. Documentation bug?

2. why does <Control-Key-underscore> trigger when
    event generate .t <Control-backslash>
is requested?

fvogel added on 2015-10-19 20:01:24:

Problem is only in core-8-5-branch, not in trunk where <Control-backslash> has been replaced by <<SelectNone>> (bug [3555644]).


fvogel added on 2015-10-19 19:52:52:
The reason for the failure is that the event is not received by the text widget:

    event generate .top.t <Control-backslash>

does apparently nothing, contrary to Windows for which it delivers the event to the text widget.

If I hit the key combination by hand on my keyboard, the event is correctly fired however.

I've checked this on two different Linuxes (Debian 6.0 and OpenSuse 12.2).

I'm puzzled. Is anyone able to advise why the widget does not receive the event?

fvogel added on 2015-10-18 21:28:27:
Re-opening since one of the tests (text-25.20) added for this ticket fails on Linux Debian 6.0:


==== text-25.20 patch 1669632 (iv) - undo after <Control-backslash> FAILED
==== Contents of test case:

    toplevel .top
    pack [text .top.t -undo 1]
    .top.t insert end "This is an example text"
    .top.t edit reset
    .top.t mark set insert 1.5
    .top.t insert 1.5 HELLO
    .top.t tag add sel 1.10 1.12
    update
    focus -force .top.t
    event generate .top.t <Control-backslash>
    .top.t insert insert " WORLD "
    .top.t edit undo
    .top.t get 1.5 1.10

---- Result was:
is an
---- Result should have been (exact matching):
HELLO
==== text-25.20 FAILED

fvogel added on 2015-10-09 19:08:41:
Merged to core-8-5-branch and trunk. Closing.

fvogel added on 2015-10-04 14:10:55:
All cases now pushed in branch bug-1669632fff. All cases look relevant to me.

Peer review welcome, I will merge to core branches in a few days unless someone objects.

fvogel added on 2015-10-03 20:02:31:
Fixes for cases (i) and (iv) pushed in branch bug-1669632fff

kjnash added on 2007-02-27 09:58:32:

File Added - 217932: text.tcl-patch

Attachments: