File tree Expand file tree Collapse file tree 2 files changed +34
-1
lines changed Expand file tree Collapse file tree 2 files changed +34
-1
lines changed Original file line number Diff line number Diff line change @@ -15,6 +15,7 @@ import { webLinksHandler } from "./lib/addons";
15
15
import { initiateRemoteCommunicationChannelSocket } from "./lib/remote" ;
16
16
import { Emitter } from '@gitpod/gitpod-protocol/lib/util/event' ;
17
17
import { DisposableCollection } from '@gitpod/gitpod-protocol/lib/util/disposable' ;
18
+ import { debounce } from './lib/helpers' ;
18
19
19
20
const onDidChangeState = new Emitter < void > ( ) ;
20
21
let state : IDEFrontendState = "initializing" as IDEFrontendState ;
@@ -238,7 +239,8 @@ function updateTerminalSize(): void {
238
239
fitAddon . fit ( ) ;
239
240
}
240
241
241
- window . onresize = ( ) => updateTerminalSize ( ) ;
242
+ const debouncedUpdateTerminalSize = debounce ( updateTerminalSize , 200 , true ) ;
243
+ window . onresize = ( ) => debouncedUpdateTerminalSize ( ) ;
242
244
243
245
window . gitpod . ideService = {
244
246
get state ( ) {
Original file line number Diff line number Diff line change
1
+ /**
2
+ * Debounces a function by limiting the rate at which it is called.
3
+ * The debounced function will be called immediately when first called,
4
+ * and then at most once every `wait` milliseconds during subsequent calls.
5
+ * If `trailing` is set to `true`, the function will also be called once
6
+ * after the last event is triggered.
7
+ *
8
+ * @param {() => void } func - The function to be debounced.
9
+ * @param {number } wait - The number of milliseconds to wait before allowing the function to be called again.
10
+ * @param {boolean } trailing - Whether to call the function once after the last event is triggered.
11
+ * @returns {() => void } - The debounced function.
12
+ */
13
+ export const debounce = ( func : ( ) => void , wait : number , trailing : boolean ) : ( ) => void => {
14
+ let timeout : NodeJS . Timeout | null = null ;
15
+
16
+ return ( ) => {
17
+ const later = ( ) => {
18
+ timeout = null ;
19
+ if ( trailing ) {
20
+ func ( ) ;
21
+ }
22
+ } ;
23
+
24
+ if ( timeout === null ) {
25
+ func ( ) ;
26
+ } else {
27
+ clearTimeout ( timeout ) ;
28
+ }
29
+ timeout = setTimeout ( later , wait ) ;
30
+ } ;
31
+ }
You can’t perform that action at this time.
0 commit comments