@@ -54,6 +54,9 @@ export class ViewModelEventDispatcher extends Disposable {
5454 return ;
5555 }
5656 const event = this . _outgoingEvents . shift ( ) ! ;
57+ if ( event . isNoOp ( ) ) {
58+ continue ;
59+ }
5760 this . _onEvent . fire ( event ) ;
5861 }
5962 }
@@ -143,6 +146,8 @@ export class ViewModelEventDispatcher extends Disposable {
143146
144147export const enum OutgoingViewModelEventKind {
145148 ContentSizeChanged ,
149+ FocusChanged ,
150+ ScrollChanged ,
146151}
147152
148153export class ContentSizeChangedEvent implements IContentSizeChangedEvent {
@@ -166,9 +171,100 @@ export class ContentSizeChangedEvent implements IContentSizeChangedEvent {
166171 this . contentHeightChanged = ( this . _oldContentHeight !== this . contentHeight ) ;
167172 }
168173
169- public merge ( other : ContentSizeChangedEvent ) : ContentSizeChangedEvent {
174+ public isNoOp ( ) : boolean {
175+ return ( ! this . contentWidthChanged && ! this . contentHeightChanged ) ;
176+ }
177+
178+
179+ public merge ( other : OutgoingViewModelEvent ) : ContentSizeChangedEvent {
180+ if ( other . kind !== OutgoingViewModelEventKind . ContentSizeChanged ) {
181+ return this ;
182+ }
170183 return new ContentSizeChangedEvent ( this . _oldContentWidth , this . _oldContentHeight , other . contentWidth , other . contentHeight ) ;
171184 }
172185}
173186
174- export type OutgoingViewModelEvent = ContentSizeChangedEvent ;
187+ export class FocusChangedEvent {
188+
189+ public readonly kind = OutgoingViewModelEventKind . FocusChanged ;
190+
191+ readonly oldHasFocus : boolean ;
192+ readonly hasFocus : boolean ;
193+
194+ constructor ( oldHasFocus : boolean , hasFocus : boolean ) {
195+ this . oldHasFocus = oldHasFocus ;
196+ this . hasFocus = hasFocus ;
197+ }
198+
199+ public isNoOp ( ) : boolean {
200+ return ( this . oldHasFocus === this . hasFocus ) ;
201+ }
202+
203+ public merge ( other : OutgoingViewModelEvent ) : FocusChangedEvent {
204+ if ( other . kind !== OutgoingViewModelEventKind . FocusChanged ) {
205+ return this ;
206+ }
207+ return new FocusChangedEvent ( this . oldHasFocus , other . hasFocus ) ;
208+ }
209+ }
210+
211+ export class ScrollChangedEvent {
212+
213+ public readonly kind = OutgoingViewModelEventKind . ScrollChanged ;
214+
215+ private readonly _oldScrollWidth : number ;
216+ private readonly _oldScrollLeft : number ;
217+ private readonly _oldScrollHeight : number ;
218+ private readonly _oldScrollTop : number ;
219+
220+ public readonly scrollWidth : number ;
221+ public readonly scrollLeft : number ;
222+ public readonly scrollHeight : number ;
223+ public readonly scrollTop : number ;
224+
225+ public readonly scrollWidthChanged : boolean ;
226+ public readonly scrollLeftChanged : boolean ;
227+ public readonly scrollHeightChanged : boolean ;
228+ public readonly scrollTopChanged : boolean ;
229+
230+ constructor (
231+ oldScrollWidth : number , oldScrollLeft : number , oldScrollHeight : number , oldScrollTop : number ,
232+ scrollWidth : number , scrollLeft : number , scrollHeight : number , scrollTop : number ,
233+ ) {
234+ this . _oldScrollWidth = oldScrollWidth ;
235+ this . _oldScrollLeft = oldScrollLeft ;
236+ this . _oldScrollHeight = oldScrollHeight ;
237+ this . _oldScrollTop = oldScrollTop ;
238+
239+ this . scrollWidth = scrollWidth ;
240+ this . scrollLeft = scrollLeft ;
241+ this . scrollHeight = scrollHeight ;
242+ this . scrollTop = scrollTop ;
243+
244+ this . scrollWidthChanged = ( this . _oldScrollWidth !== this . scrollWidth ) ;
245+ this . scrollLeftChanged = ( this . _oldScrollLeft !== this . scrollLeft ) ;
246+ this . scrollHeightChanged = ( this . _oldScrollHeight !== this . scrollHeight ) ;
247+ this . scrollTopChanged = ( this . _oldScrollTop !== this . scrollTop ) ;
248+ }
249+
250+ public isNoOp ( ) : boolean {
251+ return ( ! this . scrollWidthChanged && ! this . scrollLeftChanged && ! this . scrollHeightChanged && ! this . scrollTopChanged ) ;
252+ }
253+
254+
255+ public merge ( other : OutgoingViewModelEvent ) : ScrollChangedEvent {
256+ if ( other . kind !== OutgoingViewModelEventKind . ScrollChanged ) {
257+ return this ;
258+ }
259+ return new ScrollChangedEvent (
260+ this . _oldScrollWidth , this . _oldScrollLeft , this . _oldScrollHeight , this . _oldScrollTop ,
261+ other . scrollWidth , other . scrollLeft , other . scrollHeight , other . scrollTop
262+ ) ;
263+ }
264+ }
265+
266+ export type OutgoingViewModelEvent = (
267+ ContentSizeChangedEvent
268+ | FocusChangedEvent
269+ | ScrollChangedEvent
270+ ) ;
0 commit comments