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)
This commit is contained in:
Juan José Gutiérrez de Quevedo Pérez 2025-11-21 20:48:15 +01:00
parent 13f37be9c2
commit c15b759378
2 changed files with 37 additions and 2 deletions

View file

@ -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 = '<div class="loading">Generating diff...</div>';
if (!previousRevision) {
// If there's no previous revision, show a message
ui.diffContent.innerHTML = '<div class="loading">This is the first revision - no previous version to compare</div>';
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 = `<div class="loading" style="color: #991b1b;">Error generating diff: ${error.message}</div>`;
ui.showView(ui.diffView);
}
}
/**
* Show patchsets view
*/

View file

@ -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);
});
});
}