in reply to Re: Indices and inserts in Tk::Text
in thread Indices and inserts in Tk::Text
Lets call it an intentional bug then. Or at least it is a huge inconsistency. If you change the sub in anna_blacks program to:
sub replace { my ($text,$start_index,$end_index) = @_; my $old_data = $text->get($start_index,$end_index); print "<$old_data>\n"; $old_data =~ s/cdefg/12345/g; $text->delete($start_index,$end_index); $text->insert($start_index,$old_data); my $old_data = $text->get('3.0',$end_index); print "<$old_data>\n"; return; }
... you can see that the insert started one char too early.
It could be argued that you should not insert into lines that don't exist (i.e. after the delete of all lines starting from line 16 the location 16.0 doesn't really exist anymore). But then your 'end-1c' solution would be illegal as well, and it only works because the additional \n is confused with the \n of not-existant line 16.
If TK inserts spurious characters it is its job to make sure that those characters don't get in the way of the programmer.
PS: Why double quotes? They don't do anything different than a single quote here.
UPDATE: changed 2 sentences
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^3: Indices and inserts in Tk::Text
by zentara (Cardinal) on Nov 28, 2008 at 13:47 UTC |