feat: refresh files and notes on file events
This commit is contained in:
@@ -335,6 +335,13 @@
|
||||
return full.indexOf(workspaceRoot + '/') === 0 ? full.slice(workspaceRoot.length + 1) : full;
|
||||
}
|
||||
|
||||
function isWorkspaceEvent(event) {
|
||||
var payload = (event && event.payload) || {};
|
||||
var path = cleanPath(payload.path || '');
|
||||
if (!path) return true;
|
||||
return !workspaceRoot || path === workspaceRoot || path.indexOf(workspaceRoot + '/') === 0;
|
||||
}
|
||||
|
||||
var toolbar = el('div', { className: 'files-toolbar' });
|
||||
var breadcrumb = el('div', { className: 'files-breadcrumb' });
|
||||
var backBtn = iconButton('back', 'Back', 'back', goBack);
|
||||
@@ -1412,8 +1419,22 @@
|
||||
loadContributionActions();
|
||||
loadEntries();
|
||||
|
||||
var fileChangedUnsubscribe = null;
|
||||
if (api.events && typeof api.events.subscribe === 'function') {
|
||||
api.events.subscribe('file.changed', function (event) {
|
||||
if (disposed || !isWorkspaceEvent(event)) return;
|
||||
if (showingTrash) loadTrashEntries();
|
||||
else loadEntries();
|
||||
}).then(function (unsubscribe) {
|
||||
fileChangedUnsubscribe = unsubscribe;
|
||||
}).catch(function (err) {
|
||||
console.error('[files] file.changed subscription:', err);
|
||||
});
|
||||
}
|
||||
|
||||
containerEl.__filesCleanup = function () {
|
||||
disposed = true;
|
||||
if (typeof fileChangedUnsubscribe === 'function') fileChangedUnsubscribe();
|
||||
document.removeEventListener('click', onDocClick);
|
||||
document.removeEventListener('keydown', onDocKeydown);
|
||||
window.removeEventListener('mousedown', handleMouseHistory, true);
|
||||
|
||||
@@ -19,6 +19,7 @@
|
||||
"files.write",
|
||||
"files.delete",
|
||||
"files.openExternal",
|
||||
"events.subscribe",
|
||||
"workbench.open",
|
||||
"ui.register"
|
||||
],
|
||||
|
||||
@@ -345,6 +345,14 @@
|
||||
});
|
||||
}
|
||||
|
||||
function isNotesEvent(event) {
|
||||
var payload = (event && event.payload) || {};
|
||||
var changedPath = cleanPath(payload.path || '');
|
||||
if (!changedPath) return true;
|
||||
var parent = notesParent();
|
||||
return changedPath === parent || changedPath.indexOf(parent + '/') === 0;
|
||||
}
|
||||
|
||||
function actionInitial(action) {
|
||||
var label = String(action && action.label || '').trim();
|
||||
return label ? label.charAt(0).toUpperCase() : '+';
|
||||
@@ -640,8 +648,21 @@
|
||||
loadContributionActions();
|
||||
loadNotes();
|
||||
|
||||
var fileChangedUnsubscribe = null;
|
||||
if (api.events && typeof api.events.subscribe === 'function') {
|
||||
api.events.subscribe('file.changed', function (event) {
|
||||
if (disposed || !isNotesEvent(event)) return;
|
||||
loadNotes();
|
||||
}).then(function (unsubscribe) {
|
||||
fileChangedUnsubscribe = unsubscribe;
|
||||
}).catch(function (err) {
|
||||
console.error('[notes] file.changed subscription:', err);
|
||||
});
|
||||
}
|
||||
|
||||
containerEl.__notesCleanup = function () {
|
||||
disposed = true;
|
||||
if (typeof fileChangedUnsubscribe === 'function') fileChangedUnsubscribe();
|
||||
};
|
||||
},
|
||||
|
||||
|
||||
@@ -18,6 +18,7 @@
|
||||
"files.read",
|
||||
"files.write",
|
||||
"files.delete",
|
||||
"events.subscribe",
|
||||
"workbench.open",
|
||||
"ui.register"
|
||||
],
|
||||
|
||||
Reference in New Issue
Block a user