[Dextrose] [Sugar-devel] [PATCH sugar-toolkit] Cursor moves to beginning while trying to edit activity instance name #2608
Bernie Innocenti
bernie at codewiz.org
Tue Feb 15 15:19:57 EST 2011
On Tue, 2011-02-15 at 21:00 +0100, Sascha Silbe wrote:
> Excerpts from Aleksey Lim's message of Mon Feb 14 23:23:25 +0100 2011:
>
> > def __jobject_updated_cb(self, jobject):
> > + prev_pos = self.entry.props.cursor_position
> > self.entry.set_text(jobject['title'])
> > + self.entry.set_position(prev_pos)
>
> The GTK documentation doesn't say anything about what the cursor position
> will be after a set_text() call, so we need to take care of saving and
> restoring the cursor position (i.e. your patch does the right thing).
>
> But the documentation for set_position() says the position must not
> exceed the number of characters currently in the widget, so we need some
> bounds checking here (the title might have been shortened).
The above patch isn't sufficient in this race-condition between the user
typing and the metadata update: even if we reset the cursor position to
the right place, the text that we set back into the widget is likely to
miss one or two keystrokes from the user.
We must absolutely avoid triggering a save while the user could still be
typing in the widget, which is easily achieved by *NOT* having an
arbitrary timeout of 2 seconds and instead hooking to the
focus-out-event.
The problem with the focus-out-event is that we don't get one when the
user clicks directly on the Stop button after editing the name. That
case is tricky because the Stop button does not have an easy way to find
the name widget even though it's in the same toolbar.
Someone (tomeu?) pointed out that, normally, gtk sends a focus-out-event
in this case. There was even a small test case demonstrating it. For
some reason, it doesn't work in Sugar. Fixing this bug would let us
remove all these half-baked workarounds.
--
// Bernie Innocenti - http://codewiz.org/
\X/ Sugar Labs - http://sugarlabs.org/
More information about the Dextrose
mailing list