Skip to content

Commit

Permalink
Merge pull request #301 from afshin/split-panel-handle-moved
Browse files Browse the repository at this point in the history
Add handle moved signal to split panel
  • Loading branch information
afshin authored May 11, 2022
2 parents 401075a + dd82675 commit 9c2948e
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 1 deletion.
13 changes: 13 additions & 0 deletions packages/widgets/src/splitpanel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ import { Drag } from '@lumino/dragdrop';

import { Message } from '@lumino/messaging';

import { ISignal, Signal } from '@lumino/signaling';

import { Panel } from './panel';

import { SplitLayout } from './splitlayout';
Expand Down Expand Up @@ -110,6 +112,13 @@ export class SplitPanel extends Panel {
return (this.layout as SplitLayout).renderer;
}

/**
* A signal emitted when a split handle has moved.
*/
get handleMoved(): ISignal<this, void> {
return this._handleMoved;
}

/**
* A read-only array of the split handles in the panel.
*/
Expand Down Expand Up @@ -341,6 +350,9 @@ export class SplitPanel extends Panel {
this._pressData.override.dispose();
this._pressData = null;

// Emit the handle moved signal.
this._handleMoved.emit();

// Remove the extra document listeners.
document.removeEventListener('mouseup', this, true);
document.removeEventListener('mousemove', this, true);
Expand All @@ -350,6 +362,7 @@ export class SplitPanel extends Panel {
document.removeEventListener('contextmenu', this, true);
}

private _handleMoved = new Signal<any, void>(this);
private _pressData: Private.IPressData | null = null;
}

Expand Down
31 changes: 31 additions & 0 deletions packages/widgets/tests/src/splitpanel.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,17 @@ const renderer: SplitPanel.IRenderer = {
createHandle: () => document.createElement('div')
};

function dragHandle(panel: LogSplitPanel): void {
MessageLoop.sendMessage(panel, Widget.Msg.UpdateRequest);
let handle = panel.handles[0];
let rect = handle.getBoundingClientRect();
let args = { clientX: rect.left + 1, clientY: rect.top + 1 };
simulate(handle, 'mousedown', args);
args = { clientX: rect.left + 10, clientY: rect.top + 1 };
simulate(document.body, 'mousemove', args);
simulate(document.body, 'mouseup');
}

class LogSplitPanel extends SplitPanel {
events: string[] = [];

Expand Down Expand Up @@ -130,6 +141,26 @@ describe('@lumino/widgets', () => {
});
});

describe('#handleMoved', () => {
it('should be emitted when a handle is moved by the user', done => {
let panel = new LogSplitPanel();
let widgets = [new Widget(), new Widget()];
panel.orientation = 'horizontal';
each(widgets, w => {
w.node.style.minHeight = '40px';
w.node.style.minWidth = '40px';
panel.addWidget(w);
});
panel.setRelativeSizes([40, 80]);
Widget.attach(panel, document.body);
panel.handleMoved.connect((sender, _) => {
expect(sender).to.equal(panel);
done();
});
dragHandle(panel);
});
});

describe('#handles', () => {
it('should get the read-only sequence of the split handles in the panel', () => {
let panel = new SplitPanel();
Expand Down
2 changes: 1 addition & 1 deletion packages/widgets/tests/src/tabbar.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ function startDrag(
// Force an update.
MessageLoop.sendMessage(bar, Widget.Msg.UpdateRequest);
simulateOnNode(tab, 'mousedown');
let called = true;
let called = false;
bar.tabDetachRequested.connect((sender, args) => {
called = true;
});
Expand Down

0 comments on commit 9c2948e

Please sign in to comment.