Java Code Examples for org.eclipse.jface.text.TextEvent#getOffset()

The following examples show how to use org.eclipse.jface.text.TextEvent#getOffset() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: TMPresentationReconciler.java    From tm4e with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Translates the given text event into the corresponding range of the viewer's
 * document.
 *
 * @param e
 *            the text event
 * @return the widget region corresponding the region of the given event or
 *         <code>null</code> if none
 * @since 2.1
 */
private IRegion widgetRegion2ModelRegion(TextEvent e) {
	String text = e.getText();
	int length = text == null ? 0 : text.length();
	if (viewer instanceof ITextViewerExtension5) {
		ITextViewerExtension5 extension = (ITextViewerExtension5) viewer;
		return extension.widgetRange2ModelRange(new Region(e.getOffset(), length));
	}
	IRegion visible = viewer.getVisibleRegion();
	return new Region(e.getOffset() + visible.getOffset(), length);
}
 
Example 2
Source File: TMPresentationReconcilerTestGenerator.java    From tm4e with Eclipse Public License 1.0 5 votes vote down vote up
@Override
public void textChanged(TextEvent event) {
	if (event.getDocumentEvent() != null) {
		return;
	}

	String command = "viewer.invalidateTextPresentation(" + event.getOffset() + ", " + event.getLength() + ");";
	write("\t\t" + command, true);

	//commands.add(new Command(command));

}
 
Example 3
Source File: TMPresentationReconciler.java    From tm4e with Eclipse Public License 1.0 4 votes vote down vote up
@Override
public void textChanged(TextEvent e) {
	if (!e.getViewerRedrawState()) {
		return;
	}
	// changed text: propagate previous style, which will be overridden
	// later asynchronously by TM
	if (e.getDocumentEvent() != null) {
		int diff = e.getText().length() - e.getLength();
		if (diff == 0 || e.getOffset() <= 0) {
			return;
		}
		StyleRange range = viewer.getTextWidget().getStyleRangeAtOffset(e.getOffset() - 1);
		if (range == null) {
			return;
		}
		range.length = Math.max(0, range.length + diff);
		viewer.getTextWidget().setStyleRange(range);
		return;
	}

	// TextViewer#invalidateTextPresentation is called (because
	// of validation, folding, etc)
	// case 2), do the colorization.
	IDocument document = viewer.getDocument();
	if (document == null) {
		return;
	}
	IRegion region = computeRegionToRedraw(e, document);
	if (enabled) {
		// case where there is grammar & theme -> update text presentation with the
		// grammar tokens
		ITMModel model = getTMModelManager().connect(document);
		if (model == null) {
			return;
		}
		try {
			TMPresentationReconciler.this.colorize(region, (TMDocumentModel) model);
		} catch (BadLocationException e1) {
			TMUIPlugin.getDefault().getLog().log(new Status(IStatus.ERROR, TMUIPlugin.PLUGIN_ID, e1.getMessage(), e1));
		}
	} else {
		// case where there is no grammar & theme -> update text presentation with the
		// default styles (ex: to support highlighting with GenericEditor)
		TextPresentation presentation = new TextPresentation(region, 100);
		presentation.setDefaultStyleRange(
				new StyleRange(region.getOffset(), region.getLength(), null, null));
		applyTextRegionCollection(presentation);
	}
}