@@ -203,17 +203,20 @@ export class DashboardLayout extends Layout {
203203 widget . mode = 'present' ;
204204 }
205205 this . attachWidget ( widget ) ;
206- this . _moveWidget ( widget , _pos ) ;
207- this . _outputTracker . add ( widget ) ;
206+ // if (widget.mode !== 'grid') {
207+ // this._moveWidget(widget, _pos, false);
208+ // this._outputTracker.add(widget);
209+ // }
208210
209211 const { id, notebookId, cellId } = widget ;
210212
211213 const ignore = ! this . _signalChanges ;
212214
213215 widget . ready . connect ( ( ) => {
214- if ( widget . mode === 'grid' ) {
215- this . _moveWidget ( widget , widget . pos ) ;
216- }
216+ this . _moveWidget ( widget , widget . pos , false ) ;
217+ this . fixOverlaps ( widget ) ;
218+ this . _outputTracker . add ( widget ) ;
219+
217220 const change : IDashboardChange = {
218221 type : 'add' ,
219222 pos : widget . pos ,
@@ -240,9 +243,10 @@ export class DashboardLayout extends Layout {
240243
241244 private _updateWidget (
242245 widget : DashboardWidget ,
243- pos : Widgetstore . WidgetPosition
246+ pos : Widgetstore . WidgetPosition ,
247+ fixOverlaps = true
244248 ) : boolean {
245- const success = this . _moveWidget ( widget , pos ) ;
249+ const success = this . _moveWidget ( widget , pos , fixOverlaps ) ;
246250 if ( success ) {
247251 const change : IDashboardChange = {
248252 type : 'move' ,
@@ -256,7 +260,8 @@ export class DashboardLayout extends Layout {
256260
257261 private _moveWidget (
258262 widget : DashboardWidget ,
259- pos : Widgetstore . WidgetPosition
263+ pos : Widgetstore . WidgetPosition ,
264+ fixOverlaps = true
260265 ) : boolean {
261266 // Get the item from the map.
262267 const item = this . _items . get ( widget . id ) ;
@@ -290,25 +295,13 @@ export class DashboardLayout extends Layout {
290295 item . update ( 0 , 0 , 0 , 0 ) ;
291296 }
292297
293- // const oldWidgets = this._widgetsInSelection({ left, top, width, height });
294-
295- // console.log(
296- // 'old widgets',
297- // toArray(filter(oldWidgets, (w) => w.widget.id !== widget.id))
298- // );
299-
300- const newPos : Widgetstore . WidgetPosition = { left, top, width, height } ;
298+ this . clearCanvas ( ) ;
301299
302300 item . update ( left , top , width , height ) ;
303301
304- const overlaps = filter (
305- this . _widgetsInSelection ( newPos ) ,
306- ( overlap ) => overlap . widget !== widget
307- ) ;
308-
309- widget . locked = true ;
310- this . handleOverlaps ( overlaps , newPos ) ;
311- widget . locked = false ;
302+ if ( fixOverlaps ) {
303+ this . fixOverlaps ( widget ) ;
304+ }
312305
313306 return true ;
314307 }
@@ -354,6 +347,8 @@ export class DashboardLayout extends Layout {
354347 this . detachWidget ( - 1 , widget ) ;
355348 }
356349
350+ this . clearCanvas ( ) ;
351+
357352 // Dispose the layout item.
358353 item . dispose ( ) ;
359354
@@ -515,6 +510,16 @@ export class DashboardLayout extends Layout {
515510 newPos . top = 0 ;
516511 this . _expandCanvas ( type , adjust ) ;
517512 }
513+ const heightDiff = newPos . top + newPos . height - this . height ;
514+ if ( heightDiff > 0 ) {
515+ adjust = heightDiff ;
516+ this . _expandCanvas ( type , adjust ) ;
517+ }
518+ const widthDiff = newPos . left + newPos . width - this . width ;
519+ if ( widthDiff > 0 ) {
520+ adjust = widthDiff ;
521+ this . _expandCanvas ( type , adjust ) ;
522+ }
518523
519524 this . _moveWidget ( widget , newPos ) ;
520525 }
@@ -526,6 +531,17 @@ export class DashboardLayout extends Layout {
526531 each ( overlaps , ( overlap ) => void this . _handleOverlap ( pos , overlap ) ) ;
527532 }
528533
534+ fixOverlaps ( widget : DashboardWidget ) {
535+ const overlaps = filter (
536+ this . _widgetsInSelection ( widget . pos ) ,
537+ ( overlap ) => overlap . widget !== widget
538+ ) ;
539+
540+ widget . locked = true ;
541+ this . handleOverlaps ( overlaps , widget . pos ) ;
542+ widget . locked = false ;
543+ }
544+
529545 private _expandCanvas (
530546 direction : DashboardWidget . Direction ,
531547 amount : number
0 commit comments