Package org.eclipse.jface.text

Examples of org.eclipse.jface.text.TextSelection


    }

    // --------------- All others point to this 2 methods!
    public void toggleBreakpoints(IWorkbenchPart part, ISelection selection) throws CoreException {
        if (part instanceof PyEdit && selection instanceof TextSelection) {
            TextSelection textSelection = (TextSelection) selection;
            PyEdit pyEdit = (PyEdit) part;
            int startLine = textSelection.getStartLine();

            List<IMarker> markersFromCurrentFile = PyBreakpointRulerAction.getMarkersFromCurrentFile(pyEdit, startLine);
            if (markersFromCurrentFile.size() > 0) {
                PyBreakpointRulerAction.removeMarkers(markersFromCurrentFile);
            } else {
View Full Code Here


        return this.doc;
    }

    public ITextSelection getExtendedSelection() {
        if (this.extendedSelection == null) {
            this.extendedSelection = new TextSelection(this.doc, this.userSelection.getOffset(),
                    this.userSelection.getLength());

            if (getScopeAdapter() != null) {
                this.extendedSelection = moduleAdapter.normalizeSelection(VisitorFactory.createSelectionExtension(
                        getScopeAdapter(), this.extendedSelection));
View Full Code Here

    /**
     * @param document the document we are using to make the selection
     * @param offset the offset where the selection will happen (0 characters will be selected)
     */
    public TextSelectionUtils(IDocument doc, int offset) {
        this(doc, new TextSelection(doc, offset, 0));
    }
View Full Code Here

        resultSelection = parseSelection(resultCursors.positions);
    }

    private ITextSelection parseSelection(List<Integer> list) {
        if (list.size() == 1) {
            return new TextSelection(list.get(0), 0);
        } else if (list.size() == 2) {
            int start = list.get(0);
            int end = list.get(1);
            return new TextSelection(start, end - start);
        } else {
            return null;
        }
    }
View Full Code Here

            String selectedText = ps.getSelectedText();
            if (selectedText.length() == 0) {
                //Select the current word
                Tuple<String, Integer> currToken = ps.getCurrToken();
                if (currToken.o1.length() > 0) {
                    return new TextSelection(currToken.o2, currToken.o1.length());
                } else {
                    char c = '\0';
                    try {
                        c = ps.getCharAtCurrentOffset();
                    } catch (BadLocationException e) {
                        //Ignore (end of document is selected).
                    }
                    if (StringUtils.isClosingPeer(c)) {
                        PythonPairMatcher pairMatcher = new PythonPairMatcher();
                        int openingOffset = pairMatcher.searchForOpeningPeer(ps.getAbsoluteCursorOffset(),
                                StringUtils.getPeer(c), c, doc);
                        if (openingOffset >= 0) {
                            return new TextSelection(openingOffset, ps.getAbsoluteCursorOffset() - openingOffset + 1);
                        }
                    }
                }
            } else {
                //There's already some text selected
                boolean tryMatchWithQualifier = true;
                boolean hasDotSelected = false; //value only valid if tryMatchWithQualifier == true!
                for (int i = 0; i < selectedText.length(); i++) {
                    char c = selectedText.charAt(i);
                    if (c == '.') {
                        hasDotSelected = true;
                        continue;
                    }
                    if (!Character.isJavaIdentifierPart(c)) {
                        tryMatchWithQualifier = false;
                        break;
                    }
                }
                if (tryMatchWithQualifier) {
                    Tuple<String, Integer> currToken = ps.getCurrToken();
                    if (!hasDotSelected && !currToken.o1.equals(selectedText)) {
                        return new TextSelection(currToken.o2, currToken.o1.length());
                    } else {
                        //The selected text is not equal to the current token, let's see if we have to select a full dotted word
                        Tuple<String, Integer> currDottedToken = ps.getCurrDottedStatement();
                        if (!currDottedToken.o1.equals(selectedText)) {
                            return new TextSelection(currDottedToken.o2, currDottedToken.o1.length());
                        }
                    }
                }
            }
            Scopes scopes = ScopesParser.createScopes(doc);
            //            System.out.println(scopes.debugString(doc));
            IRegion scope = scopes.getScopeForSelection(selection.getOffset(), selection.getLength());
            if (scope != null) {
                return new TextSelection(scope.getOffset(), scope.getLength());
            }

        } catch (BadLocationException e) {
            Log.log(e);
        }
View Full Code Here

     */
    private void handleLiteral(IDocument document, DocumentCommand command, boolean isDefaultContext, char literalChar) {
        if (!prefs.getAutoLiterals()) {
            return;
        }
        PySelection ps = new PySelection(document, new TextSelection(document, command.offset, command.length));
        if (command.length > 0) {
            try {
                //We have more contents selected. Delete it so that we can properly use the heuristics.
                ps.deleteSelection();
                command.length = 0;
View Full Code Here

    public void showInEditor(ITextEditor textEdit, Location start, Location end) {
        try {
            IDocument doc = textEdit.getDocumentProvider().getDocument(textEdit.getEditorInput());
            int s = start.toOffset(doc);
            int e = end == null ? s : end.toOffset(doc);
            TextSelection sel = new TextSelection(s, e - s);
            textEdit.getSelectionProvider().setSelection(sel);
        } catch (BadLocationException e1) {
            if (textEdit instanceof PyEdit) {
                PyEdit p = (PyEdit) textEdit;
                Log.log(IStatus.ERROR, ("Error setting selection:" + start + " - " + end + " - " + p.getEditorFile()),
View Full Code Here

        final int endLineLen = getLineLength(doc, endLine);
        final int endLineDelimiterLen = getLineDelimiterLen(doc, endLine);
        int endOffset = fixOffset(endLineOffset + endCol, endLineOffset, endLineOffset + endLineLen
                - endLineDelimiterLen);

        selectionProvider.setSelection(new TextSelection(startOffset, endOffset - startOffset));
    }
View Full Code Here

    }

    private RefactoringInfo setupInfo(MockupSelectionConfig config) throws Throwable {
        IDocument doc = new Document(data.source);

        ITextSelection selection = new TextSelection(doc, data.sourceSelection.getOffset(),
                data.sourceSelection.getLength());
        RefactoringInfo info = new RefactoringInfo(doc, selection, new IGrammarVersionProvider() {

            public int getGrammarVersion() throws MisconfigurationException {
                return IGrammarVersionProvider.GRAMMAR_PYTHON_VERSION_2_7;
View Full Code Here

                "";
        Module mod = (Module) parseLegalDocStr(s);
        stmtType b0 = mod.body[0];

        Document doc = new Document(s);
        FindDuplicatesVisitor visitor = new FindDuplicatesVisitor(new TextSelection(doc, 0, 7), ((Expr) b0).value, doc);
        mod.accept(visitor);
        List<Tuple<ITextSelection, SimpleNode>> duplicates = visitor.getDuplicates();

        Comparator<? super Tuple<Integer, Integer>> comparator = new Comparator<Tuple<Integer, Integer>>() {
View Full Code Here

TOP

Related Classes of org.eclipse.jface.text.TextSelection

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.