@Override public void verifyKey(VerifyEvent event) { if (matched && event.keyCode == 27) { Point range = sourceViewer.getSelectedRange(); try { sourceViewer.getDocument().replace(range.x - longForm.length(), longForm.length(), shortcut); sourceViewer.setSelectedRange(range.x - longForm.length() + shortcut.length(), 0); matched = false; } catch (BadLocationException e) { handleBadLocationException(e); } } }
private void restorePosition() { if (storedPosition != null && !storedPosition.isDeleted() && viewer.getDocument() != null) { viewer.setSelectedRange(storedPosition.offset, storedPosition.length); viewer.revealRange(storedPosition.offset, storedPosition.length); } storedPosition = null; }
protected XtextEditor openEditor(String string) throws Exception { int cursor = string.indexOf('|'); String fileExtension = getFileExtension(); IFile file = createFile("foo/myfile" + files.size() + "." + fileExtension, string.replace("|", "")); files.add(file); XtextEditor editor = openEditor(file); editor.getInternalSourceViewer().setSelectedRange(cursor, 0); editor.getInternalSourceViewer().getTextWidget().setFocus(); return editor; }
protected XtextEditor openEditor(String content) throws Exception { int cursor = content.indexOf('|'); String fileExtension = getFileExtension(); IFile file = createFile("foo/myfile" + files.size() + "." + fileExtension, content.replace("|", "")); files.add(file); XtextEditor editor = openEditor(file); editor.getInternalSourceViewer().setSelectedRange(cursor, 0); editor.getInternalSourceViewer().getTextWidget().setFocus(); return editor; }
protected XtextEditor openEditor(String string) throws Exception { int cursor = string.indexOf('|'); String fileExtension = getFileExtension(); IFile file = createFile("foo/myfile" + files.size() + "." + fileExtension, string.replace("|", "")); files.add(file); XtextEditor editor = openEditor(file); editor.getInternalSourceViewer().setSelectedRange(cursor, 0); editor.getInternalSourceViewer().getTextWidget().setFocus(); return editor; }
protected XtextEditor openEditor(String content) throws Exception { int cursor = content.indexOf('|'); String fileExtension = getFileExtension(); IFile file = createFile("foo/myfile" + files.size() + "." + fileExtension, content.replace("|", "")); files.add(file); XtextEditor editor = openEditor(file); editor.getInternalSourceViewer().setSelectedRange(cursor, 0); editor.getInternalSourceViewer().getTextWidget().setFocus(); return editor; }
@Override public void apply(IDocument document) { if (markerResolution instanceof TextDocumentMarkerResolution) { try { IRegion region = ((TextDocumentMarkerResolution) markerResolution).processFix(document, marker); if (region != null) { sourceViewer.setSelectedRange(region.getOffset(), region.getLength()); } } catch (CoreException e) { Activator.getDefault().getLog().log(e.getStatus()); } } else { markerResolution.run(marker); } }
private void restoreFullSelection() { if (fOriginalSelection.y != 0) { int originalOffset= fOriginalSelection.x; LinkedPosition[] positions= fLinkedPositionGroup.getPositions(); for (int i= 0; i < positions.length; i++) { LinkedPosition position= positions[i]; if (! position.isDeleted() && position.includes(originalOffset)) { fEditor.getViewer().setSelectedRange(position.offset, position.length); return; } } } }
protected void selectText(XtextEditor editor,int relativeToCurrentOffset,int length) throws Exception { ITextSelection selection = (ITextSelection) editor.getSelectionProvider().getSelection(); editor.getInternalSourceViewer().setSelectedRange(selection.getOffset()+relativeToCurrentOffset, length); }
private void restoreFullSelection() { if (fOriginalSelection.y != 0) { int originalOffset= fOriginalSelection.x; LinkedPosition[] positions= fLinkedPositionGroup.getPositions(); for (int i= 0; i < positions.length; i++) { LinkedPosition position= positions[i]; if (! position.isDeleted() && position.includes(originalOffset)) { fEditor.getViewer().setSelectedRange(position.offset, position.length); return; } } } }
protected void selectText(XtextEditor editor,int relativeToCurrentOffset,int length) throws Exception { ITextSelection selection = (ITextSelection) editor.getSelectionProvider().getSelection(); editor.getInternalSourceViewer().setSelectedRange(selection.getOffset()+relativeToCurrentOffset, length); }
private void restoreFullSelection() { if (fOriginalSelection.y != 0) { int originalOffset= fOriginalSelection.x; LinkedPosition[] positions= fLinkedPositionGroup.getPositions(); for (int i= 0; i < positions.length; i++) { LinkedPosition position= positions[i]; if (! position.isDeleted() && position.includes(originalOffset)) { fEditor.getViewer().setSelectedRange(position.offset, position.length); return; } } } }
public void setHighlightRange(IDocumentKey key) { ISourceViewer sourceViewer = getSourceViewer(); if (sourceViewer == null) return; IDocument document = sourceViewer.getDocument(); if (document == null) return; int offset = key.getOffset(); int length = key.getLength(); if (offset == -1 || length == -1) return; setHighlightRange(offset, length, true); int nameLength = PropertiesUtil.createWritableName(key.getName()).length(); sourceViewer.setSelectedRange(offset, Math.min(nameLength, length)); }
protected void restoreOriginalSelection() { ISelection originalSelection = renameElementContext.getTriggeringEditorSelection(); if (originalSelection instanceof ITextSelection) { getXtextEditor().getInternalSourceViewer().setSelectedRange( ((ITextSelection) originalSelection).getOffset(), ((ITextSelection) originalSelection).getLength()); } }
public void setSelectedRange(IDocumentRange range, boolean fullNodeSelection) { ISourceViewer sourceViewer = getSourceViewer(); if (sourceViewer == null) return; IDocument document = sourceViewer.getDocument(); if (document == null) return; int offset; int length; if (range instanceof IDocumentElementNode && !fullNodeSelection) { length = ((IDocumentElementNode) range).getXMLTagName().length(); offset = range.getOffset() + 1; } else { length = range.getLength(); offset = range.getOffset(); } sourceViewer.setSelectedRange(offset, length); }
/** * Selects the given range on the editor. * * @param newOffset the selection offset * @param newLength the selection range */ private void selectAndReveal(int newOffset, int newLength) { Assert.isTrue(newOffset >= 0); Assert.isTrue(newLength >= 0); ITextEditor editor= getTextEditor(); if (editor instanceof JavaEditor) { ISourceViewer viewer= ((JavaEditor)editor).getViewer(); if (viewer != null) viewer.setSelectedRange(newOffset, newLength); } else // this is too intrusive, but will never get called anyway getTextEditor().selectAndReveal(newOffset, newLength); }
/** * Selects the given range on the editor. * * @param newOffset the selection offset * @param newLength the selection range */ private void selectAndReveal(int newOffset, int newLength) { Assert.isTrue(newOffset >= 0); Assert.isTrue(newLength >= 0); ITextEditor editor= getTextEditor(); if (editor instanceof JavaEditor) { ISourceViewer viewer= ((JavaEditor)editor).getViewer(); if (viewer != null) viewer.setSelectedRange(newOffset, newLength); } else // this is too intrusive, but will never get called anyway getTextEditor().selectAndReveal(newOffset, newLength); }
/** * Perform the next completion. */ private void completeNext() { try { fDocument.replace(fLastCompletion.startOffset, fLastCompletion.length, fLastCompletion.next()); //next() will already advance } catch (BadLocationException e) { // we should never get here. different from other places to notify the user. log(e); clearState(); return; } // move the caret to the insertion point ISourceViewer sourceViewer= ((AbstractTextEditor) getTextEditor()).getSourceViewer(); sourceViewer.setSelectedRange(fLastCompletion.startOffset + fLastCompletion.length, 0); sourceViewer.revealRange(fLastCompletion.startOffset, fLastCompletion.length); fExitStrategy.arm(((AbstractTextEditor) getTextEditor()).getSourceViewer()); }
/** * Perform the next completion. */ private void completeNext() { try { fDocument.replace(fLastCompletion.startOffset, fLastCompletion.length, fLastCompletion.next()); //next() will already advance } catch (BadLocationException e) { // we should never get here. different from other places to notify the user. log(e); clearState(); return; } // move the caret to the insertion point ISourceViewer sourceViewer= ((AbstractTextEditor) getTextEditor()).getSourceViewer(); sourceViewer.setSelectedRange(fLastCompletion.startOffset + fLastCompletion.length, 0); sourceViewer.revealRange(fLastCompletion.startOffset, fLastCompletion.length); fExitStrategy.arm(((AbstractTextEditor) getTextEditor()).getSourceViewer()); }
/** * Perform the next completion. */ private void completeNext() { try { fDocument.replace(fLastCompletion.startOffset, fLastCompletion.length, fLastCompletion.suggestions[fLastCompletion.nextSuggestion]); } catch (BadLocationException e) { // we should never get here. different from other places to notify the user. log(e); clearState(); return; } // advance the suggestion state fLastCompletion.advance(); // move the caret to the insertion point ISourceViewer sourceViewer= ((AbstractTextEditor) getTextEditor()).getSourceViewer(); sourceViewer.setSelectedRange(fLastCompletion.startOffset + fLastCompletion.length, 0); sourceViewer.revealRange(fLastCompletion.startOffset, fLastCompletion.length); fExitStrategy.arm(((AbstractTextEditor) getTextEditor()).getSourceViewer()); }