dcorking / google-wave-resources

Automatically exported from code.google.com/p/google-wave-resources
0 stars 0 forks source link

Bug: inserting at end of blip causes crash should append #744

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
blip.append(element.Button('bob', 'fred')) works fine
blip.at(len(blip)).insert(element.Button('bob', 'fred')) causes crash:
raise IndexError('Position outside the document')

but the two actions should do the same thing
python v2 api

Original issue reported on code.google.com by duncan.hawthorne on 24 Apr 2010 at 11:29

GoogleCodeExporter commented 9 years ago
That should be:

  blip.at(len(blip)-1).insert(element.Button('bob', 'fred')) 

because indices into the blip are 0-based.

Original comment by joe.gregorio@gmail.com on 7 May 2010 at 12:41

GoogleCodeExporter commented 9 years ago
blip.at(len(blip)) is the position on the right side of the last character, so 
should do append, which it doesn't
blip.at(len(blip)-1) is the left side of the last character, so should insert 
just before the last character, which it does

Please consider the following code and the running of that code:
https://wave.google.com/wave/#minimized:search,restored:wave:googlewave.com!w%25
2B7U3OtCPyH.2,restored:wave:googlewave.com!w%252B7U
3OtCPyL.1

The code is
blip.append("test")
blip.at(len(blip)-1).insert('foo')
blip.append("\ntest")
blip.at(len(blip)).insert("bar") 

The result is 
tesfoot
test

with no "bar" appearing because of a crash.
The expected result would be
tesfoot
testbar

My use case is that I want to add something after finding a piece of text in a 
wave. I don't want to have to check whether the 
thing that has been entered is at the last position in the wave and then switch 
to appending instead. I think I haven't screwed up 
indexes.

Original comment by duncan.hawthorne on 7 May 2010 at 10:15

GoogleCodeExporter commented 9 years ago

Original comment by pamela.fox on 7 May 2010 at 11:14

GoogleCodeExporter commented 9 years ago
OK, that's because insert means insert before the position. There is an 
insert_after 
operation which does what you want. So revising the code, it
should be:

 blip.at(len(blip)-1).insert_after(element.Button('bob', 'fred')) 

Does that solve the problem for you?

Original comment by joe.gregorio@gmail.com on 13 May 2010 at 12:45

GoogleCodeExporter commented 9 years ago
Closing for now, please reopen if that doesn't work for you.

Original comment by joe.gregorio@gmail.com on 27 May 2010 at 12:28