From e806bd03ef2bf0da40c6d9d0a3eaf3cb5f9f5aca Mon Sep 17 00:00:00 2001 From: leihaiyong Date: Wed, 12 Jan 2022 18:27:59 +0800 Subject: [PATCH] Add dyn window resizing with debounce. --- public/template/term.template | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/public/template/term.template b/public/template/term.template index 07386b9..8a52730 100644 --- a/public/template/term.template +++ b/public/template/term.template @@ -48,6 +48,18 @@ }) fitAddon.fit(); term.focus(); + + function debounce(f, timeout){ + let t; + return (...args) => { + clearTimeout(t); + t = setTimeout(() => { f.apply(this, args); }, timeout); + }; + }; + + window.addEventListener('resize', debounce(() => { + fitAddon.fit(); + }, 250)); \ No newline at end of file