public UndoCollector(TextEdit root) { fOffset= root.getOffset(); fLength= root.getLength(); }
/** * Returns the inclusive end position of this edit. The inclusive end * position denotes the last character of the region manipulated by * this edit. The returned value is the result of the following * calculation: * <pre> * getOffset() + getLength() - 1; * <pre> * * @return the inclusive end position */ public final int getInclusiveEnd() { return getOffset() + getLength() - 1; }
public UndoCollector(TextEdit root) { fOffset= root.getOffset(); fLength= root.getLength(); }
/** * Returns the inclusive end position of this edit. The inclusive end * position denotes the last character of the region manipulated by * this edit. The returned value is the result of the following * calculation: * <pre> * getOffset() + getLength() - 1; * <pre> * * @return the inclusive end position */ public final int getInclusiveEnd() { return getOffset() + getLength() - 1; }
@Override public final int getLength() { if (fDefined) return super.getLength(); List<TextEdit> children= internalGetChildren(); if (children == null || children.size() == 0) return 0; // the children are already sorted TextEdit first= children.get(0); TextEdit last= children.get(children.size() - 1); return last.getOffset() - first.getOffset() + last.getLength(); }
/** * Returns the exclusive end position of this edit. The exclusive end * position denotes the next character of the region manipulated by * this edit. The returned value is the result of the following * calculation: * <pre> * getOffset() + getLength(); * </pre> * * @return the exclusive end position */ public final int getExclusiveEnd() { return getOffset() + getLength(); }
/** * Returns the exclusive end position of this edit. The exclusive end * position denotes the next character of the region manipulated by * this edit. The returned value is the result of the following * calculation: * <pre> * getOffset() + getLength(); * </pre> * * @return the exclusive end position */ public final int getExclusiveEnd() { return getOffset() + getLength(); }
@Override public final int getLength() { if (fDefined) return super.getLength(); List<TextEdit> children= internalGetChildren(); if (children == null || children.size() == 0) return 0; // the children are already sorted TextEdit first= children.get(0); TextEdit last= children.get(children.size() - 1); return last.getOffset() - first.getOffset() + last.getLength(); }
private static void restorePositions(Map<TextEdit, TextEdit> editMap) { for (Iterator<TextEdit> iter= editMap.keySet().iterator(); iter.hasNext();) { TextEdit marker= iter.next(); TextEdit edit= editMap.get(marker); if (marker.isDeleted()) { edit.markAsDeleted(); } else { edit.adjustOffset(marker.getOffset() - edit.getOffset()); edit.adjustLength(marker.getLength() - edit.getLength()); } } } }
private static void restorePositions(Map<TextEdit, TextEdit> editMap) { for (Entry<TextEdit, TextEdit> entry: editMap.entrySet()) { TextEdit marker = entry.getKey(); TextEdit edit= entry.getValue(); if (marker.isDeleted()) { edit.markAsDeleted(); } else { edit.adjustOffset(marker.getOffset() - edit.getOffset()); edit.adjustLength(marker.getLength() - edit.getLength()); } } } }
protected static boolean covers(TextEdit thisEdit, TextEdit otherEdit) { if (thisEdit.getLength() == 0) // an insertion point can't cover anything return false; int thisOffset= thisEdit.getOffset(); int thisEnd= thisEdit.getExclusiveEnd(); if (otherEdit.getLength() == 0) { int otherOffset= otherEdit.getOffset(); return thisOffset < otherOffset && otherOffset < thisEnd; } int otherOffset= otherEdit.getOffset(); int otherEnd= otherEdit.getExclusiveEnd(); return thisOffset <= otherOffset && otherEnd <= thisEnd; }
protected static boolean covers(TextEdit thisEdit, TextEdit otherEdit) { if (thisEdit.getLength() == 0) // an insertion point can't cover anything return false; int thisOffset = thisEdit.getOffset(); int thisEnd = thisEdit.getExclusiveEnd(); if (otherEdit.getLength() == 0) { int otherOffset = otherEdit.getOffset(); return thisOffset < otherOffset && otherOffset < thisEnd; } int otherOffset = otherEdit.getOffset(); int otherEnd = otherEdit.getExclusiveEnd(); return thisOffset <= otherOffset && otherEnd <= thisEnd; }
protected static boolean covers(TextEdit thisEdit, TextEdit otherEdit) { if (thisEdit.getLength() == 0) // an insertion point can't cover anything return false; int thisOffset = thisEdit.getOffset(); int thisEnd = thisEdit.getExclusiveEnd(); if (otherEdit.getLength() == 0) { int otherOffset = otherEdit.getOffset(); return thisOffset < otherOffset && otherOffset < thisEnd; } int otherOffset = otherEdit.getOffset(); int otherEnd = otherEdit.getExclusiveEnd(); return thisOffset <= otherOffset && otherEnd <= thisEnd; }
private static boolean covers(TextEdit thisEdit, TextEdit otherEdit) { if (thisEdit.getLength() == 0) // an insertion point can't cover anything return false; int thisOffset= thisEdit.getOffset(); int thisEnd= thisEdit.getExclusiveEnd(); if (otherEdit.getLength() == 0) { int otherOffset= otherEdit.getOffset(); return thisOffset < otherOffset && otherOffset < thisEnd; } else { int otherOffset= otherEdit.getOffset(); int otherEnd= otherEdit.getExclusiveEnd(); return thisOffset <= otherOffset && otherEnd <= thisEnd; } }
private static boolean covers(TextEdit thisEdit, TextEdit otherEdit) { if (thisEdit.getLength() == 0) // an insertion point can't cover anything return false; int thisOffset= thisEdit.getOffset(); int thisEnd= thisEdit.getExclusiveEnd(); if (otherEdit.getLength() == 0) { int otherOffset= otherEdit.getOffset(); return thisOffset < otherOffset && otherOffset < thisEnd; } else { int otherOffset= otherEdit.getOffset(); int otherEnd= otherEdit.getExclusiveEnd(); return thisOffset <= otherOffset && otherEnd <= thisEnd; } }
private static boolean covers(TextEdit thisEdit, TextEdit otherEdit) { if (thisEdit.getLength() == 0) // an insertion point can't cover anything return false; int thisOffset= thisEdit.getOffset(); int thisEnd= thisEdit.getExclusiveEnd(); if (otherEdit.getLength() == 0) { int otherOffset= otherEdit.getOffset(); return thisOffset < otherOffset && otherOffset < thisEnd; } else { int otherOffset= otherEdit.getOffset(); int otherEnd= otherEdit.getExclusiveEnd(); return thisOffset <= otherOffset && otherEnd <= thisEnd; } }
private static boolean covers(TextEdit thisEdit, TextEdit otherEdit) { if (thisEdit.getLength() == 0) // an insertion point can't cover anything return false; int thisOffset= thisEdit.getOffset(); int thisEnd= thisEdit.getExclusiveEnd(); if (otherEdit.getLength() == 0) { int otherOffset= otherEdit.getOffset(); return thisOffset < otherOffset && otherOffset < thisEnd; } else { int otherOffset= otherEdit.getOffset(); int otherEnd= otherEdit.getExclusiveEnd(); return thisOffset <= otherOffset && otherEnd <= thisEnd; } }
private static void createEdit(TextEdit source, TextEdit target, Map<TextEdit, TextEdit> editMap) { TextEdit[] children= source.getChildren(); for (TextEdit child : children) { // a deleted child remains deleted even if the temporary buffer // gets modified. if (child.isDeleted()) continue; RangeMarker marker= new RangeMarker(child.getOffset(), child.getLength()); target.addChild(marker); editMap.put(marker, child); createEdit(child, marker, editMap); } }
private static void createEdit(TextEdit source, TextEdit target, Map<TextEdit, TextEdit> editMap) { TextEdit[] children= source.getChildren(); for (int i= 0; i < children.length; i++) { TextEdit child= children[i]; // a deleted child remains deleted even if the temporary buffer // gets modified. if (child.isDeleted()) continue; RangeMarker marker= new RangeMarker(child.getOffset(), child.getLength()); target.addChild(marker); editMap.put(marker, child); createEdit(child, marker, editMap); } }
private static org.eclipse.lsp4j.TextEdit convertEdit(TextEdit edit, IDocument document) { org.eclipse.lsp4j.TextEdit textEdit = new org.eclipse.lsp4j.TextEdit(); if (edit instanceof ReplaceEdit) { ReplaceEdit replaceEdit = (ReplaceEdit) edit; textEdit.setNewText(replaceEdit.getText()); int offset = edit.getOffset(); textEdit.setRange(new Range(createPosition(document, offset), createPosition(document, offset + edit.getLength()))); } return textEdit; }