Skip to content

Commit 53d0e62

Browse files
committedSep 30, 2020
Reduce the number of spurious documentHighlights requests
1 parent 738553d commit 53d0e62

File tree

3 files changed

+39
-3
lines changed

3 files changed

+39
-3
lines changed
 

‎dist/main/atom/occurrence/controller.js

+20-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎dist/main/atom/occurrence/controller.js.map

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎lib/main/atom/occurrence/controller.ts

+18-1
Original file line numberDiff line numberDiff line change
@@ -12,15 +12,32 @@ export class OccurenceController {
1212

1313
constructor(private getClient: GetClientFunction, private editor: TextEditor) {
1414
let debouncedUpdate: DebouncedFunc<() => void>
15+
let didChangeTimeout: number | undefined
16+
let changeDelay: number
17+
let shouldHighlight: boolean = false
1518
this.disposables.add(
1619
atom.config.observe("atom-typescript.ocurrenceHighlightDebounceTimeout", (val) => {
1720
debouncedUpdate = debounce(() => {
1821
handlePromise(this.update())
1922
}, val)
23+
changeDelay = val * 3.5
24+
}),
25+
editor.onDidChangeCursorPosition(() => {
26+
if (didChangeTimeout === undefined) debouncedUpdate()
27+
else shouldHighlight = true
2028
}),
21-
editor.onDidChangeCursorPosition(() => debouncedUpdate()),
2229
editor.onDidChangePath(() => debouncedUpdate()),
2330
editor.onDidChangeGrammar(() => debouncedUpdate()),
31+
editor.onDidChange(() => {
32+
if (didChangeTimeout !== undefined) clearTimeout(didChangeTimeout)
33+
didChangeTimeout = window.setTimeout(() => {
34+
if (shouldHighlight) {
35+
debouncedUpdate()
36+
shouldHighlight = false
37+
}
38+
didChangeTimeout = undefined
39+
}, changeDelay)
40+
}),
2441
)
2542
}
2643

0 commit comments

Comments
 (0)
Please sign in to comment.