diff --git a/ui/app.js b/ui/app.js index b2de050..a473567 100644 --- a/ui/app.js +++ b/ui/app.js @@ -158,6 +158,36 @@ class CVSRepositoryBrowser { } } + /** + * Show diff for a history item (comparing with previous revision) + * @param {string} filePath - Path to the file + * @param {string} currentRevision - Current revision + * @param {string} previousRevision - Previous revision (or null if this is the first) + */ + async showHistoryItemDiff(filePath, currentRevision, previousRevision) { + if (!filePath) return; + + try { + ui.diffContent.innerHTML = '
Generating diff...
'; + + if (!previousRevision) { + // If there's no previous revision, show a message + ui.diffContent.innerHTML = '
This is the first revision - no previous version to compare
'; + ui.showView(ui.diffView); + return; + } + + // Generate diff between previous and current revision + const diffResult = await api.getDiff(filePath, previousRevision, currentRevision); + const diffText = diffResult.diff || diffResult; + ui.displayDiff(diffText); + } catch (error) { + console.error('Error generating history item diff:', error); + ui.diffContent.innerHTML = `
Error generating diff: ${error.message}
`; + ui.showView(ui.diffView); + } + } + /** * Show patchsets view */ diff --git a/ui/ui.js b/ui/ui.js index 5d0c5d5..c770da4 100644 --- a/ui/ui.js +++ b/ui/ui.js @@ -254,14 +254,19 @@ class UIManager { this.showView(this.historyView); // Add click handlers to history items - this.historyContent.querySelectorAll('.history-item').forEach(item => { + this.historyContent.querySelectorAll('.history-item').forEach((item, index) => { item.addEventListener('click', () => { // Remove active class from all items this.historyContent.querySelectorAll('.history-item').forEach(i => i.classList.remove('active')); // Add active class to clicked item item.classList.add('active'); const revision = item.dataset.revision; - window.app.loadFileAtRevision(this.currentFile, revision); + + // Get the previous revision if it exists + const previousRevision = index < history.length - 1 ? history[index + 1].revision : null; + + // Show diff between current and previous revision + window.app.showHistoryItemDiff(this.currentFile, revision, previousRevision); }); }); }