Sublime Forum

View.replace does not work

#1

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:

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:

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

Can any one tell me what is wrong?

thanks,
Ayoub.

1 Like

What is the easiest way to clear the view?
#2

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

sublimetext.com/docs/3/api_reference.html:

0 Likes

#3

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

0 Likes

#4

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.

0 Likes

#5

Yeah I checked that it is the correct text. It is the view that is not edited.

0 Likes