Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
 package org.eclipse.xtext.ui.editor.embedded;
 
 import  org.eclipse.jface.text.IMarkRegionTarget;
 import  org.eclipse.jface.text.IRegion;
 import  org.eclipse.jface.text.ITextViewer;
 import  org.eclipse.jface.text.ITextViewerExtension;
 import  org.eclipse.jface.text.ITextViewerExtension5;
 import  org.eclipse.swt.graphics.Point;

Implementation of IMarkRegionTarget using ITextViewer. This class was initially copied from org.eclipse.ui.texteditor.MarkRegionTarget.

Author(s):
Sebastian Zarnekow - Initial contribution and API
Since:
2.3
public class MarkRegionTargetWithoutStatusline implements IMarkRegionTarget {

The text viewer.
	private final ITextViewer fViewer;

Creates a MarkRegionTargetWithoutStatusline.

Parameters:
viewer the text viewer
	public MarkRegionTargetWithoutStatusline(ITextViewer viewer) {
		 = viewer;
	}
	public void setMarkAtCursor(boolean set) {
		if (!( instanceof ITextViewerExtension))
			return;
		ITextViewerExtension viewerExtension = ((ITextViewerExtension) );
		if (set) {
			Point selection = .getSelectedRange();
			viewerExtension.setMark(selection.x);
else {
			viewerExtension.setMark(-1);
		}
	}
	public void swapMarkAndCursor() {
		if (!( instanceof ITextViewerExtension))
			return;
		ITextViewerExtension viewerExtension = ((ITextViewerExtension) );
		int markPosition = viewerExtension.getMark();
		if (markPosition == -1) {
			return;
		}
		if (!isVisible(markPosition)) {
			return;
		}
		Point selection = .getSelectedRange();
		viewerExtension.setMark(selection.x);
		.setSelectedRange(markPosition, 0);
		.revealRange(markPosition, 0);
	}

Tells whether the given offset is visible in the given text viewer.

Parameters:
viewer the text viewer
offset the offset to check
Returns:
true if the given offset is visible in the given text viewer
	protected boolean isVisible(ITextViewer viewerint offset) {
		if (viewer instanceof ITextViewerExtension5) {
			ITextViewerExtension5 extension = (ITextViewerExtension5) viewer;
			return extension.modelOffset2WidgetOffset(offset) >= 0;
		}
		IRegion region = viewer.getVisibleRegion();
		int vOffset = region.getOffset();
		return (vOffset <= offset && offset <= vOffset + region.getLength());
	}
New to GrepCode? Check out our FAQ X