Skip to content

Commit

Permalink
Update the marker in BasicMarkerUpdater::updateMarker in one operation
Browse files Browse the repository at this point in the history
Do not use (up to) 3 workspace operations to update a marker, do it all
in one single operation instead.

Contributes to
#983
  • Loading branch information
fedejeanne authored and iloveeclipse committed Aug 1, 2023
1 parent 1a1eb94 commit 7da51e7
Showing 1 changed file with 21 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,19 @@
*******************************************************************************/
package org.eclipse.ui.texteditor;

import java.util.HashMap;
import java.util.Map;

import org.eclipse.core.runtime.CoreException;

import org.eclipse.core.resources.IMarker;

import org.eclipse.jface.text.BadLocationException;
import org.eclipse.jface.text.IDocument;
import org.eclipse.jface.text.Position;

import org.eclipse.ui.internal.editors.text.EditorsPlugin;


/**
* Updates a marker's positional attributes which are
Expand Down Expand Up @@ -63,31 +70,42 @@ public boolean updateMarker(IMarker marker, IDocument document, Position positio
int markerStart= MarkerUtilities.getCharStart(marker);
int markerEnd= MarkerUtilities.getCharEnd(marker);


Map<String, Object> attributeChanges= new HashMap<>(3);

if (markerStart != -1 && markerEnd != -1) {

offsetsInitialized= true;

int offset= position.getOffset();
if (markerStart != offset) {
MarkerUtilities.setCharStart(marker, offset);
MarkerUtilities.setCharStart(attributeChanges, offset);
offsetsChanged= true;
}

offset += position.getLength();
if (markerEnd != offset) {
MarkerUtilities.setCharEnd(marker, offset);
MarkerUtilities.setCharEnd(attributeChanges, offset);
offsetsChanged= true;
}
}

if (!offsetsInitialized || (offsetsChanged && MarkerUtilities.getLineNumber(marker) != -1)) {
try {
// marker line numbers are 1-based
MarkerUtilities.setLineNumber(marker, document.getLineOfOffset(position.getOffset()) + 1);
MarkerUtilities.setLineNumber(attributeChanges, document.getLineOfOffset(position.getOffset()) + 1);
} catch (BadLocationException x) {
}
}

if (!attributeChanges.isEmpty()) {
try {
marker.setAttributes(attributeChanges);
} catch (CoreException e) {
EditorsPlugin.log(e);
}
}

return true;
}
}

0 comments on commit 7da51e7

Please sign in to comment.