Java Code Examples for org.eclipse.jface.text.ITextViewerExtension5#widgetOffset2ModelOffset()
The following examples show how to use
org.eclipse.jface.text.ITextViewerExtension5#widgetOffset2ModelOffset() .
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: QuickOutlinePopupDialog.java From APICloud-Studio with GNU General Public License v3.0 | 6 votes |
/** * {@inheritDoc} */ @Override protected Control createDialogArea(Composite parent) { Composite composite = new Composite(parent, SWT.NONE); GridLayoutFactory.fillDefaults().applyTo(composite); fPage.createControl(composite); // Try to select the current item we're on in editor in the outline ISourceViewer viewer = fEditor.getISourceViewer(); int offset = viewer.getTextWidget().getCaretOffset(); if (viewer instanceof ITextViewerExtension5) { ITextViewerExtension5 v5 = (ITextViewerExtension5) viewer; offset = v5.widgetOffset2ModelOffset(offset); } if (offset != -1) { fPage.revealPosition(offset); } GridDataFactory.fillDefaults().hint(320, 240).applyTo(composite); return composite; }
Example 2
Source File: AbstractThemeableEditor.java From APICloud-Studio with GNU General Public License v3.0 | 6 votes |
public int getCaretOffset() { ISourceViewer sourceViewer = getSourceViewer(); if (sourceViewer == null) { return -1; } StyledText styledText = sourceViewer.getTextWidget(); if (styledText == null) { return -1; } if (sourceViewer instanceof ITextViewerExtension5) { ITextViewerExtension5 extension = (ITextViewerExtension5) sourceViewer; return extension.widgetOffset2ModelOffset(styledText.getCaretOffset()); } int offset = sourceViewer.getVisibleRegion().getOffset(); return offset + styledText.getCaretOffset(); }
Example 3
Source File: IndentGuidesPainter.java From xds-ide with Eclipse Public License 1.0 | 5 votes |
/** * Convert a widget offset to the corresponding document offset. * * @param widgetOffset * the widget offset * @return document offset */ private int getDocumentOffset(int widgetOffset) { if (fTextViewer instanceof ITextViewerExtension5) { ITextViewerExtension5 extension = (ITextViewerExtension5) fTextViewer; return extension.widgetOffset2ModelOffset(widgetOffset); } IRegion visible = fTextViewer.getVisibleRegion(); if (widgetOffset > visible.getLength()) { return -1; } return widgetOffset + visible.getOffset(); }
Example 4
Source File: TypeScriptEditor.java From typescript.java with MIT License | 5 votes |
@Override public int getCursorOffset() { ISourceViewer sourceViewer = getSourceViewer(); StyledText styledText = sourceViewer.getTextWidget(); if (styledText == null) { return 0; } if (sourceViewer instanceof ITextViewerExtension5) { ITextViewerExtension5 extension = (ITextViewerExtension5) sourceViewer; return extension.widgetOffset2ModelOffset(styledText.getCaretOffset()); } else { int offset = sourceViewer.getVisibleRegion().getOffset(); return offset + styledText.getCaretOffset(); } }
Example 5
Source File: WhitespaceCharacterPainter.java From APICloud-Studio with GNU General Public License v3.0 | 5 votes |
/** * Convert a widget offset to the corresponding document offset. * * @param widgetOffset * @return document offset */ private int getDocumentOffset(int widgetOffset) { if (fTextViewer instanceof ITextViewerExtension5) { ITextViewerExtension5 extension = (ITextViewerExtension5) fTextViewer; return extension.widgetOffset2ModelOffset(widgetOffset); } IRegion visible = fTextViewer.getVisibleRegion(); if (widgetOffset > visible.getLength()) { return -1; } return widgetOffset + visible.getOffset(); }
Example 6
Source File: CommandExecutionUtils.java From APICloud-Studio with GNU General Public License v3.0 | 5 votes |
private static int getCaretOffset(ITextViewer textViewer) { StyledText textWidget = textViewer.getTextWidget(); int caretOffset = textWidget.getCaretOffset(); if (textViewer instanceof ITextViewerExtension5) { ITextViewerExtension5 extension = (ITextViewerExtension5) textViewer; return extension.widgetOffset2ModelOffset(caretOffset); } return caretOffset; }
Example 7
Source File: LineBackgroundPainter.java From APICloud-Studio with GNU General Public License v3.0 | 5 votes |
/** * Returns the location of the caret as offset in the source viewer's input document. * * @return the caret location */ private int getModelCaret() { int widgetCaret = fViewer.getTextWidget().getCaretOffset(); if (fViewer instanceof ITextViewerExtension5) { ITextViewerExtension5 extension = (ITextViewerExtension5) fViewer; return extension.widgetOffset2ModelOffset(widgetCaret); } IRegion visible = fViewer.getVisibleRegion(); return widgetCaret + visible.getOffset(); }
Example 8
Source File: AbstractJavaCompletionProposal.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 5 votes |
/** * Creates a style range for the text viewer. * * @param viewer the text viewer * @return the new style range for the text viewer or <code>null</code> * @since 3.6 */ private StyleRange createStyleRange(ITextViewer viewer) { StyledText text= viewer.getTextWidget(); if (text == null || text.isDisposed()) return null; int widgetCaret= text.getCaretOffset(); int modelCaret= 0; if (viewer instanceof ITextViewerExtension5) { ITextViewerExtension5 extension= (ITextViewerExtension5) viewer; modelCaret= extension.widgetOffset2ModelOffset(widgetCaret); } else { IRegion visibleRegion= viewer.getVisibleRegion(); modelCaret= widgetCaret + visibleRegion.getOffset(); } if (modelCaret >= getReplacementOffset() + getReplacementLength()) return null; int length= getReplacementOffset() + getReplacementLength() - modelCaret; Color foreground= getForegroundColor(); Color background= getBackgroundColor(); return new StyleRange(modelCaret, length, foreground, background); }
Example 9
Source File: IndentGuidePainter.java From IndentGuide with MIT License | 5 votes |
/** * Convert a widget offset to the corresponding document offset. * * @param widgetOffset * the widget offset * @return document offset */ private int getDocumentOffset(int widgetOffset) { if (fTextViewer instanceof ITextViewerExtension5) { ITextViewerExtension5 extension = (ITextViewerExtension5) fTextViewer; return extension.widgetOffset2ModelOffset(widgetOffset); } IRegion visible = fTextViewer.getVisibleRegion(); if (widgetOffset > visible.getLength()) { return -1; } return widgetOffset + visible.getOffset(); }
Example 10
Source File: PyCompletionPresentationUpdater.java From Pydev with Eclipse Public License 1.0 | 5 votes |
private StyleRange createStyleRange(ITextViewer viewer, int initialOffset, int len) { StyledText text = viewer.getTextWidget(); if (text == null || text.isDisposed()) { return null; } int widgetCaret = text.getCaretOffset(); int modelCaret = 0; if (viewer instanceof ITextViewerExtension5) { ITextViewerExtension5 extension = (ITextViewerExtension5) viewer; modelCaret = extension.widgetOffset2ModelOffset(widgetCaret); } else { IRegion visibleRegion = viewer.getVisibleRegion(); modelCaret = widgetCaret + visibleRegion.getOffset(); } if (modelCaret >= initialOffset + len) { return null; } int length = initialOffset + len - modelCaret; Color foreground = getForegroundColor(); Color background = getBackgroundColor(); return new StyleRange(modelCaret, length, foreground, background); }
Example 11
Source File: JavaEditor.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 4 votes |
/** * Computes and returns the source reference that includes the caret and * serves as provider for the outline page selection and the editor range * indication. * * @return the computed source reference * @since 3.0 */ protected ISourceReference computeHighlightRangeSourceReference() { ISourceViewer sourceViewer= getSourceViewer(); if (sourceViewer == null) return null; StyledText styledText= sourceViewer.getTextWidget(); if (styledText == null) return null; int caret= 0; if (sourceViewer instanceof ITextViewerExtension5) { ITextViewerExtension5 extension= (ITextViewerExtension5)sourceViewer; caret= extension.widgetOffset2ModelOffset(styledText.getCaretOffset()); } else { int offset= sourceViewer.getVisibleRegion().getOffset(); caret= offset + styledText.getCaretOffset(); } IJavaElement element= getElementAt(caret, false); if ( !(element instanceof ISourceReference)) return null; if (element.getElementType() == IJavaElement.IMPORT_DECLARATION) { IImportDeclaration declaration= (IImportDeclaration) element; IImportContainer container= (IImportContainer) declaration.getParent(); ISourceRange srcRange= null; try { srcRange= container.getSourceRange(); } catch (JavaModelException e) { } if (srcRange != null && srcRange.getOffset() == caret) return container; } return (ISourceReference) element; }