@Override public <N, E extends N, T extends N> void exec(MutableDocument<N, E, T> doc) { Point<N> point = doc.locate(location); doc.createElement(point, Blips.THREAD_INLINE_ANCHOR_TAGNAME, Collections.singletonMap(Blips.THREAD_INLINE_ANCHOR_ID_ATTR, threadId)); } });
@Override public Point<N> locate(int location) { return getDelegate().locate(location); }
private Point<Node> l(int location) { if (location < 0) { location = doc.size() + location; } return doc.locate(location); }
private Point<Node> l(int location) { if (location < 0) { location = doc.size() + location; } return doc.locate(location); }
private void checkLineRanges(String ... expectedLines) { List<Range> ranges = LineContainers.getLineRanges(doc); assertEquals(expectedLines.length, ranges.size()); int i = 0; for (Range r : ranges) { Point<Node> start = doc.locate(r.getStart()); Point<Node> end = doc.locate(r.getStart()); String expectedLine = expectedLines[i++]; assertEquals(expectedLine, DocHelper.getText(doc, doc, r.getStart(), r.getEnd())); } }
private void checkLineRanges(String ... expectedLines) { List<Range> ranges = LineContainers.getLineRanges(doc); assertEquals(expectedLines.length, ranges.size()); int i = 0; for (Range r : ranges) { Point<Node> start = doc.locate(r.getStart()); Point<Node> end = doc.locate(r.getStart()); String expectedLine = expectedLines[i++]; assertEquals(expectedLine, DocHelper.getText(doc, doc, r.getStart(), r.getEnd())); } }
public void testExtractNormalizedAnnotation() { // a[b{c]d} where [] = link, {} = spell annotation, normalizing over abcd useDocument("<line/>abcd", "link:L:4:6", "spell:S:5:7", "style:Q:1:2"); PasteAnnotationLogic<Node, Element, Text> logic = initDefault(); List<RangedAnnotation<String>> extracted = logic.extractNormalizedAnnotation(doc.locate(3), doc.locate(7)); assertEquals(4, extracted.size()); checkRangedAnnotation(extracted, 0, 4, STYLE_KEY, null); // no styles checkRangedAnnotation(extracted, 0, 1, LINK_KEY, null); // before linked bit checkRangedAnnotation(extracted, 1, 3, LINK_KEY, "L"); // linked bit checkRangedAnnotation(extracted, 3, 4, LINK_KEY, null); // after linked bit }
public void testExtractNormalizedAnnotation() { // a[b{c]d} where [] = link, {} = spell annotation, normalizing over abcd useDocument("<line/>abcd", "link:L:4:6", "spell:S:5:7", "style:Q:1:2"); PasteAnnotationLogic<Node, Element, Text> logic = initDefault(); List<RangedAnnotation<String>> extracted = logic.extractNormalizedAnnotation(doc.locate(3), doc.locate(7)); assertEquals(4, extracted.size()); checkRangedAnnotation(extracted, 0, 4, STYLE_KEY, null); // no styles checkRangedAnnotation(extracted, 0, 1, LINK_KEY, null); // before linked bit checkRangedAnnotation(extracted, 1, 3, LINK_KEY, "L"); // linked bit checkRangedAnnotation(extracted, 3, 4, LINK_KEY, null); // after linked bit }
public <N, E extends N, T extends N> void exec(MutableDocument<N, E, T> doc) { E anchor = Point.elementAfter(doc, doc.locate(location)); E anchorParent = doc.getParentElement(anchor); doc.createChildElement(anchorParent, doc.getTagName(anchor), doc.getAttributes(anchor)); } });
public <N, E extends N, T extends N> void exec(MutableDocument<N, E, T> doc) { E anchor = Point.elementAfter(doc, doc.locate(location)); E anchorParent = doc.getParentElement(anchor); doc.createChildElement(anchorParent, doc.getTagName(anchor), doc.getAttributes(anchor)); } });
public <N, E extends N, T extends N> void exec(MutableDocument<N, E, T> doc) { Point<N> startText = doc.locate(locateAfterLineElement(doc)); doc.insertText(startText, "cd"); // Insert reply between c|d. N bodyNode = DocHelper.getElementWithTagName(doc, Blips.BODY_TAGNAME); N textNode = doc.getFirstChild(bodyNode); textNode = doc.getNextSibling(textNode); int replyLocation = doc.getLocation(Point.inText(textNode, 1)); blip.addReplyThread(replyLocation); // Insert text to give abc|d startText = Point.before(doc, textNode); doc.insertText(startText, "ab"); int newLocation = blip.locateReplyThreads().iterator().next().getLocation(); assertEquals(replyLocation + 2, newLocation); } });
public <N, E extends N, T extends N> void exec(MutableDocument<N, E, T> doc) { Point<N> startText = doc.locate(locateAfterLineElement(doc)); doc.insertText(startText, "cd"); // Insert reply between c|d. N bodyNode = DocHelper.getElementWithTagName(doc, Blips.BODY_TAGNAME); N textNode = doc.getFirstChild(bodyNode); textNode = doc.getNextSibling(textNode); int replyLocation = doc.getLocation(Point.inText(textNode, 1)); ConversationThread replyThread = blip.addReplyThread(replyLocation); // Delete text and anchor. doc.deleteRange(Point.before(doc, textNode), Point.inElement(bodyNode, null)); int newLocation = blip.locateReplyThreads().iterator().next().getLocation(); assertEquals(Blips.INVALID_INLINE_LOCATION, newLocation); } });
public <N, E extends N, T extends N> void exec(MutableDocument<N, E, T> doc) { Point<N> startText = doc.locate(locateAfterLineElement(doc)); doc.insertText(startText, "cd"); // Insert reply between c|d. N bodyNode = DocHelper.getElementWithTagName(doc, Blips.BODY_TAGNAME); N textNode = doc.getFirstChild(bodyNode); textNode = doc.getNextSibling(textNode); int replyLocation = doc.getLocation(Point.inText(textNode, 1)); blip.addReplyThread(replyLocation); // Insert text to give abc|d startText = Point.before(doc, textNode); doc.insertText(startText, "ab"); int newLocation = blip.locateReplyThreads().iterator().next().getLocation(); assertEquals(replyLocation + 2, newLocation); } });
public <N, E extends N, T extends N> void exec(MutableDocument<N, E, T> doc) { Point<N> startText = doc.locate(locateAfterLineElement(doc)); doc.insertText(startText, "cd"); // Insert reply between c|d. N bodyNode = DocHelper.getElementWithTagName(doc, Blips.BODY_TAGNAME); N textNode = doc.getFirstChild(bodyNode); textNode = doc.getNextSibling(textNode); int replyLocation = doc.getLocation(Point.inText(textNode, 1)); ConversationThread replyThread = blip.addReplyThread(replyLocation); // Delete text and anchor. doc.deleteRange(Point.before(doc, textNode), Point.inElement(bodyNode, null)); int newLocation = blip.locateReplyThreads().iterator().next().getLocation(); assertEquals(Blips.INVALID_INLINE_LOCATION, newLocation); } });
/** Check that a collapsed range in the middle behaves correctly. */ public void testCollapsedRange() { String initialContent = "abc"; TestDocumentContext<Node, Element, Text> test = ContextProviders.createTestPojoContext( DocProviders.POJO.parse(initialContent).asOperation(), null, null, null, DocumentSchema.NO_SCHEMA_CONSTRAINTS); MutableDocument<Node, Element, Text> doc = test.document(); RangeTracker tracker = new RangeTracker(test.localAnnotations()); // collapsed at the start, through mutation: tracker.trackRange(new Range(2, 2)); assertEquals(new Range(2, 2), tracker.getRange()); doc.insertText(doc.locate(0), "a"); assertEquals(new Range(3, 3), tracker.getRange()); doc.insertText(doc.locate(4), "b"); assertEquals(new Range(3, 3), tracker.getRange()); doc.insertText(doc.locate(3), "c"); assertEquals(new Range(4, 4), tracker.getRange()); }
/** Check that a collapsed range at 0 behaves correctly. */ public void testCollapsedStartRange() { String initialContent = "abc"; TestDocumentContext<Node, Element, Text> test = ContextProviders.createTestPojoContext( DocProviders.POJO.parse(initialContent).asOperation(), null, null, null, DocumentSchema.NO_SCHEMA_CONSTRAINTS); MutableDocument<Node, Element, Text> doc = test.document(); RangeTracker tracker = new RangeTracker(test.localAnnotations()); // collapsed at the start, through mutation: tracker.trackRange(new Range(0, 0)); assertEquals(new Range(0, 0), tracker.getRange()); doc.insertText(doc.locate(3), "a"); assertEquals(new Range(0, 0), tracker.getRange()); doc.insertText(doc.locate(0), "x"); assertEquals(new Range(1, 1), tracker.getRange()); }
/** Check that a collapsed range at 0 behaves correctly. */ public void testCollapsedStartRange() { String initialContent = "abc"; TestDocumentContext<Node, Element, Text> test = ContextProviders.createTestPojoContext( DocProviders.POJO.parse(initialContent).asOperation(), null, null, null, DocumentSchema.NO_SCHEMA_CONSTRAINTS); MutableDocument<Node, Element, Text> doc = test.document(); RangeTracker tracker = new RangeTracker(test.localAnnotations()); // collapsed at the start, through mutation: tracker.trackRange(new Range(0, 0)); assertEquals(new Range(0, 0), tracker.getRange()); doc.insertText(doc.locate(3), "a"); assertEquals(new Range(0, 0), tracker.getRange()); doc.insertText(doc.locate(0), "x"); assertEquals(new Range(1, 1), tracker.getRange()); }
/** Check that a collapsed range over the document behaves correctly. */ public void testEntireCoverRanges() { String initialContent = "abc"; TestDocumentContext<Node, Element, Text> test = ContextProviders.createTestPojoContext( DocProviders.POJO.parse(initialContent).asOperation(), null, null, null, DocumentSchema.NO_SCHEMA_CONSTRAINTS); MutableDocument<Node, Element, Text> doc = test.document(); RangeTracker tracker = new RangeTracker(test.localAnnotations()); // entire range through mutation at middle, end, start tracker.trackRange(new Range(0, doc.size())); assertEquals(new Range(0, doc.size()), tracker.getRange()); doc.insertText(doc.locate(1), "a"); assertEquals(new Range(0, doc.size()), tracker.getRange()); doc.insertText(doc.locate(doc.size()), "b"); assertEquals(new Range(0, doc.size()), tracker.getRange()); doc.insertText(doc.locate(0), "c"); assertEquals(new Range(1, doc.size()), tracker.getRange()); }
/** Check that a collapsed range at doc.size() behaves correctly. */ public void testCollapsedEndRange() { String initialContent = "abc"; TestDocumentContext<Node, Element, Text> test = ContextProviders.createTestPojoContext( DocProviders.POJO.parse(initialContent).asOperation(), null, null, null, DocumentSchema.NO_SCHEMA_CONSTRAINTS); MutableDocument<Node, Element, Text> doc = test.document(); RangeTracker tracker = new RangeTracker(test.localAnnotations()); int end = doc.size(); // collapsed at the start, through mutation: tracker.trackRange(new Range(end, end)); assertEquals(new Range(end, end), tracker.getRange()); doc.insertText(doc.locate(3), "a"); assertEquals(new Range(end + 1, end + 1), tracker.getRange()); doc.insertText(doc.locate(doc.size()), "x"); assertEquals(new Range(end + 2, end + 2), tracker.getRange()); }
/** Check that a collapsed range at doc.size() behaves correctly. */ public void testCollapsedEndRange() { String initialContent = "abc"; TestDocumentContext<Node, Element, Text> test = ContextProviders.createTestPojoContext( DocProviders.POJO.parse(initialContent).asOperation(), null, null, null, DocumentSchema.NO_SCHEMA_CONSTRAINTS); MutableDocument<Node, Element, Text> doc = test.document(); RangeTracker tracker = new RangeTracker(test.localAnnotations()); int end = doc.size(); // collapsed at the start, through mutation: tracker.trackRange(new Range(end, end)); assertEquals(new Range(end, end), tracker.getRange()); doc.insertText(doc.locate(3), "a"); assertEquals(new Range(end + 1, end + 1), tracker.getRange()); doc.insertText(doc.locate(doc.size()), "x"); assertEquals(new Range(end + 2, end + 2), tracker.getRange()); }