1

I am developing a eclipse plugin in which i need to open up a text file in eclipse editor and highlight a line inside the file programatically.

To open a file and to highlight a text/line in eclipse editor area, i used below code,

fileStore = EFS.getLocalFileSystem().getStore(file.toURI());
page = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
ITextEditor editor = (ITextEditor) IDE.openEditorOnFileStore( page, fileStore);
editor.selectAndReveal(startOffset, endOffset);

Now say i have a file with below contents

Line:1         xxxxxxxxxxxxxxxxxxx
Line:2         yyyyyyyyyyyyyyyyyyyy
:
:
Line: 20       aaaaaaaaaaaaaaaaaaaaa
Line: 21       bbbbbbbbbbbbbbbbbbbbb

Now i need to highlight Line:20 in above file. For that i need to start offset and end offset of that line. How can i achieve this in Java?

Thanks in advance.

Andrea Ligios
  • 49,480
  • 26
  • 114
  • 243
AJJ
  • 3,570
  • 7
  • 43
  • 76

0 Answers0