From c15b7593784b4d185692b7bad6e7f0f85193ca61 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Juan=20Jos=C3=A9=20Guti=C3=A9rrez=20de=20Quevedo=20P=C3=A9?= =?UTF-8?q?rez?= Date: Fri, 21 Nov 2025 20:48:15 +0100 Subject: [PATCH] Fix: clicking on history item now shows diff for that revision - Modified ui.js displayHistory() to pass previous revision to click handler - Added showHistoryItemDiff() method in app.js to generate and display diff - Diff compares selected revision with previous revision (Option A) - First revision shows message instead of diff (no previous to compare) --- ui/app.js | 30 ++++++++++++++++++++++++++++++ ui/ui.js | 9 +++++++-- 2 files changed, 37 insertions(+), 2 deletions(-) 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); }); }); }