@Override public int getEndLine() { return textSelection.getEndLine(); }
@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; }
/** * Returns the active line. * * @param useRulerInfo <code>true</code> if ruler info should be used * @return the line of interest. * @since 3.1 */ private int computeLine(boolean useRulerInfo) { int lastLine; if (useRulerInfo) { IVerticalRulerInfo ruler= getRuler(); if (ruler == null) lastLine= -1; else lastLine= ruler.getLineOfLastMouseButtonActivity(); } else { ITextSelection selection= getSelection(); if (selection == null) lastLine= -1; else lastLine= selection.getEndLine(); } return lastLine; }
/** * 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); }
/** * 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; }
/** * 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; } }
@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; }
/** * 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; } }