Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Move DocumentOrShadowRoot.getSelection to Document.getSelection #3037

Merged
merged 4 commits into from
Mar 12, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions files/en-us/_redirects.txt
Original file line number Diff line number Diff line change
Expand Up @@ -1928,7 +1928,7 @@
/en-US/docs/DOM/document.getElementsByName /en-US/docs/Web/API/Document/getElementsByName
/en-US/docs/DOM/document.getElementsByTagName /en-US/docs/Web/API/Document/getElementsByTagName
/en-US/docs/DOM/document.getElementsByTagNameNS /en-US/docs/Web/API/Document/getElementsByTagNameNS
/en-US/docs/DOM/document.getSelection /en-US/docs/Web/API/DocumentOrShadowRoot/getSelection
/en-US/docs/DOM/document.getSelection /en-US/docs/Web/API/Document/getSelection
/en-US/docs/DOM/document.hasFocus /en-US/docs/Web/API/Document/hasFocus
/en-US/docs/DOM/document.head /en-US/docs/Web/API/Document/head
/en-US/docs/DOM/document.height /en-US/docs/Web/API/Document/height
Expand Down Expand Up @@ -3297,7 +3297,7 @@
/en-US/docs/Document_Object_Model_(DOM)/document.getElementsByName /en-US/docs/Web/API/Document/getElementsByName
/en-US/docs/Document_Object_Model_(DOM)/document.getElementsByTagName /en-US/docs/Web/API/Document/getElementsByTagName
/en-US/docs/Document_Object_Model_(DOM)/document.getElementsByTagNameNS /en-US/docs/Web/API/Document/getElementsByTagNameNS
/en-US/docs/Document_Object_Model_(DOM)/document.getSelection /en-US/docs/Web/API/DocumentOrShadowRoot/getSelection
/en-US/docs/Document_Object_Model_(DOM)/document.getSelection /en-US/docs/Web/API/Document/getSelection
/en-US/docs/Document_Object_Model_(DOM)/document.hasFocus /en-US/docs/Web/API/Document/hasFocus
/en-US/docs/Document_Object_Model_(DOM)/document.head /en-US/docs/Web/API/Document/head
/en-US/docs/Document_Object_Model_(DOM)/document.height /en-US/docs/Web/API/Document/height
Expand Down Expand Up @@ -7516,7 +7516,6 @@
/en-US/docs/Web/API/Document/elementFromPoint /en-US/docs/Web/API/DocumentOrShadowRoot/elementFromPoint
/en-US/docs/Web/API/Document/elementsFromPoint /en-US/docs/Web/API/DocumentOrShadowRoot/elementsFromPoint
/en-US/docs/Web/API/Document/firstElementChild /en-US/docs/Web/API/ParentNode/firstElementChild
/en-US/docs/Web/API/Document/getSelection /en-US/docs/Web/API/DocumentOrShadowRoot/getSelection
/en-US/docs/Web/API/Document/inputEncoding /en-US/docs/Web/API/document/characterSet
/en-US/docs/Web/API/Document/lastElementChild /en-US/docs/Web/API/ParentNode/lastElementChild
/en-US/docs/Web/API/Document/mozCancelFullScreen /en-US/docs/Web/API/Document/exitFullscreen
Expand Down Expand Up @@ -7558,6 +7557,7 @@
/en-US/docs/Web/API/DocumentOrShadowRoot/activeElement /en-US/docs/Web/API/Document/activeElement
/en-US/docs/Web/API/DocumentOrShadowRoot/fullscreenElement /en-US/docs/Web/API/Document/fullscreenElement
/en-US/docs/Web/API/DocumentOrShadowRoot/getAnimations /en-US/docs/Web/API/Document/getAnimations
/en-US/docs/Web/API/DocumentOrShadowRoot/getSelection /en-US/docs/Web/API/Document/getSelection
/en-US/docs/Web/API/DocumentOrShadowRoot/nodeFromPoint /en-US/docs/Web/API/DocumentOrShadowRoot
/en-US/docs/Web/API/DocumentOrShadowRoot/nodesFromPoint /en-US/docs/Web/API/DocumentOrShadowRoot
/en-US/docs/Web/API/DocumentOrShadowRoot/pictureInPictureElement /en-US/docs/Web/API/Document/pictureInPictureElement
Expand Down Expand Up @@ -9307,7 +9307,7 @@
/en-US/docs/Web/API/document.getElementsByName /en-US/docs/Web/API/Document/getElementsByName
/en-US/docs/Web/API/document.getElementsByTagName /en-US/docs/Web/API/Document/getElementsByTagName
/en-US/docs/Web/API/document.getElementsByTagNameNS /en-US/docs/Web/API/Document/getElementsByTagNameNS
/en-US/docs/Web/API/document.getSelection /en-US/docs/Web/API/DocumentOrShadowRoot/getSelection
/en-US/docs/Web/API/document.getSelection /en-US/docs/Web/API/Document/getSelection
/en-US/docs/Web/API/document.hasFocus /en-US/docs/Web/API/Document/hasFocus
/en-US/docs/Web/API/document.head /en-US/docs/Web/API/Document/head
/en-US/docs/Web/API/document.height /en-US/docs/Web/API/Document/height
Expand Down
26 changes: 13 additions & 13 deletions files/en-us/_wikihistory.json
Original file line number Diff line number Diff line change
Expand Up @@ -44334,19 +44334,6 @@
"jpmedley"
]
},
"Web/API/DocumentOrShadowRoot/getSelection": {
"modified": "2020-10-15T21:49:28.182Z",
"contributors": [
"mfuji09",
"chrisdavidmills",
"ExE-Boss",
"nmaxcom",
"jpmedley",
"fscholz",
"bede",
"david_ross"
]
},
"Web/API/DocumentTimeline": {
"modified": "2020-10-15T21:45:09.763Z",
"contributors": [
Expand Down Expand Up @@ -165787,5 +165774,18 @@
"chrisdavidmills",
"rachelnabors"
]
},
"Web/API/Document/getSelection": {
"modified": "2020-10-15T21:49:28.182Z",
"contributors": [
"mfuji09",
"chrisdavidmills",
"ExE-Boss",
"nmaxcom",
"jpmedley",
"fscholz",
"bede",
"david_ross"
]
}
}
2 changes: 1 addition & 1 deletion files/en-us/mozilla/firefox/releases/57/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ <h4 id="DOM">DOM</h4>
<li>The {{DOMxRef("Selection.type")}} property of the <a href="/en-US/docs/Web/API/Selection">Selection API</a> is now implemented ({{bug(1359157)}}).</li>
<li>{{DOMxRef("Document.createEvent", "Document.createEvent('FocusEvent')")}} is now supported ({{bug(1388069)}}).</li>
<li>The <code>files</code> property of the {{DOMxRef("HTMLInputElement")}} interface is now settable ({{bug(1384030)}}).</li>
<li>The <code>HTMLDocument.getSelection()</code> method has been moved to the {{DOMxRef("DocumentOrShadowRoot/getSelection","Document")}} interface so it is available to XML documents ({{bug(718711)}}).</li>
<li>The <code>HTMLDocument.getSelection()</code> method has been moved to the {{DOMxRef("Document/getSelection","Document")}} interface so it is available to XML documents ({{bug(718711)}}).</li>
<li>The {{Event("messageerror")}} event is now implemented, and can have code run in response to it firing via event handlers implemented on message targets — see {{DOMxRef("MessagePort.onmessageerror")}}, {{DOMxRef("DedicatedWorkerGlobalScope.onmessageerror")}}, {{DOMxRef("Worker.onmessageerror")}}, {{DOMxRef("BroadcastChannel.onmessageerror")}}, and {{DOMxRef("Window.onmessageerror")}} ({{bug(1359017)}}).</li>
<li>When {{DOMxRef("Headers")}} values are iterated over, they are automatically sorted in lexicographical order, and values from duplicate header names are combined ({{bug(1396848)}}).</li>
</ul>
Expand Down
2 changes: 1 addition & 1 deletion files/en-us/mozilla/firefox/releases/8/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ <h3 id="DOM">DOM</h3>
<li>When editing {{ domxref("element.contenteditable") }} areas, exiting a heading by pressing return, or exiting list editing mode by pressing return twice, now returns to paragraph entry mode (that is, paragraphs inside {{ HTMLElement("p") }} blocks) instead of separating lines by {{ HTMLElement("br") }} elements.</li>
<li>Fixed a bug that prevents justification from taking effect properly when applied to the first line in a {{ domxref("element.contenteditable") }} area.</li>
<li>Fixed a bug that caused pressing delete or backspace at the beginning of a {{ domxref("element.contenteditable") }} area to affect the previous <code>contenteditable</code> block if one is present.</li>
<li>{{ domxref("DocumentOrShadowRoot/getSelection", "document.getSelection()") }} now returns the same <code>Selection</code> object as {{ domxref("window.getSelection()") }}, instead of <em>stringifying</em> it.</li>
<li>{{ domxref("Document.getSelection()") }} now returns the same <code>Selection</code> object as {{ domxref("window.getSelection()") }}, instead of <em>stringifying</em> it.</li>
<li>The HTML5 <code>selectionDirection</code> property makes it possible to define the direction of the selection in an editable text.</li>
<li>{{ domxref("HTMLMediaElement") }} now have a <code>seekable</code> property that return a {{ domxref("TimeRanges") }} object.</li>
<li>The {{ domxref("HTMLMediaElement") }}<code>.preload</code> attribute now correctly reflects as an <em>enumerated value</em>.</li>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ <h2 id="Date_handling_improved">Date handling improved</h2>
<h2 id="DOM_changes">DOM changes</h2>
<p>There have been a couple of changes in the DOM that impact add-ons:</p>
<h3 id="Selection_changes">Selection changes</h3>
<p>In the past, {{ domxref("DocumentOrShadowRoot/getSelection", "document.getSelection()") }} was returning a stringified version of the selection instead of the {{ domxref("Selection") }} object itself. This was non-standard behavior, and has been corrected.</p>
<p>In the past, {{ domxref("Document.getSelection()") }} was returning a stringified version of the selection instead of the {{ domxref("Selection") }} object itself. This was non-standard behavior, and has been corrected.</p>
<h3 id="Potential_name_conflicts">Potential name conflicts</h3>
<p>When the DOM File API was added, a new global called {{ domxref("File") }} was added; this can conflict with objects in your scripts. If you have any globals called <code>File</code>, you should rename them.</p>
<p>Similarly, a new global, {{ domxref("ChromeWorker") }}, was introduced to support allowing Workers to be used from chrome code. If by some chance you have any globals with this name, you should rename them.</p>
Expand Down
83 changes: 83 additions & 0 deletions files/en-us/web/api/document/getselection/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
---
title: Document.getSelection()
slug: Web/API/Document/getSelection
tags:
- API
- Document
- Method
- Reference
- getSelection
---
<div>{{APIRef("DOM")}}</div>

<p><span class="seoSummary">The <strong><code>getSelection()</code></strong> property of
the {{DOMxRef("Document")}} interface returns a {{DOMxRef("Selection")}}
object representing the range of text selected by the user, or the current position of
the caret.</span></p>

<h2 id="Syntax">Syntax</h2>

<pre class="brush: js">getSelection()</pre>

<h3 id="Parameters">Parameters</h3>

<p>None.</p>

<h3 id="Returns">Returns</h3>

<p>A {{DOMxRef("Selection")}} object.</p>

<h2 id="Example">Example</h2>

<h3 id="Getting_a_Selection_object">Getting a Selection object</h3>

<pre class="brush:js">
let selection = document.getSelection();
let selRange = selection.getRangeAt(0);
// do stuff with the range

console.log(selection); // Selection object
</pre>

<h3 id="String_representation_of_the_Selection_object">String representation of the Selection object</h3>

<p>Some functions (like {{DOMxRef("Window.alert()")}}) call {{JSxRef("Object.toString", "toString()")}}
automatically and the returned value is passed to the function. As a consequence, this will return the selected text
and not the <code>Selection</code> object:</p>

<pre class="brush:js;">alert(selection);</pre>

<p>However, not all functions call <code>toString()</code> automatically.
To use a <code>Selection</code> object as a string, call its <code>toString()</code> method directly:</p>

<pre class="brush:js;">let selectedText = selection.toString();</pre>

<h2 id="Related_objects">Related objects</h3>

<p>You can call {{domxref("Window.getSelection()")}}, which works identically to
<code>Document.getSelection()</code>.</p>

<p>It is worth noting that currently <code>getSelection()</code> doesn't work on the
content of {{htmlelement("input")}} elements in Firefox.
{{domxref("HTMLInputElement.setSelectionRange()")}}) could be used to work around this.
</p>

<p>Notice also the difference between <em>selection</em> and <em>focus</em>.
{{domxref("Document.activeElement")}} returns the focused element.</p>

<h2 id="Specifications">Specifications</h2>

<table class="standard-table">
<tbody>
<tr>
<th scope="col">Specification</th>
</tr>
<tr>
<td>{{SpecName("Selection API", "#extensions-to-document-interface", "Document.getSelection")}}</td>
</tr>
</tbody>
</table>

<h2 id="Browser_compatibility">Browser compatibility</h2>

<p>{{Compat("api.Document.getSelection")}}</p>
4 changes: 2 additions & 2 deletions files/en-us/web/api/document/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -256,6 +256,8 @@ <h2 id="Methods">Methods</h2>
<dd>Returns a list of elements with the given tag name.</dd>
<dt>{{DOMxRef("Document.getElementsByTagNameNS()")}}</dt>
<dd>Returns a list of elements with the given tag name and namespace.</dd>
<dt>{{DOMxRef("Document.getSelection()")}}</dt>
<dd>Returns a {{DOMxRef('Selection')}} object representing the range of text selected by the user, or the current position of the caret.</dd>
<dt>{{DOMxRef("Document.hasStorageAccess()")}} {{Experimental_Inline}}</dt>
<dd>Returns a {{jsxref("Promise")}} that resolves with a boolean value indicating whether the document has access to its first-party storage.</dd>
<dt>{{DOMxRef("Document.importNode()")}}</dt>
Expand Down Expand Up @@ -340,8 +342,6 @@ <h3 id="Methods_included_from_DocumentOrShadowRoot">Methods included from Docume
<dd>Returns the topmost element at the specified coordinates.</dd>
<dt>{{DOMxRef("DocumentOrShadowRoot.elementsFromPoint()")}}</dt>
<dd>Returns an array of all elements at the specified coordinates.</dd>
<dt>{{DOMxRef("DocumentOrShadowRoot.getSelection()")}}</dt>
<dd>Returns a {{DOMxRef('Selection')}} object representing the range of text selected by the user, or the current position of the caret.</dd>
</dl>

<h2 id="Events">Events</h2>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,6 @@ <h2 id="See_also">See also</h2>

<ul>
<li>{{domxref("Document/selectstart_event", "selectstart")}}</li>
<li>{{domxref("DocumentOrShadowRoot/getSelection", "Document.getSelection")}}</li>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nitpick — this is a method, so should be written with parens after it.

<li>{{domxref("Document.getSelection()")}}</li>
<li>{{domxref("Selection", "Selection")}}</li>
</ul>
107 changes: 0 additions & 107 deletions files/en-us/web/api/documentorshadowroot/getselection/index.html

This file was deleted.