Skip to content

Commit 3a62827

Browse files
committed
refactor: getDebounceTime
1 parent 9b4ad8d commit 3a62827

File tree

1 file changed

+10
-4
lines changed

1 file changed

+10
-4
lines changed

src/main.ts

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,15 @@ export async function consumeOutlineProvider(provider: OutlineProvider) {
7171
// disposables returned inside onEditorChangedDisposable
7272
let onEditorChangedDisposable: CompositeDisposable | undefined = undefined
7373

74+
/**
75+
* How long to wait for the new changes before updating the outline. A high number will increase the responsiveness of
76+
* the text editor in large files.
77+
*/
78+
function getDebounceTime(editor: TextEditor) {
79+
const largeness = editorLargeness(editor)
80+
return Math.max(largeness / 4, 300) // 1/4 of the line count
81+
}
82+
7483
async function editorChanged(editor?: TextEditor) {
7584
if (editor === undefined) {
7685
return
@@ -85,10 +94,7 @@ async function editorChanged(editor?: TextEditor) {
8594
// the following updates rely on the visibility
8695
await getOutline(editor)
8796

88-
const largeness = editorLargeness(editor as TextEditor)
89-
// How long to wait for the new changes before updating the outline.
90-
// A high number will increase the responsiveness of the text editor in large files.
91-
const updateDebounceTime = Math.max(largeness / 4, 300) // 1/4 of the line count
97+
const updateDebounceTime = getDebounceTime(editor)
9298

9399
const doubouncedGetOutline = debounce(
94100
getOutlintIfVisible as (textEditor: TextEditor) => Promise<void>,

0 commit comments

Comments
 (0)