Java Code Examples for org.eclipse.jface.text.link.LinkedModeModel#findPosition()

The following examples show how to use org.eclipse.jface.text.link.LinkedModeModel#findPosition() . 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: RenameLinkedMode.java    From xtext-eclipse with Eclipse Public License 2.0 6 votes vote down vote up
@Override
public ExitFlags doExit(LinkedModeModel model, VerifyEvent event, int offset, int length) {
	showPreview = (event.stateMask & SWT.CTRL) != 0 && (event.character == SWT.CR || event.character == SWT.LF);
	if (length == 0 && (event.character == SWT.BS || event.character == SWT.DEL)) {
		LinkedPosition position = model.findPosition(new LinkedPosition(document, offset, 0,
				LinkedPositionGroup.NO_STOP));
		if (position != null) {
			if (event.character == SWT.BS) {
				if (offset - 1 < position.getOffset()) {
					// skip backspace at beginning of linked position
					event.doit = false;
				}
			} else /* event.character == SWT.DEL */{
				if (offset + 1 > position.getOffset() + position.getLength()) {
					// skip delete at end of linked position
					event.doit = false;
				}
			}
		}
	}
	return null; // don't change behavior
}
 
Example 2
Source File: LinkedNamesAssistProposal.java    From typescript.java with MIT License 6 votes vote down vote up
@Override
public ExitFlags doExit(LinkedModeModel model, VerifyEvent event, int offset, int length) {
	if (length == 0 && (event.character == SWT.BS || event.character == SWT.DEL)) {
		LinkedPosition position= model.findPosition(new LinkedPosition(fDocument, offset, 0, LinkedPositionGroup.NO_STOP));
		if (position != null) {
			if (event.character == SWT.BS) {
				if (offset - 1 < position.getOffset()) {
					//skip backspace at beginning of linked position
					event.doit= false;
				}
			} else /* event.character == SWT.DEL */ {
				if (offset + 1 > position.getOffset() + position.getLength()) {
					//skip delete at end of linked position
					event.doit= false;
				}
			}
		}
	}

	return null; // don't change behavior
}
 
Example 3
Source File: LinkedNamesAssistProposal.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
public ExitFlags doExit(LinkedModeModel model, VerifyEvent event, int offset, int length) {
	if (length == 0 && (event.character == SWT.BS || event.character == SWT.DEL)) {
		LinkedPosition position= model.findPosition(new LinkedPosition(fDocument, offset, 0, LinkedPositionGroup.NO_STOP));
		if (position != null) {
			if (event.character == SWT.BS) {
				if (offset - 1 < position.getOffset()) {
					//skip backspace at beginning of linked position
					event.doit= false;
				}
			} else /* event.character == SWT.DEL */ {
				if (offset + 1 > position.getOffset() + position.getLength()) {
					//skip delete at end of linked position
					event.doit= false;
				}
			}
		}
	}

	return null; // don't change behavior
}
 
Example 4
Source File: DeleteBlockingExitPolicy.java    From eclipse-multicursor with Eclipse Public License 1.0 6 votes vote down vote up
@Override
public ExitFlags doExit(LinkedModeModel model, VerifyEvent event, int offset, int length) {
	if (length == 0 && (event.character == SWT.BS || event.character == SWT.DEL)) {
		LinkedPosition position= model.findPosition(new LinkedPosition(fDocument, offset, 0, LinkedPositionGroup.NO_STOP));
		if (position != null) {
			if (event.character == SWT.BS) {
				if (offset - 1 < position.getOffset()) {
					//skip backspace at beginning of linked position
					event.doit= false;
				}
			} else /* event.character == SWT.DEL */ {
				if (offset + 1 > position.getOffset() + position.getLength()) {
					//skip delete at end of linked position
					event.doit= false;
				}
			}
		}
	}

	return null; // don't change behavior
}
 
Example 5
Source File: XtextEditor.java    From xtext-eclipse with Eclipse Public License 2.0 5 votes vote down vote up
/**
 * Finds the next position after the given position.
 * 
 * @param position
 *            the current position
 * @return the next position
 */
protected int findNextPosition(int position) {
	ISourceViewer viewer = getSourceViewer();
	int widget = -1;
	int next = position;
	while (next != BreakIterator.DONE && widget == -1) {
		next = fIterator.following(next);
		if (next != BreakIterator.DONE)
			widget = modelOffset2WidgetOffset(viewer, next);
	}

	IDocument document = viewer.getDocument();
	LinkedModeModel model = LinkedModeModel.getModel(document, position);
	if (model != null) {
		LinkedPosition linkedPosition = model.findPosition(new LinkedPosition(document, position, 0));
		if (linkedPosition != null) {
			int linkedPositionEnd = linkedPosition.getOffset() + linkedPosition.getLength();
			if (position != linkedPositionEnd && linkedPositionEnd < next)
				next = linkedPositionEnd;
		} else {
			LinkedPosition nextLinkedPosition = model.findPosition(new LinkedPosition(document, next, 0));
			if (nextLinkedPosition != null) {
				int nextLinkedPositionOffset = nextLinkedPosition.getOffset();
				if (position != nextLinkedPositionOffset && nextLinkedPositionOffset < next)
					next = nextLinkedPositionOffset;
			}
		}
	}

	return next;
}
 
Example 6
Source File: XtextEditor.java    From xtext-eclipse with Eclipse Public License 2.0 5 votes vote down vote up
/**
 * Finds the previous position before the given position.
 * 
 * @param position
 *            the current position
 * @return the previous position
 */
protected int findPreviousPosition(int position) {
	ISourceViewer viewer = getSourceViewer();
	int widget = -1;
	int previous = position;
	while (previous != BreakIterator.DONE && widget == -1) { // XXX: optimize
		previous = fIterator.preceding(previous);
		if (previous != BreakIterator.DONE)
			widget = modelOffset2WidgetOffset(viewer, previous);
	}

	IDocument document = viewer.getDocument();
	LinkedModeModel model = LinkedModeModel.getModel(document, position);
	if (model != null) {
		LinkedPosition linkedPosition = model.findPosition(new LinkedPosition(document, position, 0));
		if (linkedPosition != null) {
			int linkedPositionOffset = linkedPosition.getOffset();
			if (position != linkedPositionOffset && previous < linkedPositionOffset)
				previous = linkedPositionOffset;
		} else {
			LinkedPosition previousLinkedPosition = model
					.findPosition(new LinkedPosition(document, previous, 0));
			if (previousLinkedPosition != null) {
				int previousLinkedPositionEnd = previousLinkedPosition.getOffset()
						+ previousLinkedPosition.getLength();
				if (position != previousLinkedPositionEnd && previous < previousLinkedPositionEnd)
					previous = previousLinkedPositionEnd;
			}
		}
	}

	return previous;
}
 
Example 7
Source File: JavaEditor.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Finds the next position after the given position.
 *
 * @param position the current position
 * @return the next position
 */
protected int findNextPosition(int position) {
	ISourceViewer viewer= getSourceViewer();
	int widget= -1;
	int next= position;
	while (next != BreakIterator.DONE && widget == -1) { // XXX: optimize
		next= fIterator.following(next);
		if (next != BreakIterator.DONE)
			widget= modelOffset2WidgetOffset(viewer, next);
	}

	IDocument document= viewer.getDocument();
	LinkedModeModel model= LinkedModeModel.getModel(document, position);
	if (model != null && next != BreakIterator.DONE) {
		LinkedPosition linkedPosition= model.findPosition(new LinkedPosition(document, position, 0));
		if (linkedPosition != null) {
			int linkedPositionEnd= linkedPosition.getOffset() + linkedPosition.getLength();
			if (position != linkedPositionEnd && linkedPositionEnd < next)
				next= linkedPositionEnd;
		} else {
			LinkedPosition nextLinkedPosition= model.findPosition(new LinkedPosition(document, next, 0));
			if (nextLinkedPosition != null) {
				int nextLinkedPositionOffset= nextLinkedPosition.getOffset();
				if (position != nextLinkedPositionOffset && nextLinkedPositionOffset < next)
					next= nextLinkedPositionOffset;
			}
		}
	}

	return next;
}
 
Example 8
Source File: JavaEditor.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Finds the previous position before the given position.
 *
 * @param position the current position
 * @return the previous position
 */
protected int findPreviousPosition(int position) {
	ISourceViewer viewer= getSourceViewer();
	int widget= -1;
	int previous= position;
	while (previous != BreakIterator.DONE && widget == -1) { // XXX: optimize
		previous= fIterator.preceding(previous);
		if (previous != BreakIterator.DONE)
			widget= modelOffset2WidgetOffset(viewer, previous);
	}

	IDocument document= viewer.getDocument();
	LinkedModeModel model= LinkedModeModel.getModel(document, position);
	if (model != null && previous != BreakIterator.DONE) {
		LinkedPosition linkedPosition= model.findPosition(new LinkedPosition(document, position, 0));
		if (linkedPosition != null) {
			int linkedPositionOffset= linkedPosition.getOffset();
			if (position != linkedPositionOffset && previous < linkedPositionOffset)
				previous= linkedPositionOffset;
		} else {
			LinkedPosition previousLinkedPosition= model.findPosition(new LinkedPosition(document, previous, 0));
			if (previousLinkedPosition != null) {
				int previousLinkedPositionEnd= previousLinkedPosition.getOffset() + previousLinkedPosition.getLength();
				if (position != previousLinkedPositionEnd && previous < previousLinkedPositionEnd)
					previous= previousLinkedPositionEnd;
			}
		}
	}

	return previous;
}
 
Example 9
Source File: SubWordActions.java    From Pydev with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Finds the next position after the given position.
 *
 * @param position the current position
 * @return the next position
 */
protected int findNextPosition(int position) {
    ISourceViewer viewer = getSourceViewer();
    int widget = -1;
    int next = position;
    while (next != BreakIterator.DONE && widget == -1) { // XXX: optimize
        next = fIterator.following(next);
        if (next != BreakIterator.DONE) {
            widget = modelOffset2WidgetOffset(viewer, next);
        }
    }

    IDocument document = viewer.getDocument();
    LinkedModeModel model = LinkedModeModel.getModel(document, position);
    if (model != null && next != BreakIterator.DONE) {
        LinkedPosition linkedPosition = model.findPosition(new LinkedPosition(document, position, 0));
        if (linkedPosition != null) {
            int linkedPositionEnd = linkedPosition.getOffset() + linkedPosition.getLength();
            if (position != linkedPositionEnd && linkedPositionEnd < next) {
                next = linkedPositionEnd;
            }
        } else {
            LinkedPosition nextLinkedPosition = model.findPosition(new LinkedPosition(document, next, 0));
            if (nextLinkedPosition != null) {
                int nextLinkedPositionOffset = nextLinkedPosition.getOffset();
                if (position != nextLinkedPositionOffset && nextLinkedPositionOffset < next) {
                    next = nextLinkedPositionOffset;
                }
            }
        }
    }

    return next;
}
 
Example 10
Source File: SubWordActions.java    From Pydev with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Finds the previous position before the given position.
 *
 * @param position the current position
 * @return the previous position
 */
protected int findPreviousPosition(int position) {
    ISourceViewer viewer = getSourceViewer();
    int widget = -1;
    int previous = position;
    while (previous != BreakIterator.DONE && widget == -1) { // XXX: optimize
        previous = fIterator.preceding(previous);
        if (previous != BreakIterator.DONE) {
            widget = modelOffset2WidgetOffset(viewer, previous);
        }
    }

    IDocument document = viewer.getDocument();
    LinkedModeModel model = LinkedModeModel.getModel(document, position);
    if (model != null && previous != BreakIterator.DONE) {
        LinkedPosition linkedPosition = model.findPosition(new LinkedPosition(document, position, 0));
        if (linkedPosition != null) {
            int linkedPositionOffset = linkedPosition.getOffset();
            if (position != linkedPositionOffset && previous < linkedPositionOffset) {
                previous = linkedPositionOffset;
            }
        } else {
            LinkedPosition previousLinkedPosition = model
                    .findPosition(new LinkedPosition(document, previous, 0));
            if (previousLinkedPosition != null) {
                int previousLinkedPositionEnd = previousLinkedPosition.getOffset()
                        + previousLinkedPosition.getLength();
                if (position != previousLinkedPositionEnd && previous < previousLinkedPositionEnd) {
                    previous = previousLinkedPositionEnd;
                }
            }
        }
    }

    return previous;
}