On Fri, 12 Apr 2013 10:23:57 +0800
HaveF <[email protected]> wrote:
> hi,
>
> I want to select text in body, make a childnode with that text,
> and insert the section reference(like <<xxx>>) before the select
> text, but the insert text would disappear when I redraw, here is
> the code:
>
> # insert section(selecting text as section name)
> w = c.frame.body.bodyCtrl # Leo's body pane.
>
> i,j = w.getSelectionRange(sort=True)
> s = w.getSelectedText() # Return the selected text, if any.
> sectionName = g.angleBrackets(s)
>
> w.insert(i, sectionName+"\n")
You're just inserting text in the GUI widget, not the Leo node.
You need something like
all = [p.b[:i], sectionName+"\n", p.b[i:]]
p.b = ''.join(all)
if you were going to let the user edit the code you might also want
w.setText(p.b)
w.setInsertPoint(i+len(sectionName+"\n"))
to place the cursor after the inserted text, but you move on to another
node I think, so that's not needed.
Cheers -Terry
> child = p.insertAsLastChild()
> child.initHeadString(sectionName)
>
> c.redraw()
>
--
You received this message because you are subscribed to the Google Groups
"leo-editor" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/leo-editor?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.