[Idle-dev] Shift+HOME selects wrong text

Weeble clockworksaint at gmail.com
Thu Jan 22 22:45:12 CET 2009

Okay, I got home and it works fine here, but that appears to be
because Python is using Tk 8.4 on my install of Ubuntu. Looking at
text.tcl, it seems that 8.5 has changed the name of the anchor mark to
be private and unique to each widget:

# 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$w'.

I think the following method should fix it, but I haven't had a chance
to try it on Tk 8.5 yet. It at least seems just as good as the other
method on Tk 8.4:

In EditorWindow.py, replace this:
        if (event.state&1) == 0:
            # shift not pressed
            self.text.tag_remove("sel", "1.0", "end")
            if not self.text.index("sel.first"):

            first = self.text.index(dest)
            last = self.text.index("anchor")

            if self.text.compare(first,">",last):
                first,last = last,first

            self.text.tag_remove("sel", "1.0", "end")
            self.text.tag_add("sel", first, last)

With this:
        if (event.state&1) == 0:
            # shift not pressed
            self.text.tag_remove("sel", "1.0", "end")
            self.text.tk.call('tk::TextKeySelect', self.text._w, dest)

This retains the behaviour where Home toggles between the first
non-whitespace character and the start of the line. I'll try it out on
Tk 8.5 at work tomorrow.

On Thu, Jan 22, 2009 at 1:38 PM, Weeble <clockworksaint at gmail.com> wrote:
> When I press shift and home, IDLE raises an exception and/or selects
> the wrong text. For example, enter some text, then hold down shift and
> use the cursor to select some of it and position the cursor in the
> middle of a line. Then press shift+home. The problem seems to occur in
> EditorWindow.py in home_callback. When it does this:
>    first = self.text.index(dest)
>    last = self.text.index("anchor")
> There is no mark called "anchor". There appears instead to be one
> called "tk::anchor.44486744.44486984.text", although I would guess
> that the numbers are not fixed. If you press shift+home with no
> selection, it will create a mark called "anchor", but all that means
> is that the selection behaviour gets even stranger, since the home-key
> handling is using "anchor" but the standard cursor actions are using
> the weirdly named one.
> I'm using: Python 2.6, Tk 8.5, IDLE 2.6
> I'm running the 32-bit version on 64-bit Vista. I installed it from an
> installer on the Python website.
> When I get home I can test it on Ubuntu and see if I see the same thing.
> I think perhaps this might have been introduced with the fix for this
> bug: http://bugs.python.org/issue3851

More information about the IDLE-dev mailing list