|
1 | 1 | local M = {} |
2 | 2 |
|
| 3 | +local log = require("code-preview.log") |
| 4 | + |
3 | 5 | -- Active diffs keyed by absolute file path. |
4 | 6 | -- Each entry: { tab, bufs, augroup, inline_win } |
5 | 7 | local active_diffs = {} |
@@ -32,6 +34,7 @@ local function mark_change_and_reveal(abs_file_path) |
32 | 34 | end |
33 | 35 |
|
34 | 36 | local status = vim.loop.fs_stat(abs_file_path) and "modified" or "created" |
| 37 | + log.debug(log.fmt("mark_change_and_reveal: %s → %s", abs_file_path, status)) |
35 | 38 | pcall(function() require("code-preview.changes").set(abs_file_path, status) end) |
36 | 39 | pcall(function() require("code-preview.neo_tree").refresh() end) |
37 | 40 |
|
@@ -371,16 +374,21 @@ end |
371 | 374 |
|
372 | 375 | function M.show_diff(original_path, proposed_path, real_file_path, abs_file_path) |
373 | 376 | local file_key = abs_file_path or real_file_path |
| 377 | + local cfg = require("code-preview").config |
| 378 | + log.info(log.fmt("show_diff: file=%s layout=%s active=%d", |
| 379 | + file_key or "nil", |
| 380 | + (cfg.diff and cfg.diff.layout) or "tab", |
| 381 | + active_count())) |
| 382 | + |
374 | 383 | -- If a diff for this SAME file is already open, close it first (re-edit) |
375 | 384 | if file_key and active_diffs[file_key] then |
| 385 | + log.debug(log.fmt("show_diff: re-edit detected, closing existing diff for %s", file_key)) |
376 | 386 | M.close_for_file(file_key) |
377 | 387 | end |
378 | 388 |
|
379 | 389 | -- Set the neo-tree indicator + reveal |
380 | 390 | mark_change_and_reveal(abs_file_path) |
381 | 391 |
|
382 | | - local cfg = require("code-preview").config |
383 | | - |
384 | 392 | -- Inline layout |
385 | 393 | if cfg.diff.layout == "inline" then |
386 | 394 | local result = show_inline_diff(original_path, proposed_path, real_file_path, cfg) |
|
478 | 486 | function M.close_for_file(file_path) |
479 | 487 | local entry = active_diffs[file_path] |
480 | 488 | if not entry then |
| 489 | + log.debug(log.fmt("close_for_file: no active diff for %s, skipping", file_path)) |
481 | 490 | return |
482 | 491 | end |
483 | 492 |
|
| 493 | + log.info(log.fmt("close_for_file: closing diff for %s (remaining=%d)", file_path, active_count() - 1)) |
| 494 | + |
484 | 495 | -- Clear neo-tree indicator (refresh is deferred until after the tab is closed |
485 | 496 | -- to avoid neo-tree walking a stale tabpage id) |
486 | 497 | pcall(function() require("code-preview.changes").clear(file_path) end) |
|
545 | 556 |
|
546 | 557 | -- Close ALL diffs and clear neo-tree indicators (for manual close via <leader>dq) |
547 | 558 | function M.close_diff_and_clear() |
| 559 | + log.info(log.fmt("close_diff_and_clear: closing all diffs (count=%d)", active_count())) |
548 | 560 | -- Collect keys first to avoid modifying table during iteration |
549 | 561 | local files = {} |
550 | 562 | for file_path, _ in pairs(active_diffs) do |
|
0 commit comments