Skip to content

Commit b0c207a

Browse files
committed
Use stack to determine if user initiated
1 parent d244c46 commit b0c207a

File tree

2 files changed

+47
-18
lines changed

2 files changed

+47
-18
lines changed

src/contents.ts

Lines changed: 46 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,10 @@ export class Drive implements Contents.IDrive {
3838
this._serverSettings = ServerConnection.makeSettings();
3939
this._name = options.name ?? '';
4040
this._drivesList = options.drivesList ?? [];
41+
42+
this.fileChanged.connect((sender, args) => {
43+
console.log('fileChanged', args);
44+
});
4145
}
4246

4347
/**
@@ -219,8 +223,11 @@ export class Drive implements Contents.IDrive {
219223
localPath: string,
220224
options?: Contents.IFetchOptions
221225
): Promise<Contents.IModel> {
226+
console.log('[DEBUG] get() called with localPath:', localPath);
222227
let data: Contents.IModel;
223228

229+
const isFromClick = this.isUserInitiated();
230+
224231
if (localPath !== '') {
225232
console.log('debug: IF get() called with localPath:', localPath);
226233
const currentDrive = extractCurrentDrive(localPath, this._drivesList);
@@ -244,12 +251,13 @@ export class Drive implements Contents.IDrive {
244251
registeredFileTypes: this._registeredFileTypes
245252
});
246253

247-
this._loadingContents.emit({
248-
type: 'loading',
249-
path: localPath,
250-
driveName: this._name,
251-
itemType: result.isDir ? 'directory' : 'file'
252-
});
254+
isFromClick &&
255+
this._loadingContents.emit({
256+
type: 'loading',
257+
path: localPath,
258+
driveName: this._name,
259+
itemType: result.isDir ? 'directory' : 'file'
260+
});
253261

254262
data = {
255263
name: result.isDir
@@ -277,12 +285,13 @@ export class Drive implements Contents.IDrive {
277285
} else {
278286
console.log('debug: ELSE get() called with localPath:', localPath);
279287

280-
this._loadingContents.emit({
281-
type: 'loading',
282-
path: localPath,
283-
driveName: this._name,
284-
itemType: 'directory'
285-
});
288+
isFromClick &&
289+
this._loadingContents.emit({
290+
type: 'loading',
291+
path: localPath,
292+
driveName: this._name,
293+
itemType: 'directory'
294+
});
286295

287296
// retriving list of contents from root
288297
// in our case: list available drives
@@ -326,15 +335,34 @@ export class Drive implements Contents.IDrive {
326335
}
327336

328337
Contents.validateContentsModel(data);
329-
this._loadingContents.emit({
330-
type: 'loaded',
331-
path: localPath,
332-
driveName: this._name,
333-
itemType: 'directory'
334-
});
338+
339+
isFromClick &&
340+
this._loadingContents.emit({
341+
type: 'loaded',
342+
path: localPath,
343+
driveName: this._name,
344+
itemType: 'directory'
345+
});
335346
return data;
336347
}
337348

349+
// This is dumb?
350+
isUserInitiated() {
351+
const stack = new Error().stack;
352+
353+
// Check if it's from a click event by examining the call stack
354+
const isFromClick =
355+
stack?.includes('evtDblClick') ||
356+
stack?.includes('handleOpen') ||
357+
stack?.includes('_evtClick');
358+
359+
console.log('[DEBUG] Call stack analysis:');
360+
console.log(' - Is from click event:', isFromClick);
361+
console.log(' - Call stack:', stack?.split('\n').join('\n '));
362+
363+
return isFromClick;
364+
}
365+
338366
/**
339367
* Create a new untitled file or directory in the specified directory path.
340368
*

src/plugins/driveBrowserPlugin.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -358,6 +358,7 @@ namespace Private {
358358
}
359359
} else {
360360
await browser.model.restore(browser.id);
361+
console.log('PROOF');
361362
await browser.model.refresh();
362363
}
363364
browser.removeClass(restoring);

0 commit comments

Comments
 (0)