Skip to content

Commit 1e58fd4

Browse files
committed
CommitBox now correctly updates on changes to marking
1 parent c5b0c4f commit 1e58fd4

File tree

3 files changed

+29
-9
lines changed

3 files changed

+29
-9
lines changed

src/components/FileItemSimple.tsx

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,10 @@ export class GitMarkBox extends React.Component<IGitMarkBoxProps> {
3636
}
3737

3838
protected _onClick(event: React.ChangeEvent<HTMLInputElement>) {
39+
// toggle will force an update of GitPanel
3940
this.props.marker.toggle(this.props.fname);
40-
console.log(this.props.marker);
41+
42+
// needed if not a descendent of a GitPanel
4143
this.forceUpdate();
4244
}
4345

@@ -107,9 +109,9 @@ export class FileItemSimple extends React.Component<IFileItemSimpleProps> {
107109
return (
108110
<li className={fileStyle}>
109111
<GitMarkBox
110-
marker={this.props.marker}
111-
stage={this.props.stage}
112112
fname={this.props.file.to}
113+
stage={this.props.stage}
114+
marker={this.props.marker}
113115
/>
114116
<span
115117
className={classes(

src/components/GitPanel.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@ export class GitPanel extends React.Component<
7676
this.refreshStatus();
7777
}
7878
}, this);
79+
props.model.markChanged.connect(() => this.forceUpdate());
7980

8081
props.settings.changed.connect(this.refresh, this);
8182
}

src/model.ts

Lines changed: 23 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,13 @@ export class GitExtension implements IGitExtension, IDisposable {
125125
return this._statusChanged;
126126
}
127127

128+
/**
129+
* A signal emitted when the current marking of the git repository changes.
130+
*/
131+
get markChanged(): ISignal<IGitExtension, void> {
132+
return this._markChanged;
133+
}
134+
128135
public get commands(): CommandRegistry | null {
129136
return this._app ? this._app.commands : null;
130137
}
@@ -856,12 +863,13 @@ export class GitExtension implements IGitExtension, IDisposable {
856863
private _app: JupyterFrontEnd | null;
857864
private _diffProviders: { [key: string]: Git.IDiffCallback } = {};
858865
private _isDisposed = false;
859-
private _markerCache: Markers = new Markers();
866+
private _markerCache: Markers = new Markers(() => this._markChanged.emit());
860867
private _currentMarker: BranchMarker = null;
861868
private _readyPromise: Promise<void> = Promise.resolve();
862869
private _pendingReadyPromise = 0;
863870
private _poll: Poll;
864871
private _headChanged = new Signal<IGitExtension, void>(this);
872+
private _markChanged = new Signal<IGitExtension, void>(this);
865873
private _repositoryChanged = new Signal<
866874
IGitExtension,
867875
IChangedArgs<string | null>
@@ -872,9 +880,11 @@ export class GitExtension implements IGitExtension, IDisposable {
872880
}
873881

874882
export class BranchMarker {
883+
constructor(private _refresh: () => void) {}
884+
875885
add(fname: string, mark: boolean = true) {
876886
if (!(fname in this._marks)) {
877-
this._marks[fname] = mark;
887+
this.set(fname, mark);
878888
}
879889
}
880890

@@ -895,28 +905,35 @@ export class BranchMarker {
895905
}
896906

897907
mark(fname: string) {
898-
this._marks[fname] = true;
908+
this.set(fname, true);
899909
}
900910

901911
unmark(fname: string) {
902-
this._marks[fname] = false;
912+
this.set(fname, false);
913+
}
914+
915+
set(fname: string, mark: boolean) {
916+
this._marks[fname] = mark;
917+
this._refresh();
903918
}
904919

905920
toggle(fname: string) {
906-
this._marks[fname] = !this._marks[fname];
921+
this.set(fname, !this._marks[fname]);
907922
}
908923

909924
private _marks: { [key: string]: boolean } = {};
910925
}
911926

912927
export class Markers {
928+
constructor(private _refresh: () => void) {}
929+
913930
get(path: string, branch: string): BranchMarker {
914931
const key = Markers.markerKey(path, branch);
915932
if (key in this._branchMarkers) {
916933
return this._branchMarkers[key];
917934
}
918935

919-
let marker = new BranchMarker();
936+
let marker = new BranchMarker(this._refresh);
920937
this._branchMarkers[key] = marker;
921938
return marker;
922939
}

0 commit comments

Comments
 (0)