Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add handle moved signal to split panel #301

Merged
merged 4 commits into from
May 11, 2022
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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(undefined);
afshin marked this conversation as resolved.
Show resolved Hide resolved

// 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