Skip to content

Commit e732ee9

Browse files
authored
Merge branch 'main' into pr/improve-tab-performance
2 parents 543e212 + 9dd3985 commit e732ee9

File tree

3 files changed

+43
-37
lines changed

3 files changed

+43
-37
lines changed

src/document/selection.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ export function setUISelection(
101101
const anchorOffset =
102102
mode === 'replace' || element[UISelection] === undefined
103103
? sanitizeOffset(anchorOffsetParam)
104-
: (element[UISelection] as UISelection).anchorOffset
104+
: element[UISelection].anchorOffset
105105
const focusOffset = sanitizeOffset(focusOffsetParam)
106106

107107
const startOffset = Math.min(anchorOffset, focusOffset)

src/utils/dataTransfer/Clipboard.ts

Lines changed: 41 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -54,43 +54,50 @@ export function createClipboardItem(
5454
}
5555

5656
const ClipboardStubControl = Symbol('Manage ClipboardSub')
57+
type ClipboardStubControlInstance = {
58+
resetClipboardStub: () => void
59+
detachClipboardStub: () => void
60+
}
5761

58-
function createClipboardStub(window: Window & typeof globalThis) {
59-
return new (class Clipboard extends window.EventTarget {
60-
private items: ClipboardItem[] = []
62+
function createClipboardStub(
63+
window: Window & typeof globalThis,
64+
control: ClipboardStubControlInstance,
65+
) {
66+
return Object.assign(
67+
new (class Clipboard extends window.EventTarget {
68+
private items: ClipboardItem[] = []
6169

62-
async read() {
63-
return Array.from(this.items)
64-
}
70+
async read() {
71+
return Array.from(this.items)
72+
}
6573

66-
async readText() {
67-
let text = ''
68-
for (const item of this.items) {
69-
const type = item.types.includes('text/plain')
70-
? 'text/plain'
71-
: item.types.find(t => t.startsWith('text/'))
72-
if (type) {
73-
text += await item
74-
.getType(type)
75-
.then(b => readBlobText(b, window.FileReader))
74+
async readText() {
75+
let text = ''
76+
for (const item of this.items) {
77+
const type = item.types.includes('text/plain')
78+
? 'text/plain'
79+
: item.types.find(t => t.startsWith('text/'))
80+
if (type) {
81+
text += await item
82+
.getType(type)
83+
.then(b => readBlobText(b, window.FileReader))
84+
}
7685
}
86+
return text
7787
}
78-
return text
79-
}
80-
81-
async write(data: ClipboardItem[]) {
82-
this.items = data
83-
}
8488

85-
async writeText(text: string) {
86-
this.items = [createClipboardItem(window, text)]
87-
}
89+
async write(data: ClipboardItem[]) {
90+
this.items = data
91+
}
8892

89-
[ClipboardStubControl]: {
90-
resetClipboardStub: () => void
91-
detachClipboardStub: () => void
92-
}
93-
})()
93+
async writeText(text: string) {
94+
this.items = [createClipboardItem(window, text)]
95+
}
96+
})(),
97+
{
98+
[ClipboardStubControl]: control,
99+
},
100+
)
94101
}
95102
type ClipboardStub = ReturnType<typeof createClipboardStub>
96103

@@ -112,11 +119,10 @@ export function attachClipboardStubToView(window: Window & typeof globalThis) {
112119
'clipboard',
113120
)
114121

115-
let stub = createClipboardStub(window)
116-
const control = {
122+
let stub: ClipboardStub
123+
const control: ClipboardStubControlInstance = {
117124
resetClipboardStub: () => {
118-
stub = createClipboardStub(window)
119-
stub[ClipboardStubControl] = control
125+
stub = createClipboardStub(window, control)
120126
},
121127
detachClipboardStub: () => {
122128
/* istanbul ignore if */
@@ -130,7 +136,7 @@ export function attachClipboardStubToView(window: Window & typeof globalThis) {
130136
}
131137
},
132138
}
133-
stub[ClipboardStubControl] = control
139+
stub = createClipboardStub(window, control)
134140

135141
Object.defineProperty(window.navigator, 'clipboard', {
136142
get: () => stub,

src/utils/misc/level.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ declare module '../../setup' {
1717

1818
export function setLevelRef(config: Config, level: ApiLevel) {
1919
config[Level] ??= {}
20-
;(config[Level] as LevelRefs)[level] = {}
20+
config[Level][level] = {}
2121
}
2222

2323
export function getLevelRef(config: Config, level: ApiLevel) {

0 commit comments

Comments
 (0)