MCPcopy Create free account
hub / github.com/krasimir/react-in-patterns / getSelection

Function getSelection

code/new-context-api/public/app.js:5988–6003  ·  view source on GitHub ↗

* Get an object which is a unique representation of the current selection. * * The return value will not be consistent across nodes or browsers, but * two identical selections on the same node will return identical objects. * * @param {DOMElement} node * @return {object}

(node)

Source from the content-addressed store, hash-verified

5986 * @return {object}
5987 */
5988function getSelection(node) {
5989 if ('selectionStart' in node && hasSelectionCapabilities(node)) {
5990 return {
5991 start: node.selectionStart,
5992 end: node.selectionEnd
5993 };
5994 } else if (window.getSelection) {
5995 var selection = window.getSelection();
5996 return {
5997 anchorNode: selection.anchorNode,
5998 anchorOffset: selection.anchorOffset,
5999 focusNode: selection.focusNode,
6000 focusOffset: selection.focusOffset
6001 };
6002 }
6003}
6004
6005/**
6006 * Poll selection to see whether it's changed.

Callers 1

constructSelectEventFunction · 0.70

Calls 1

hasSelectionCapabilitiesFunction · 0.70

Tested by

no test coverage detected