expect(c.doc().children()[2].getText()).to.equal(' cat');
});
});
+
+ describe('getting vertically first text element', function() {
+ it('returns the first child if it\'s text element, ignores metadata', function() {
+ var c = canvas.fromXML('<section><metadata><dc:author>author</dc:author></metadata>Alice<div>has</div>a cat</section>'),
+ first = c.doc().getVerticallyFirstTextElement();
+
+ expect(first.sameNode(c.doc().children()[1])).to.be.true;
+ });
+
+ it('looks recursively inside node elements if they precede text element', function() {
+ var c = canvas.fromXML('\
+ <section>\
+ <div>\
+ <div>\
+ Alice\
+ </div>\
+ </div>\
+ Some text\
+ </section>'),
+ textAlice = c.doc().children()[0].children()[0].children()[0],
+ first = c.doc().getVerticallyFirstTextElement();
+
+ expect(textAlice).to.be.instanceOf(documentElement.DocumentTextElement);
+ expect(first.sameNode(textAlice)).to.be.true;
+ });
+ });
});
describe('manipulation api', function() {
markAsCurrent: function() {
this.canvas.markAsCurrent(this);
+ },
+
+ getVerticallyFirstTextElement: function() {
+ var toret;
+ this.children().some(function(child) {
+ if(!child.isVisible())
+ return false; // continue
+ if(child instanceof DocumentTextElement) {
+ toret = child;
+ return true; // break
+ } else {
+ toret = child.getVerticallyFirstTextElement();
+ if(toret)
+ return true; // break
+ }
+ });
+ return toret;
+ },
+
+ isVisible: function() {
+ return this instanceof DocumentTextElement || this.getWlxmlTag() !== 'metadata';
}
});
canvasWrapper.onShow = function() {
if(!shownAlready) {
shownAlready = true;
+ canvas.setCurrentElement(canvas.doc().getVerticallyFirstTextElement());
} else {
canvas.setCursorPosition(cursorPosition);
this.find('#rng-module-documentCanvas-contentWrapper').scrollTop(scrollbarPosition);