MCPcopy Index your code
hub / github.com/editablejs/editable / deselectCurrent

Function deselectCurrent

packages/editor/src/utils/clipboard.ts:5–50  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

3import { isDOMHTMLElement } from '@editablejs/models'
4
5const deselectCurrent = () => {
6 const selection = document.getSelection()
7 if (!selection?.rangeCount) {
8 return function () {}
9 }
10 let active: HTMLElement | null = null
11 let activeElement = document.activeElement
12 if (activeElement && activeElement.shadowRoot) {
13 activeElement = activeElement.shadowRoot.activeElement
14 }
15 if (isDOMHTMLElement(activeElement)) {
16 active = activeElement
17 }
18 const ranges: Range[] = []
19 for (var i = 0; i < selection.rangeCount; i++) {
20 ranges.push(selection.getRangeAt(i))
21 }
22 switch (
23 active?.tagName.toUpperCase() // .toUpperCase handles XHTML
24 ) {
25 case 'INPUT':
26 case 'TEXTAREA':
27 active.blur()
28 break
29
30 default:
31 active = null
32 break
33 }
34
35 selection.removeAllRanges()
36 return () => {
37 if (selection.type === 'Caret') {
38 selection.removeAllRanges()
39 }
40
41 if (!selection.rangeCount) {
42 ranges.forEach(range => {
43 selection.addRange(range)
44 })
45 }
46 if (active) {
47 active.focus()
48 }
49 }
50}
51
52export const readClipboardDataByCommand = () => {
53 return new Promise<DataTransfer | null>((resolve, reject) => {

Callers 2

Calls 3

isDOMHTMLElementFunction · 0.90
blurMethod · 0.80
focusMethod · 0.80

Tested by

no test coverage detected