0

Hi, I m doing a eclipse plugin project to create an IDE. In my IDE,the currently opened editor is checked for a particular string and should be replaced by a string entered in the textbox which is in the side view. I m able to access the editor but if i search for the particular string and replace that string with the input entered by the user it is not working.

 IDocumentProvider provider=((AbstractTextEditor) ieditorpart).getDocumentProvid();
 IDocument doc = provider.getDocument(ieditorpart.getEditorInput());  
 String content = doc.get();
 pos=content.compareTo("\\/\\*ProbeEnd\\*\\/");
 doc.replace(pos,5, "hello");

But this is not working... here i have just given the replacement string as hello,but that value should be taken from the textbox..

Is there any mistake in accessing the editor? should i use this approach to do this or is there any approach to implement this? Can Anyone help me in doing this?

2 Answers 2

1

Why is the variable 'pos' the compareTo-Value (-1,0,1)? The compareTo returns the lexicographical order of the two Strings.

The replace method of IDocument has three parameters:

  • int offset - the offset in the document, where 'text' should be inserted
  • int length - the length starting from 'offset', which should be overwritten. length 0 means insert.
  • String text - the substitution text

Example:

String oldContent = doc.get();
assert oldContent.equals("TestingText");

String replaceText = "REPLACE";

doc.replace(5,3,replaceText);

String newContent = doc.get();
assert newContent.equals("TestiREPLACEext");
//offset 5 is the position after 'Testi'
//length 3 means 'ngT' (starting from the offset) should be replaced
//REPLACE is the newText
Sign up to request clarification or add additional context in comments.

Comments

0

Call firePropertyChange(IEditorPart.PROP_INPUT) from your editor.

1 Comment

in default texteditors, the editor registered an listener to the document and is informed about a replace directly. It is not necessary to fire that the input changed.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.