On Fri, Apr 12, 2013 at 11:06 AM, Terry Brown <[email protected]>wrote:

> 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")
>
> Thank you, Terry!


>  You're just inserting text in the GUI widget, not the Leo node.
>
I got it.
But I wonder, insert text in body widget, should insert text in the Leo
node with intuition.

>
> 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)
>
AttributeError: 'leoQTextEditWidget' object has no attribute 'setText'


my version is:
Leo 4.11 devel, build 5664, 2013-04-09 02:53:54 -0500
Python 2.7.3, qt version 4.8.3

But fine, I just comment it ;-)
thanks again!


>     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.
>
>
>


-- 
--
Sincerely,

HaveF

-- 
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.


Reply via email to