diff --git a/dlls/mshtml/tests/dom.c b/dlls/mshtml/tests/dom.c
index 5dc0c4c6a98..a4bc01fa7a9 100644
--- a/dlls/mshtml/tests/dom.c
+++ b/dlls/mshtml/tests/dom.c
@@ -4823,6 +4823,7 @@ static void test_txtrange(IHTMLDocument2 *doc)
IHTMLTxtRange *body_range, *range, *range2;
IHTMLSelectionObject *selection;
IDispatch *disp_range;
+ IHTMLElement *body;
HRESULT hres;
body_range = test_create_body_range(doc);
@@ -5008,6 +5009,16 @@ static void test_txtrange(IHTMLDocument2 *doc)
test_range_moveend(range, characterW, 2, 2);
test_range_text(range, "ab");
+ body = doc_get_body(doc);
+
+ hres = IHTMLTxtRange_moveToElementText(range, body);
+ ok(hres == S_OK, "moveToElementText failed: %08x\n", hres);
+
+ test_range_text(range, "abc xyz abc 123\r\nit's text");
+ test_range_parent(range, ET_BODY);
+
+ IHTMLElement_Release(body);
+
IHTMLTxtRange_Release(range);
}
diff --git a/dlls/mshtml/txtrange.c b/dlls/mshtml/txtrange.c
index 6b57eb27178..886f596a9de 100644
--- a/dlls/mshtml/txtrange.c
+++ b/dlls/mshtml/txtrange.c
@@ -1579,8 +1579,22 @@ static HRESULT WINAPI HTMLTxtRange_pasteHTML(IHTMLTxtRange *iface, BSTR html)
static HRESULT WINAPI HTMLTxtRange_moveToElementText(IHTMLTxtRange *iface, IHTMLElement *element)
{
HTMLTxtRange *This = impl_from_IHTMLTxtRange(iface);
- FIXME("(%p)->(%p)\n", This, element);
- return E_NOTIMPL;
+ HTMLElement *elem;
+ nsresult nsres;
+
+ TRACE("(%p)->(%p)\n", This, element);
+
+ elem = unsafe_impl_from_IHTMLElement(element);
+ if(!elem)
+ return E_INVALIDARG;
+
+ nsres = nsIDOMRange_SelectNodeContents(This->nsrange, elem->node.nsnode);
+ if(NS_FAILED(nsres)) {
+ ERR("SelectNodeContents failed: %08x\n", nsres);
+ return E_FAIL;
+ }
+
+ return S_OK;
}
static HRESULT WINAPI HTMLTxtRange_setEndPoint(IHTMLTxtRange *iface, BSTR how,