@Override public IRegion getDamageRegion(ITypedRegion partition, DocumentEvent event, boolean documentPartitioningChanged) { if (!documentPartitioningChanged) { try { IRegion info = fDocument.getLineInformationOfOffset(event.getOffset()); int start = Math.max(partition.getOffset(), info.getOffset()); int end = event.getOffset() + (event.getText() == null ? event.getLength() : event.getText().length()); if (info.getOffset() <= end && end <= info.getOffset() + info.getLength()) { // optimize the case of the same line end = info.getOffset() + info.getLength(); } else{ end = endOfLineOf(end); } end = Math.min(partition.getOffset() + partition.getLength(), end); return new Region(start, end - start); } catch (BadLocationException x) { } } return partition; }
@Override public boolean validate(IDocument document, int offset, DocumentEvent event) { try { String content = document.get(fReplacementPosition.getOffset(), offset - fReplacementPosition.getOffset()); if (fReplacementString.startsWith(content)) { return true; } else if (fReplacementString.length() > 0) { char c = fReplacementString.charAt(0); if ((c == '"' || c == '\'') && fReplacementString.startsWith(c + content)) { return true; } } } catch (BadLocationException e) { // ignore concurrently modified document } return false; }
@Override public void documentChanged(DocumentEvent event) { IDocument document = event.getDocument(); try { int startLine = DocumentHelper.getStartLine(event); if (!DocumentHelper.isRemove(event)) { if (DocumentLineList.this.getSize() != DocumentHelper.getNumberOfLines(document)) { int endLine = DocumentHelper.getEndLine(event, false); // Insert new lines for (int i = startLine; i < endLine; i++) { DocumentLineList.this.addLine(i + 1); } } else { // Update line DocumentLineList.this.updateLine(startLine); } } else { // Update line DocumentLineList.this.updateLine(startLine); } invalidateLine(startLine); } catch (BadLocationException e) { e.printStackTrace(); } }
@Override public void documentChanged(DocumentEvent event) { synchronized (monitor) { lastDocumentChangeTimeStamp = System.currentTimeMillis(); if (refreshOutlineInProgress) { /* * already marked as refreshOutlineInProgress, nothing to do */ return; } } if (!r.isListeningToFurtherDocumentChanges()) { Thread t = new Thread(r, "waiting-for-keyboard-events"); t.start(); } }
public void documentChanged(DocumentEvent event) { // if this is enabled if ("\"".equals(event.getText())) { ITextSelection textSelection = (ITextSelection) this.editor.getSelectionProvider().getSelection(); try { char prev = document.getChar(textSelection.getOffset() - 1); String replacement = "\""; // TODO null checks? IProject project = ((FileEditorInput)editor.getEditorInput()).getFile().getProject(); String lang = TexlipseProperties.getProjectProperty(project, TexlipseProperties.LANGUAGE_PROPERTY); if (Character.isWhitespace(prev)) { replacement = (String) quotes.get(lang + "o"); } else if (Character.isLetterOrDigit(prev)) { replacement = (String) quotes.get(lang + "c"); } else { return; } document.removeDocumentListener(this); document.replace(textSelection.getOffset(), 1, replacement); document.addDocumentListener(this); //editor.resetHighlightRange(); //editor.setHighlightRange(textSelection.getOffset() + 1, 1, true); //editor.getSelectionProvider().setSelection(new TextSelection(textSelection.getOffset() + 3, 5)); } catch (BadLocationException e) {} } }
/** * Informs all registered text listeners about the change specified by the * widget command. This method does not use a robust iterator. * * @param cmd * the widget command translated into a text event sent to all text listeners */ @Override protected void updateTextListeners(final WidgetCommand cmd) { List<ITextListener> textListeners = fTextListeners; if (textListeners != null) { textListeners = new ArrayList<ITextListener>(textListeners); DocumentEvent event = cmd.event; if (event instanceof SlaveDocumentEvent) { event = ((SlaveDocumentEvent) event).getMasterEvent(); } TextEvent e = new TextEvent(cmd.start, cmd.length, cmd.text, cmd.preservedText, event, redraws()) {}; for (int i = 0; i < textListeners.size(); i++) { ITextListener l = textListeners.get(i); l.textChanged(e); } } }
/** * Computes the change abstraction given a text event. * * @param event the text event to analyze * @return a change object describing the event */ private Change computeChange(TextEvent event) { DocumentEvent e = event.getDocumentEvent(); if (e == null) return new Change(TypingRun.NO_CHANGE, -1); int start = e.getOffset(); int end = e.getOffset() + e.getLength(); String newText = e.getText(); if (newText == null) newText = new String(); if (start == end) { // no replace / delete / overwrite if (newText.length() == 1) return new Change(TypingRun.INSERT, end + 1); } else if (start == end - 1) { if (newText.length() == 1) return new Change(TypingRun.OVERTYPE, end); if (newText.length() == 0) return new Change(TypingRun.DELETE, start); } return new Change(TypingRun.UNKNOWN, -1); }
/** * @since 2.4 */ @Override protected RepairEntryData getRepairEntryData(DocumentEvent e) throws Exception { int tokenStartsAt = 0; int tokenInfoIdx = 0; TokenSource source = createTokenSource(e.fDocument.get()); CommonToken token = (CommonToken) source.nextToken(); // find start idx while (true) { if (token == Token.EOF_TOKEN) { break; } if (tokenInfoIdx >= getInternalModifyableTokenInfos().size()) break; TokenInfo tokenInfo = getInternalModifyableTokenInfos().get(tokenInfoIdx); if (tokenInfo.getAntlrTokenType() != token.getType() || token.getStopIndex() - token.getStartIndex() + 1 != tokenInfo.getLength()) break; if (tokenStartsAt + tokenInfo.getLength() > e.fOffset) break; tokenStartsAt += tokenInfo.getLength(); tokenInfoIdx++; token = (CommonToken) source.nextToken(); } return new RepairEntryData(tokenStartsAt, tokenInfoIdx, token, source); }
/** * Update the given position with the given event. The event overlaps with the start of the position. * * @param position * The position * @param event * The event */ private void updateWithOverStartEvent(AttributedPosition position, DocumentEvent event) { int eventOffset = event.getOffset(); int eventEnd = eventOffset + event.getLength(); String newText = event.getText(); if (newText == null) newText = ""; //$NON-NLS-1$ int eventNewLength = newText.length(); int excludedLength = eventNewLength; while (excludedLength > 0 && Character.isJavaIdentifierPart(newText.charAt(excludedLength - 1))) excludedLength--; int deleted = eventEnd - position.getOffset(); int inserted = eventNewLength - excludedLength; position.update(eventOffset + excludedLength, position.getLength() - deleted + inserted); }
public List<StyleRange> getRanges(String expression) { final List<StyleRange> ranges = Lists.newArrayList(); DocumentEvent event = new DocumentEvent(); event.fDocument = new DummyDocument(expression); DocumentTokenSource tokenSource = tokenSourceProvider.get(); tokenSource.updateStructure(event); Iterator<ILexerTokenRegion> iterator = tokenSource.getTokenInfos().iterator(); while (iterator.hasNext()) { ILexerTokenRegion next = iterator.next(); TextAttribute attribute = attributeProvider.getAttribute(tokenTypeMapper.getId(next.getLexerTokenType())); StyleRange range = new StyleRange(next.getOffset(), next.getLength(), attribute.getForeground(), attribute.getBackground()); range.font = attribute.getFont(); range.fontStyle = attribute.getStyle(); ranges.add(range); } return ranges; }
public void fileChanged(final char[] content, final boolean isFirstTimeRead) { Runnable runnable = new Runnable() { public void run() { String text = new String(content); int offset = calculateBacklogOffset(); String currentText = getStore().get(offset,getStore().getLength() - offset); currentText = currentText.concat(text); getStore().set(currentText); getTracker().set(currentText); if(isFirstTimeRead) { offset = calculateBacklogOffset(); currentText = getStore().get(offset,getStore().getLength() - offset); getStore().set(currentText); getTracker().set(currentText); } //int newOffset = getStore().getLength() > content.length ? getStore().getLength() - content.length : 0; DocumentEvent event = new DocumentEvent(LogDocument.this, getStore().getLength(), content.length, text); fireDocumentChanged(event); } }; if(Display.getDefault() != null) { Display.getDefault().asyncExec(runnable); } }
public IRegion getDamageRegion(ITypedRegion partition, DocumentEvent event, boolean documentPartitioningChanged) { if (!documentPartitioningChanged) { try { IRegion info= document.getLineInformationOfOffset(event.getOffset()); int start= Math.max(partition.getOffset(), info.getOffset()); int end= event.getOffset() + (event.getText() == null ? event.getLength() : event.getText().length()); if (info.getOffset() <= end && end <= info.getOffset() + info.getLength()) { // optimize the case of the same line end= info.getOffset() + info.getLength(); } else end= endOfLineOf(end); end= Math.min(partition.getOffset() + partition.getLength(), end); return new Region(start, end - start); } catch (BadLocationException x) { logger.logInfo("unable to find location in document to repair a given region",x); //$NON-NLS-1$ } } return partition; }
public boolean validate(IDocument document, int offset, DocumentEvent event) { try { int replaceOffset = getReplaceOffset(); if (offset >= replaceOffset) { String content = document.get(replaceOffset, offset - replaceOffset); String templateName = fTemplate.getName().toLowerCase(); boolean valid = templateName.startsWith(content.toLowerCase()); if (!valid && fContext instanceof JavaDocContext && templateName.startsWith("<")) { // $NON-NLS-1$ valid = templateName.startsWith(content.toLowerCase(), 1); } return valid; } } catch (BadLocationException e) { // concurrent modification - ignore } return false; }
public void documentChanged(DocumentEvent event) { if ((fRememberedPosition != null) && !fRememberedPosition.isDeleted()) { event.getDocument().removePosition(fRememberedPosition); fActiveRegion = new Region(fRememberedPosition.getOffset(), fRememberedPosition.getLength()); } fRememberedPosition = null; ISourceViewer viewer = getSourceViewer(); if (viewer != null) { StyledText widget = viewer.getTextWidget(); if ((widget != null) && !widget.isDisposed()) { widget.getDisplay().asyncExec(new Runnable() { public void run() { deactivate(); } }); } } }
@Override public void documentChanged(DocumentEvent event) { if (event.getDocument() instanceof JsonDocument) { final JsonDocument document = (JsonDocument) event.getDocument(); Display.getCurrent().asyncExec(new Runnable() { @Override public void run() { document.onChange(); if (contentOutline != null) { contentOutline.setInput(getEditorInput()); } runValidate(false); } }); } }
public boolean validate(IDocument document, int offset, DocumentEvent event) { try { int replaceOffset = getReplaceOffset(document, fTemplate); if (offset >= replaceOffset) { String content = document.get(replaceOffset, offset - replaceOffset); return fTemplate.getName().startsWith(content); } } catch (BadLocationException e) { // concurrent modification - ignore } return false; }
public boolean validate(IDocument document, int offset, DocumentEvent event) { if (offset < this._replacementOffset) { return false; } int overlapIndex = getDisplayString().length() - _replacementString.length(); overlapIndex = Math.max(0, overlapIndex); String endPortion = getDisplayString().substring(overlapIndex); boolean validated = isValidPrefix(getPrefix(document, offset), endPortion); if (validated && event != null) { // make sure that we change the replacement length as the document content changes int delta = ((event.fText == null) ? 0 : event.fText.length()) - event.fLength; final int newLength = Math.max(_replacementLength + delta, 0); _replacementLength = newLength; } return validated; }
/** * Update the given position with the given event. The event overlaps with the start of the position. * * @param position The position * @param event The event */ private void updateWithOverStartEvent(HighlightedPosition position, DocumentEvent event) { int eventOffset= event.getOffset(); int eventEnd= eventOffset + event.getLength(); String newText= event.getText(); if (newText == null) newText= ""; //$NON-NLS-1$ int eventNewLength= newText.length(); int excludedLength= eventNewLength; while (excludedLength > 0 && Character.isJavaIdentifierPart(newText.charAt(excludedLength - 1))) excludedLength--; int deleted= eventEnd - position.getOffset(); int inserted= eventNewLength - excludedLength; position.update(eventOffset + excludedLength, position.getLength() - deleted + inserted); }
public boolean validate(IDocument document, int offset, DocumentEvent event) { if (!isOffsetValid(offset)) return fIsValidated= false; fIsValidated= isValidPrefix(getPrefix(document, offset)); if (fIsValidated && event != null) { // adapt replacement range to document change int delta= (event.fText == null ? 0 : event.fText.length()) - event.fLength; final int newLength= Math.max(getReplacementLength() + delta, 0); setReplacementLength(newLength); } return fIsValidated; }
/** * Computes the change abstraction given a text event. * * @param event the text event to analyze * @return a change object describing the event */ private Change computeChange(TextEvent event) { DocumentEvent e= event.getDocumentEvent(); if (e == null) return new Change(TypingRun.NO_CHANGE, -1); int start= e.getOffset(); int end= e.getOffset() + e.getLength(); String newText= e.getText(); if (newText == null) newText= new String(); if (start == end) { // no replace / delete / overwrite if (newText.length() == 1) return new Change(TypingRun.INSERT, end + 1); } else if (start == end - 1) { if (newText.length() == 1) return new Change(TypingRun.OVERTYPE, end); if (newText.length() == 0) return new Change(TypingRun.DELETE, start); } return new Change(TypingRun.UNKNOWN, -1); }
public boolean validate(IDocument document, int offset, DocumentEvent event) { try { int replaceOffset= getReplaceOffset(); if (offset >= replaceOffset) { String content= document.get(replaceOffset, offset - replaceOffset); String templateName= fTemplate.getName().toLowerCase(); boolean valid= templateName.startsWith(content.toLowerCase()); if (!valid && fContext instanceof JavaDocContext && templateName.startsWith("<")) { //$NON-NLS-1$ valid= templateName.startsWith(content.toLowerCase(), 1); } return valid; } } catch (BadLocationException e) { // concurrent modification - ignore } return false; }
public IRegion getDamageRegion(final ITypedRegion partition, final DocumentEvent e, final boolean documentPartitioningChanged) { if (!documentPartitioningChanged) { String source = fDocument.get(); int start = source.substring(0, e.getOffset()).lastIndexOf("/*"); if (start == -1) { start = 0; } int end = source.indexOf("*/", e.getOffset()); int end2 = e.getOffset() + (e.getText() == null ? e.getLength() : e.getText().length()); if (end == -1) { end = source.length(); } else if (end2 > end) { end = end2; } else { end++; } return new Region(start, end - start); } return partition; }
public IRegion getDamageRegion(final ITypedRegion partition, final DocumentEvent e, final boolean documentPartitioningChanged) { if (!documentPartitioningChanged) { String source = fDocument.get(); int start = source.substring(0, e.getOffset()).lastIndexOf('<'); if (start == -1) { start = 0; } int end = source.indexOf('>', e.getOffset()); int nextEnd = source.indexOf('>', end + 1); if (nextEnd >= 0 && nextEnd > end) { end = nextEnd; } int end2 = e.getOffset() + (e.getText() == null ? e.getLength() : e.getText().length()); if (end == -1) { end = source.length(); } else if (end2 > end) { end = end2; } else { end++; } return new Region(start, end - start); } return partition; }
/** * @see IPresentationDamager#getDamageRegion(ITypedRegion, DocumentEvent, boolean) */ public IRegion getDamageRegion(ITypedRegion partition, DocumentEvent event, boolean documentPartitioningChanged){ if (!documentPartitioningChanged){ try{ IRegion info = fDocument.getLineInformationOfOffset(event.getOffset()); int start = Math.max(partition.getOffset(), info.getOffset()); int end = event.getOffset() + (event.getText() == null ? event.getLength() : event.getText().length()); if (info.getOffset() <= end && end <= info.getOffset() + info.getLength()) { // optimize the case of the same line end = info.getOffset() + info.getLength(); }else end = endOfLineOf(end); end = Math.min(partition.getOffset() + partition.getLength(), end); return new Region(start, end - start); } catch (BadLocationException e) { } } return partition; }
public void documentChanged( DocumentEvent event ) { if ( isTextListenerEnable ) { markDirty( ); } // Disables buttons if text is empty. String text = getEditorText( ); boolean butEnabled = editorUIEnabled && text != null && text.length( ) > 0; butReset.setEnabled( butEnabled ); butValidate.setEnabled( butEnabled ); }
/** * Determine if a selection is being replaced by non-emacs+ behavior (or YANK), and save the * replaced content in the kill ring. This captures the Eclipse (but not emacs) behavior where * typing/pasting into a selection replaces the old with the new, so it is appropriate to save * the old text to the kill ring. * * @param event the DocumentEvent containing the IDocument, offset, and length * @return true if the non-zero length region matches the current selection in the editor */ private boolean isSelectionReplace(DocumentEvent event) { int len = event.getLength(); // ignore plain insertion or any emacs+ (except YANK) command invocation if (selectionReplace && len > 0 && shouldSave()) { ITextEditor editor = EmacsPlusUtils.getCurrentEditor(); // otherwise, if we can get the selection, see if it matches the replace region if (editor != null && editor.getDocumentProvider().getDocument(editor.getEditorInput()) == event.getDocument()) { ISelection isel = editor.getSelectionProvider().getSelection(); if (isel instanceof ITextSelection) { ITextSelection selection = (ITextSelection)isel; boolean result = selection.getOffset() == event.getOffset() && selection.getLength() == len; return result; } } } return false; }
@Override public void documentChanged(DocumentEvent event) { ITextFileBufferManager textFileBufferManager = FileBuffers .getTextFileBufferManager(); ITextFileBuffer textFileBuffer = textFileBufferManager .getTextFileBuffer(event.fDocument); IPath fileLocation = textFileBuffer.getLocation(); String changeType = ChangeOrigin.USER; if (RefactoringExecutionListener.isRefactoringInProgress()) changeType = ChangeOrigin.REFACTORING; else if (CommandExecutionListener.isCutInProgress()) changeType = ChangeOrigin.CUT; else if (CommandExecutionListener.isPasteInProgress()) changeType = ChangeOrigin.PASTE; else if (CommandExecutionListener.isUndoInProgress()) changeType = ChangeOrigin.UNDO; else if (CommandExecutionListener.isRedoInProgress()) changeType = ChangeOrigin.REDO; String filePath = fileLocation.toPortableString(); clientRecorderInstance.recordTextChange(event.fText, event.fOffset, event.fLength, filePath, changeType); }
@Override public boolean validate(IDocument document, int offset, DocumentEvent event) { String[] strs = PySelection.getActivationTokenAndQual(document, offset, false); //System.out.println("validating:"+strs[0]+" - "+strs[1]); //when we end with a '.', we should start a new completion (and not stay in the old one). if (strs[1].length() == 0 && (strs[0].length() == 0 || strs[0].endsWith("."))) { //System.out.println(false); return false; } String qualifier = strs[1]; final boolean useSubstringMatchInCodeCompletion = PyCodeCompletionPreferencesPage .getUseSubstringMatchInCodeCompletion(); String displayString = getDisplayString(); boolean ret = PyCodeCompletionUtils.acceptName(useSubstringMatchInCodeCompletion, displayString, qualifier); return ret; }
/** * Document changed event handler * * @param event Event information * @param file File information */ public static void documentChanged(DocumentEvent event, IFile file) { String path=file.getFullPath().toOSString(); String header="{" +"\"file\": \""+file.getName()+"\"" +",\"path\": \""+path+"\"" +",\"offset\": "+event.fOffset +",\"length\": "+event.fLength +"}"; System.out.println( "Changed ("+event.fOffset+":"+event.fLength+") "+event.fText ); String message=header+"\n\n"+event.fDocument.get(); handler.sendAll(message); }
@Override public boolean validate(IDocument document, int offset, DocumentEvent event) { if(offset < getReplaceOffset()) return false; String prefix; try { prefix = document.get(getReplaceOffset(), offset - getReplaceOffset()); } catch (BadLocationException e) { return false; } boolean validPrefix = isValidPrefix(prefix); if(validPrefix && event != null) { // adapt replacement length to document event/ int eventEndOffset = event.fOffset + event.fLength; // The event should be a common prefix completion (this should be true anyways) : int replaceEndPos = getReplaceOffset() + getReplaceLength(); if(event.fOffset >= getReplaceOffset() && eventEndOffset <= replaceEndPos) { int delta = (event.fText == null ? 0 : event.fText.length()) - event.fLength; this.replaceLength = Math.max(getReplaceLength() + delta, 0); } } return validPrefix; }
/** * @see IPresentationDamager#getDamageRegion(ITypedRegion, DocumentEvent, boolean) */ public IRegion getDamageRegion( ITypedRegion partition, DocumentEvent event, boolean documentPartitioningChanged) { if (!documentPartitioningChanged) { try { IRegion info = fDocument.getLineInformationOfOffset(event.getOffset()); int start = Math.max(partition.getOffset(), info.getOffset()); int end = event.getOffset() + (event.getText() == null ? event.getLength() : event.getText().length()); if (info.getOffset() <= end && end <= info.getOffset() + info.getLength()) { // optimize the case of the same line end = info.getOffset() + info.getLength(); } else end = endOfLineOf(end); end = Math.min( partition.getOffset() + partition.getLength(), end); return new Region(start, end - start); } catch (BadLocationException x) { } } return partition; }
@Override public void documentAboutToBeChanged(DocumentEvent event) { try { if (!DocumentHelper.isInsert(event)) { // Remove or Replace (Remove + Insert) removeLine(event); } } catch (BadLocationException e) { e.printStackTrace(); } }
private void removeLine(DocumentEvent event) throws BadLocationException { int startLine = DocumentHelper.getStartLine(event); int endLine = DocumentHelper.getEndLine(event, true); for (int i = endLine; i > startLine; i--) { DocumentLineList.this.removeLine(i); } }