mirror of
https://github.com/jlengrand/webcomponentsjs.git
synced 2026-03-10 08:51:22 +00:00
Merge pull request #421 from nazar-pc/shadowRoot.getSelection-fix
`shadowRoot.getSelection()` method added since it is present in Chromium
This commit is contained in:
@@ -46,7 +46,9 @@
|
||||
unsafeUnwrap(this).removeRange(unwrap(range));
|
||||
},
|
||||
selectAllChildren: function(node) {
|
||||
unsafeUnwrap(this).selectAllChildren(unwrapIfNeeded(node));
|
||||
unsafeUnwrap(this).selectAllChildren(
|
||||
node instanceof ShadowRoot ? unsafeUnwrap(node.host) : unwrapIfNeeded(node)
|
||||
);
|
||||
},
|
||||
toString: function() {
|
||||
return unsafeUnwrap(this).toString();
|
||||
|
||||
@@ -68,6 +68,10 @@
|
||||
elementFromPoint: function(x, y) {
|
||||
return elementFromPoint(this, this.ownerDocument, x, y);
|
||||
},
|
||||
|
||||
getSelection: function() {
|
||||
return document.getSelection();
|
||||
}
|
||||
});
|
||||
|
||||
scope.wrappers.ShadowRoot = ShadowRoot;
|
||||
|
||||
@@ -36,6 +36,30 @@ suite('ShadowRoot', function() {
|
||||
assert.equal(sr2.elementFromPoint(5, 5), null);
|
||||
});
|
||||
|
||||
test('getSelection', function() {
|
||||
div = document.body.appendChild(document.createElement('div'));
|
||||
var sr = div.createShadowRoot();
|
||||
sr.innerHTML = '<a>a</a><b>b</b><c>c</c>';
|
||||
|
||||
var selection = sr.getSelection();
|
||||
selection.selectAllChildren(sr);
|
||||
|
||||
assert.equal(selection.toString(), 'abc');
|
||||
|
||||
assert.isFalse(selection.isCollapsed);
|
||||
assert.equal(selection.rangeCount, 1);
|
||||
|
||||
// https://code.google.com/p/chromium/issues/detail?id=336821
|
||||
if (/WebKit/.test(navigator.userAgent))
|
||||
return;
|
||||
|
||||
assert.equal(selection.anchorNode, div);
|
||||
assert.equal(selection.anchorOffset, 0);
|
||||
|
||||
assert.equal(selection.focusNode, div);
|
||||
assert.equal(selection.focusOffset, 3);
|
||||
});
|
||||
|
||||
test('olderShadowRoot', function() {
|
||||
var host = document.createElement('div');
|
||||
host.innerHTML = '<a>a</a><b>b</b>';
|
||||
|
||||
Reference in New Issue
Block a user