mirror of
https://github.com/overleaf/overleaf.git
synced 2024-11-29 19:03:39 -05:00
Use dispatchTransactions option when creating EditorView (#14743)
Co-authored-by: Tim Down <158919+timdown@users.noreply.github.com> GitOrigin-RevId: ccc43ead570bdf96e47d1d08fc114ddce32d1293
This commit is contained in:
parent
b21e06952e
commit
cf0dc6f132
2 changed files with 35 additions and 24 deletions
|
@ -41,13 +41,13 @@ function CodeMirrorEditor() {
|
||||||
|
|
||||||
const view = new EditorView({
|
const view = new EditorView({
|
||||||
state,
|
state,
|
||||||
dispatch: tr => {
|
dispatchTransactions: trs => {
|
||||||
timer.start(tr)
|
timer.start(trs)
|
||||||
view.update([tr])
|
view.update(trs)
|
||||||
if (isMounted.current) {
|
if (isMounted.current) {
|
||||||
setState(view.state)
|
setState(view.state)
|
||||||
}
|
}
|
||||||
timer.end(tr, view)
|
timer.end(trs, view)
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
viewRef.current = view
|
viewRef.current = view
|
||||||
|
|
|
@ -81,8 +81,8 @@ function isKeypress(userEventType: string | undefined) {
|
||||||
}
|
}
|
||||||
|
|
||||||
export function dispatchTimer(): {
|
export function dispatchTimer(): {
|
||||||
start: (tr: Transaction) => void
|
start: (trs: readonly Transaction[]) => void
|
||||||
end: (tr: Transaction, view: EditorView) => void
|
end: (trs: readonly Transaction[], view: EditorView) => void
|
||||||
} {
|
} {
|
||||||
if (!performanceOptionsSupport) {
|
if (!performanceOptionsSupport) {
|
||||||
return { start: () => {}, end: () => {} }
|
return { start: () => {}, end: () => {} }
|
||||||
|
@ -92,22 +92,30 @@ export function dispatchTimer(): {
|
||||||
let keypressesSinceDomUpdateCount = 0
|
let keypressesSinceDomUpdateCount = 0
|
||||||
const unpaintedKeypressStartTimes: number[] = []
|
const unpaintedKeypressStartTimes: number[] = []
|
||||||
|
|
||||||
const start = (tr: Transaction) => {
|
const start = (trs: readonly Transaction[]) => {
|
||||||
|
const keypressStart = performance.now()
|
||||||
|
|
||||||
|
trs.forEach(tr => {
|
||||||
const userEventType = tr.annotation(Transaction.userEvent)
|
const userEventType = tr.annotation(Transaction.userEvent)
|
||||||
|
|
||||||
if (isKeypress(userEventType)) {
|
if (isKeypress(userEventType)) {
|
||||||
unpaintedKeypressStartTimes.push(performance.now())
|
unpaintedKeypressStartTimes.push(keypressStart)
|
||||||
}
|
}
|
||||||
|
})
|
||||||
|
|
||||||
performance.mark(TIMER_START_NAME)
|
performance.mark(TIMER_START_NAME)
|
||||||
}
|
}
|
||||||
|
|
||||||
const end = (tr: Transaction, view: EditorView) => {
|
const end = (trs: readonly Transaction[], view: EditorView) => {
|
||||||
performance.mark(TIMER_END_NAME)
|
performance.mark(TIMER_END_NAME)
|
||||||
|
|
||||||
|
let anyInputOrDelete = false
|
||||||
|
|
||||||
|
trs.forEach(tr => {
|
||||||
const userEventType = tr.annotation(Transaction.userEvent)
|
const userEventType = tr.annotation(Transaction.userEvent)
|
||||||
|
|
||||||
if (isInputOrDelete(userEventType)) {
|
if (isInputOrDelete(userEventType)) {
|
||||||
|
anyInputOrDelete = true
|
||||||
++userEventsSinceDomUpdateCount
|
++userEventsSinceDomUpdateCount
|
||||||
|
|
||||||
if (isKeypress(userEventType)) {
|
if (isKeypress(userEventType)) {
|
||||||
|
@ -119,7 +127,10 @@ export function dispatchTimer(): {
|
||||||
end: TIMER_END_NAME,
|
end: TIMER_END_NAME,
|
||||||
detail: { userEventType, userEventsSinceDomUpdateCount },
|
detail: { userEventType, userEventsSinceDomUpdateCount },
|
||||||
})
|
})
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
if (anyInputOrDelete) {
|
||||||
// The `key` property ensures that the measurement task is only run once
|
// The `key` property ensures that the measurement task is only run once
|
||||||
// per measure phase
|
// per measure phase
|
||||||
view.requestMeasure({
|
view.requestMeasure({
|
||||||
|
@ -144,7 +155,7 @@ export function dispatchTimer(): {
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
latestDocLength = tr.state.doc.length
|
latestDocLength = trs[trs.length - 1].state.doc.length
|
||||||
}
|
}
|
||||||
|
|
||||||
return { start, end }
|
return { start, end }
|
||||||
|
|
Loading…
Reference in a new issue