Home Download Buy Blog Forum Support

view.replace does not work

view.replace does not work

Postby ayoub on Sat May 11, 2013 4:24 pm

Hello,

I am trying to make this ST3 plug in https://bitbucket.org/inkytonik/scalaworksheet work in ST2 and I have a problem with the method replace of sublime.View.

I have a function that must just replace the content of a view like this:
Code: Select all
def replaceViewWith (edit, view, text):
    region = sublime.Region(0, view.size ())
    view.replace(edit, region, text)


view.replace seem to do nothing to the view, the content stays the same.

I also tried to use erase and then insert like this:
Code: Select all
def replaceViewWith (edit, view, text):
    region = sublime.Region(0, view.size ())
    view.erase(edit, region)
    view.insert(edit, 0, text)


But the same issue, erase does not change anything to the view, and insert returns 0 :(

Can any one tell me what is wrong?

thanks,
Ayoub.
ayoub
 
Posts: 3
Joined: Sat May 11, 2013 3:55 pm

Re: view.replace does not work

Postby quarnster on Sat May 11, 2013 5:43 pm

Code: Select all
    def updateViews (self, edit, input_view, input, output):
        replaceViewWith (edit, input_view, input)
        replaceViewWith (edit, self.view, output)


http://www.sublimetext.com/docs/3/api_reference.html:
Using an invalid Edit object, or an Edit object from a different view, will cause the functions that require them to fail.
quarnster
 
Posts: 389
Joined: Tue Nov 29, 2011 11:34 am

Re: view.replace does not work

Postby ayoub on Sat May 11, 2013 5:57 pm

well as I said I am using sublime text 2, so the 2nd version for the API.

Edit:
in your example you are editing two views input_view and self.view I want to edit just one.
In my code I am in the same view and trying to edit it.

I tried also to use view.begin_edit() and view.finish_edit() but without success :(
Last edited by ayoub on Sat May 11, 2013 7:51 pm, edited 1 time in total.
ayoub
 
Posts: 3
Joined: Sat May 11, 2013 3:55 pm

Re: view.replace does not work

Postby skuroda on Sat May 11, 2013 7:47 pm

Have you made sure the correct text is being passed to the function? Perhaps something got messed up while you were refactoring other parts of the code.
skuroda
 
Posts: 676
Joined: Fri Oct 05, 2012 8:11 am

Re: view.replace does not work

Postby ayoub on Sat May 11, 2013 7:55 pm

Yeah I checked that it is the correct text. It is the view that is not edited.
ayoub
 
Posts: 3
Joined: Sat May 11, 2013 3:55 pm


Return to Plugin Development

Who is online

Users browsing this forum: Google [Bot] and 7 guests