@Override public int getStartLine() { return textSelection.getStartLine(); }
@Override boolean isMultiline(ISelection selection) { ITextSelection ts= (ITextSelection)selection; return ts.getEndLine() > ts.getStartLine(); }
@Override int getCoveredLines(ISelection selection) throws BadLocationException { ITextSelection ts= (ITextSelection)selection; return ts.getEndLine() - ts.getStartLine() + 1; }
@Override int getCoveredLines(ISelection selection) throws BadLocationException { ITextSelection ts= (ITextSelection)selection; return ts.getEndLine() - ts.getStartLine() + 1; }
@Override int getCoveredLines(ISelection selection) throws BadLocationException { ITextSelection ts= (ITextSelection)selection; return ts.getEndLine() - ts.getStartLine() + 1; }
@Override boolean isMultiline(ISelection selection) { ITextSelection ts= (ITextSelection)selection; return ts.getEndLine() > ts.getStartLine(); }
@Override int getCoveredLines(ISelection selection) throws BadLocationException { ITextSelection ts= (ITextSelection)selection; return ts.getEndLine() - ts.getStartLine() + 1; }
private boolean isMultilineSelection() { ISelection selection= getSelectionProvider().getSelection(); if (selection instanceof ITextSelection) { ITextSelection ts= (ITextSelection) selection; return ts.getStartLine() != ts.getEndLine(); } return false; }
private boolean isMultilineSelection() { ISelection selection= getSelectionProvider().getSelection(); if (selection instanceof ITextSelection) { ITextSelection ts= (ITextSelection) selection; return ts.getStartLine() != ts.getEndLine(); } return false; }
public boolean canToggleWatchpoints(IWorkbenchPart part, ISelection selection) { if (selection instanceof ITextSelection) { final ITextSelection textSelection = (ITextSelection) selection; final String text = textSelection.getText(); if (part instanceof ScriptEditor) { ScriptEditor scriptEditor = (ScriptEditor) part; try { IDocument doc = scriptEditor.getScriptSourceViewer().getDocument(); IRegion region = doc.getLineInformation(textSelection.getStartLine()); String string = doc.get(region.getOffset(), region.getLength()); return string.indexOf('=') != -1 || string.trim().startsWith("var "); } catch (BadLocationException e) { DLTKUIPlugin.log(e); } } return text.indexOf("=") != -1; } return true; }
public void run() { lineNumber[0] = textSelection.getStartLine() + 1; ASTParser parser = ASTParser.newParser(AST.JLS3); parser.setSource(document.get().toCharArray()); CompilationUnit compilationUnit= (CompilationUnit)parser.createAST(null); ValidBreakpointLocationLocator locator= new ValidBreakpointLocationLocator(compilationUnit, lineNumber[0], false, false); compilationUnit.accept(locator); validLine[0]= locator.getLineLocation(); typeName[0]= locator.getFullyQualifiedTypeName(); } };
/** * Creates a region describing the text block (something that starts at * the beginning of a line) completely containing the current selection. * * @param selection the selection to use * @return the region describing the text block comprising the given selection * @throws BadLocationException when the document does not contain the selection */ private IRegion getTextBlockFromSelection(ITextSelection selection) throws BadLocationException { IDocument document= getDocument(); int start= document.getLineOffset(selection.getStartLine()); int end; int endLine= selection.getEndLine(); if (document.getNumberOfLines() > endLine+1) { end= document.getLineOffset(endLine+1); } else { end= document.getLength(); } return new Region(start, end - start); }
/** * Computes the region of the skipped line given the text block to be moved. If * <code>fUpwards</code> is <code>true</code>, the line above <code>selection</code> * is selected, otherwise the line below. * * @param document the document <code>selection</code> refers to * @param selection the selection on <code>document</code> that will be moved. * @return the region comprising the line that <code>selection</code> will be moved over, without its terminating delimiter. */ private ITextSelection getSkippedLine(IDocument document, ITextSelection selection) { int skippedLineN= (fUpwards ? selection.getStartLine() - 1 : selection.getEndLine() + 1); if (skippedLineN > document.getNumberOfLines() || (!fCopy && (skippedLineN < 0 || skippedLineN == document.getNumberOfLines()))) return null; try { if (fCopy && skippedLineN == -1) skippedLineN= 0; IRegion line= document.getLineInformation(skippedLineN); return new TextSelection(document, line.getOffset(), line.getLength()); } catch (BadLocationException e) { // only happens on concurrent modifications return null; } }
/** * Computes the region of the skipped line given the text block to be moved. If * <code>fUpwards</code> is <code>true</code>, the line above <code>selection</code> * is selected, otherwise the line below. * * @param document the document <code>selection</code> refers to * @param selection the selection on <code>document</code> that will be moved. * @return the region comprising the line that <code>selection</code> will be moved over, without its terminating delimiter. */ private ITextSelection getSkippedLine(IDocument document, ITextSelection selection) { int skippedLineN= (fUpwards ? selection.getStartLine() - 1 : selection.getEndLine() + 1); if (skippedLineN > document.getNumberOfLines() || (!fCopy && (skippedLineN < 0 || skippedLineN == document.getNumberOfLines()))) return null; try { if (fCopy && skippedLineN == -1) skippedLineN= 0; IRegion line= document.getLineInformation(skippedLineN); return new TextSelection(document, line.getOffset(), line.getLength()); } catch (BadLocationException e) { // only happens on concurrent modifications return null; } }
/** * Creates a region describing the text block (something that starts at * the beginning of a line) completely containing the current selection. * * @param selection the selection to use * @return the region describing the text block comprising the given selection * @throws BadLocationException when the document does not contain the selection */ private IRegion getTextBlockFromSelection(ITextSelection selection) throws BadLocationException { IDocument document= getDocument(); int start= document.getLineOffset(selection.getStartLine()); int end; int endLine= selection.getEndLine(); if (document.getNumberOfLines() > endLine+1) { end= document.getLineOffset(endLine+1); } else { end= document.getLength(); } return new Region(start, end - start); }
/** * Computes the region of the skipped line given the text block to be moved. If * <code>fUpwards</code> is <code>true</code>, the line above <code>selection</code> * is selected, otherwise the line below. * * @param document the document <code>selection</code> refers to * @param selection the selection on <code>document</code> that will be moved. * @return the region comprising the line that <code>selection</code> will be moved over, without its terminating delimiter. */ private ITextSelection getSkippedLine(IDocument document, ITextSelection selection) { int skippedLineN= (fUpwards ? selection.getStartLine() - 1 : selection.getEndLine() + 1); if (skippedLineN > document.getNumberOfLines() || (!fCopy && (skippedLineN < 0 || skippedLineN == document.getNumberOfLines()))) return null; try { if (fCopy && skippedLineN == -1) skippedLineN= 0; IRegion line= document.getLineInformation(skippedLineN); return new TextSelection(document, line.getOffset(), line.getLength()); } catch (BadLocationException e) { // only happens on concurrent modifications return null; } }
/** * Computes the region of the skipped line given the text block to be moved. If * <code>fUpwards</code> is <code>true</code>, the line above <code>selection</code> * is selected, otherwise the line below. * * @param document the document <code>selection</code> refers to * @param selection the selection on <code>document</code> that will be moved. * @return the region comprising the line that <code>selection</code> will be moved over, without its terminating delimiter. */ private ITextSelection getSkippedLine(IDocument document, ITextSelection selection) { int skippedLineN= (fUpwards ? selection.getStartLine() - 1 : selection.getEndLine() + 1); if (skippedLineN > document.getNumberOfLines() || (!fCopy && (skippedLineN < 0 || skippedLineN == document.getNumberOfLines()))) return null; try { if (fCopy && skippedLineN == -1) skippedLineN= 0; IRegion line= document.getLineInformation(skippedLineN); return new TextSelection(document, line.getOffset(), line.getLength()); } catch (BadLocationException e) { // only happens on concurrent modifications return null; } }
/** * Determines the text selection for the breakpoint action. If clicking on the ruler inside * the highlighted text, return the text selection for the highlighted text. Otherwise, * return a text selection representing the start of the line. * * @param document The IDocument backing the Editor. * @param line The line clicked on in the ruler. * @return An ITextSelection as described. * @throws BadLocationException If underlying operations throw. */ private ITextSelection getTextSelection(IDocument document, int line) throws BadLocationException { IRegion region = document.getLineInformation(line); ITextSelection textSelection = new TextSelection(document, region.getOffset(), 0); ISelectionProvider provider = fPart.getSite().getSelectionProvider(); if (provider != null){ ISelection selection = provider.getSelection(); if (selection instanceof ITextSelection && ((ITextSelection) selection).getStartLine() <= line && ((ITextSelection) selection).getEndLine() >= line) { textSelection = (ITextSelection) selection; } } return textSelection; }
@Override public void run() { ITextEditor editor= getTextEditor(); if (editor == null) return; if (!validateEditorInputState()) return; IDocument document= getDocument(editor); if (document == null) return; ITextSelection selection= getSelection(editor); if (selection == null) return; int startLine= selection.getStartLine(); int endLine= selection.getEndLine(); try { int caretOffset= joinLines(document, startLine, endLine); if (caretOffset > -1) editor.selectAndReveal(caretOffset, 0); } catch (BadLocationException e) { // should not happen } }
/** * Determines the text selection for the ruler action. If clicking on the * ruler inside the highlighted text, return the text selection for the * highlighted text. Otherwise, return a text selection representing the * start of the line. * * @param document The IDocument backing the Editor. * @param line The line clicked on in the ruler. * @return An ITextSelection as described. * @throws BadLocationException If underlying operations throw. */ private ITextSelection getTextSelection(IDocument document, int line) throws BadLocationException { IRegion region = document.getLineInformation(line); ITextSelection textSelection = new TextSelection(document, region.getOffset(), 0); ISelectionProvider provider = fActivePart.getSite().getSelectionProvider(); if (provider != null) { ISelection selection = provider.getSelection(); if (selection instanceof ITextSelection && ((ITextSelection) selection).getStartLine() <= line && ((ITextSelection) selection).getEndLine() >= line) { textSelection = (ITextSelection) selection; } } return textSelection; }