On Wed, 17 Apr 2013 16:53:10 -0700 (PDT)
SegundoBob <[email protected]> wrote:

> I'm sorry no one has suggested a better way to make the changes
> permanent.  How does Leo-Editor notice that typing has inserted a few
> more characters?  Couldn't the same mechanism be used here?

I don't think Leo constantly updates p.b from w.getAllText(), but just
does it when focus is lost - not sure about that though.

Here's a thought for a higher level interface.

c.get_edit_state() gives you an instance of a LeoEditState class with
these attributes:

  text attributes

  les.all_text
  les.text_before_select
  les.text_after_select
  les.selected_text
  les.text_before_cursor
  les.text_after_cursor

  integer attributes

  les.selection_start
  les.selection_end
  les.cursor_index

then you can either do

c.set_edit_state(les)

which sets the editor text and p.b to les.all_text and sets up
selection and insert position appropriately from the integers,

or c.set_edit_state(les, mode='selection')
or c.set_edit_state(les, mode='cursor')

which assembles things based on the selection or cursor text attributes.

Thoughts?  So long since I wrote any emacs text manipulation stuff I
can't remember the idiom it used.

Cheers -Terry



> On 04/17/2013 12:29 PM, Terry Brown wrote:> I think that's the way,
> see also:
> >
> > https://groups.google.com/forum/?fromgroups=#!searchin/leo-editor/insert$20text$20will$20disappear$20after$20insert$20children$20node$20and$20redraw/leo-editor/0haTWrUlNVg/lFU1JkMHrosJ
> >
> Thanks.  I vaguely remembered this thread, but I couldn't find it.
> 
> > Depending on your use you might want to
> >
> >     oldins = w.getInsertPoint()
> >
> >     ...
> >
> >     w.setInsertPoint(oldins+len(inserted_text))
> 
> http://pastebin.com/GAc15jRL  uses both w.getInsertPoint() and
> w.setInsertPoint()
> 
> >
> > to get the cursor where you want it afterwards, lots of variations how
> > the new position might be calculated.
> >
> > Other possibly useful methods:
> >
> >     i,j = w.getSelectionRange(sort=True)
> >     s = w.getSelectedText()
> 
> Yes, these are very useful.
> 

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