Search code examples
eclipseeclipse-pluginannotationshighlighting

Howto: Eclipse plugin Textmarker hightlight by line not by char and delete them


I write my own Eclipse-Plugin and get an errorlog from a server. This log includes linenumbers. I want to mark this lines with another backround color if you click on the Error in my View. My Problem i can only mark text in my editor with CHAR_START and CHAR_END but i dont know how many characters are in each line. The line number is totally ignorer And how can i delete this markers in my code? In my example the first 10 characters are marked irrespective of the line I set

          IEditorPart editorPart = PlatformUI.getWorkbench()
                    .getActiveWorkbenchWindow().getActivePage()
                    .getActiveEditor();
            if (editorPart != null) {
                FileEditorInput input = (FileEditorInput) editorPart
                        .getEditorInput();
                IFile file = input.getFile();
                IMarker marker = null;
                try {
                    marker = file.createMarker("de.fhduesseldorf.medien.mi.codecheck.marker");
                    marker.setAttribute(IMarker.LINE_NUMBER, 4);
                    marker.setAttribute(IMarker.CHAR_START, 0);
                    marker.setAttribute(IMarker.CHAR_END, 10);
                } catch (CoreException e) {
                    e.printStackTrace();
                }
            }

Solution

  • You have to get the text content being edited and manually count characters (including new line chars) in each line until you get to the line in question. That's the only way to determine the character offsets of a given line or lines.