org.eclipse.jface.text.IDocument#removePosition ( )源码实例Demo

下面列出了org.eclipse.jface.text.IDocument#removePosition ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: e4macs   文件: IndentForTabHandler.java
/**
 * Insert tab/spaces at selection offset and each subsequent line origin
 * 
 * @see com.mulgasoft.emacsplus.commands.EmacsPlusCmdHandler#transform(ITextEditor, IDocument, ITextSelection, ExecutionEvent)
 */
@Override
protected int transform(ITextEditor editor, IDocument document, ITextSelection currentSelection, ExecutionEvent event)
throws BadLocationException {
	// if we're here, either ^U or no relevant ^I
	ColumnSupport cs = new ColumnSupport(document,editor); 
	String tab = cs.getSpaces(0,cs.getTabWidth());
	int off = currentSelection.getOffset();
	Position coff = new Position(getCursorOffset(editor,currentSelection),0);
	try {
		document.addPosition(coff);
		int begin = document.getLineOfOffset(off);
		int end = document.getLineOfOffset(off+ currentSelection.getLength());
		if (begin != end) {
			while (++begin <= end) {
				document.replace(document.getLineOffset(begin), 0, tab);
			}
		}
		document.replace(off, 0, tab);
	} finally {
		document.removePosition(coff);
	} 
	return coff.offset;
}
 
源代码2 项目: typescript.java   文件: TemplateEngine.java
public void reset() {
	fProposals.clear();
	for (Iterator it = fPositions.entrySet().iterator(); it.hasNext();) {
		Entry entry = (Entry) it.next();
		IDocument doc = (IDocument) entry.getKey();
		Position position = (Position) entry.getValue();
		doc.removePosition(position);
	}
	fPositions.clear();
}
 
/**
 * Called after the document changed occurred. It must be preceded by a call to preReplace().
 *
 * @param document the document on which to track the reference position.
 * @return offset after the replace
 */
public int postReplace(IDocument document) {
	try {
		document.removePosition(CATEGORY, fPosition);
		document.removePositionUpdater(fPositionUpdater);
		document.removePositionCategory(CATEGORY);

	} catch (BadPositionCategoryException e) {
		// should not happen
		JavaPlugin.log(e);
	}
	return fPosition.getOffset();
}
 
/**
 * Empties the collector.
 */
public void reset() {
	fProposals.clear();
	for (Iterator<Entry<IDocument, Position>> it= fPositions.entrySet().iterator(); it.hasNext();) {
		Entry<IDocument, Position> entry= it.next();
		IDocument doc= entry.getKey();
		Position position= entry.getValue();
		doc.removePosition(position);
	}
	fPositions.clear();
}
 
源代码5 项目: e4macs   文件: NewLineIndentHandler.java
/**
 * @see com.mulgasoft.emacsplus.commands.EmacsPlusCmdHandler#transform(ITextEditor, IDocument, ITextSelection, ExecutionEvent)
 */
@Override
protected int transform(ITextEditor editor, IDocument document, ITextSelection currentSelection, ExecutionEvent event)
throws BadLocationException {
	int result = NO_OFFSET; 
	Control c = MarkUtils.getTextWidget(editor);
	if (c instanceof StyledText) {
		StyledText st = (StyledText)c;
		String ld = st.getLineDelimiter();
		int insertionOffset = getCursorOffset(editor,currentSelection);
		int widgetInsertionOffset = st.getCaretOffset();
		
		// the offset position will be updated by the internals on insertion/indent
		Position caret= new Position(insertionOffset, 0);
		document.addPosition(caret);
		
		st.setSelectionRange(widgetInsertionOffset, 0);
		// operate directly on the widget
		st.replaceTextRange(widgetInsertionOffset, 0, ld);
		document.removePosition(caret);
		
		if (st.getSelection().x == widgetInsertionOffset) {
			// move cursor by the amount detected
			result = getCursorOffset(editor) + caret.offset - insertionOffset;
		} 
	}
	return result;
}
 
源代码6 项目: e4macs   文件: TecoRegister.java
private void removePosition(ITextEditor editor, Position position) {
	removeListener();
	IDocument document = editor.getDocumentProvider().getDocument(editor.getEditorInput());
	try {
		document.removePosition(MarkRing.MARK_CATEGORY,position);
	} catch (BadPositionCategoryException e) {
	}			
}
 
源代码7 项目: goclipse   文件: TemplateEngine.java
/**
 * Empties the collector.
 */
public void reset() {
	fProposals.clear();
	
	for (Entry<IDocument, Position> entry : fPositions.entrySet()) {
		IDocument doc= entry.getKey();
		Position position= entry.getValue();
		doc.removePosition(position);
	}
	fPositions.clear();
}
 
源代码8 项目: n4js   文件: N4JSReplacementTextApplier.java
/**
 * Really do apply the proposal. Assumed to be run within the prevent flickering mode.
 */
private int doApply(QualifiedName qualifiedName, String alias, IDocument document,
		ConfigurableCompletionProposal proposal) throws BadLocationException {
	String shortSemanticReplacementString = alias != null ? alias : lastSegmentOrDefaultHost(qualifiedName);
	String shortSyntacticReplacementString = valueConverter.toString(shortSemanticReplacementString);
	String longReplacementString = shortSyntacticReplacementString
			+ ConfigurableCompletionProposalExtensions.getReplacementSuffix(proposal);

	ImportRewriter importRewriter = importRewriterFactory.create(document, context);

	ReplaceEdit replaceEdit = new ReplaceEdit(
			proposal.getReplacementOffset(),
			proposal.getReplacementLength(),
			longReplacementString);
	MultiTextEdit compound = new MultiTextEdit();
	AliasLocation aliasLocation = null;
	if (alias != null) {
		aliasLocation = importRewriter.addSingleImport(qualifiedName, alias, compound);
	} else {
		importRewriter.addSingleImport(qualifiedName, compound);
	}
	compound.addChild(replaceEdit);

	Position caret = new Position(proposal.getReplacementOffset(), 0);
	document.addPosition(caret);
	compound.apply(document);
	document.removePosition(caret);

	int cursorPosition = caret.getOffset();
	proposal.setReplacementOffset(cursorPosition - longReplacementString.length());
	proposal.setReplacementLength(shortSyntacticReplacementString.length()); // do not include suffix!
	proposal.setCursorPosition(
			cursorPosition - proposal.getReplacementOffset()); // cursorPosition is relative to replacementOffset!

	if (aliasLocation != null) {
		final int aliasOffset = aliasLocation.getBaseOffset() + aliasLocation.getRelativeOffset();
		final int aliasLength = shortSyntacticReplacementString.length();
		N4JSCompletionProposal castedProposal = (N4JSCompletionProposal) proposal;
		castedProposal.setLinkedModeBuilder((appliedProposal, currentDocument) -> {
			if (viewer.getTextWidget() == null || viewer.getTextWidget().isDisposed()) {
				return; // do not attempt to set up linked mode in a disposed UI
			}
			try {
				LinkedPositionGroup group = new LinkedPositionGroup();
				group.addPosition(new LinkedPosition(
						currentDocument,
						aliasOffset,
						aliasLength,
						LinkedPositionGroup.NO_STOP));
				group.addPosition(new LinkedPosition(
						currentDocument,
						proposal.getReplacementOffset(),
						proposal.getReplacementLength(),
						LinkedPositionGroup.NO_STOP));
				proposal.setSelectionStart(proposal.getReplacementOffset());
				proposal.setSelectionLength(proposal.getReplacementLength());
				LinkedModeModel model = new LinkedModeModel();
				model.addGroup(group);
				model.forceInstall();

				LinkedModeUI ui = new LinkedModeUI(model, viewer);
				ui.setExitPolicy(new IdentifierExitPolicy('\n'));
				ui.setExitPosition(
						viewer,
						proposal.getReplacementOffset()
								+ proposal.getCursorPosition()
								+ ConfigurableCompletionProposalExtensions.getCursorOffset(proposal),
						0,
						Integer.MAX_VALUE);
				ui.setCyclingMode(LinkedModeUI.CYCLE_NEVER);
				ui.enter();
			} catch (BadLocationException e) {
				logger.error(e.getMessage(), e);
			}
		});
	} else {
		adjustCursorPositionIfRequested(proposal);
	}
	return cursorPosition;
}
 
源代码9 项目: tlaplus   文件: TLAProofPosition.java
/**
 * Should be called when this is removed as a fold.
 * 
 * @param document from which this is being deleted
 */
public void remove(IDocument document)
{
    document.removePosition(positionOfProof);
    document.removePosition(positionOfStatement);
}
 
源代码10 项目: e4macs   文件: DeleteWhitespaceHandler.java
/**
 * Determine the correct set of lines and delete the whitespace at the end of each of them.
 * 
 * @see com.mulgasoft.emacsplus.commands.EmacsPlusCmdHandler#transform(ITextEditor, IDocument, ITextSelection, ExecutionEvent)
 */
@Override
protected int transform(ITextEditor editor, IDocument document, ITextSelection currentSelection,
		ExecutionEvent event) throws BadLocationException {
	int result = NO_OFFSET;
	int lastLine = 0;
	int firstLine = 0;
	int maxOffset = Integer.MAX_VALUE;		
	if (editor.showsHighlightRangeOnly()) {
		// if the buffer is narrowed, then operate on precise region
		IRegion narrow = editor.getHighlightRange();
		int lastOffset = narrow.getOffset() + narrow.getLength();
		firstLine = document.getLineOfOffset(narrow.getOffset()); 
		lastLine = document.getLineOfOffset(lastOffset);
		IRegion endInfo = document.getLineInformationOfOffset(lastOffset);
		if (endInfo.getOffset() != lastOffset) {
			// point maxOffset at the last character in the narrowed region
			maxOffset = lastOffset -1;
		} else {
			// back up if we're at the first offset of the last line
			lastLine--;
		}
	} else {
		lastLine = document.getNumberOfLines() -1;
	}
	if (firstLine <= lastLine) {
		Position coff = new Position(getCursorOffset(editor,currentSelection),0);
		try {
			// record the position so we can restore it after any whitespace deletions
			document.addPosition(coff);
			deleteWhitepace(lastLine,firstLine,maxOffset,document);
		} catch (BadLocationException e) {
			// shouldn't happen, but alert user if it does
			asyncShowMessage(editor,BAD_LOCATION_ERROR,true);
		} finally {
			result = coff.getOffset();
			document.removePosition(coff);
		}
	}
	return result;
}
 
源代码11 项目: e4macs   文件: MarkRing.java
private void removeMarkPosition(IDocument document, Position mark) throws BadPositionCategoryException {
	document.removePosition(MARK_CATEGORY, mark);
}