From 3e36aee647f93783106ccb8ba749815a7cc6ffe7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?John-Fran=C3=A7ois=20Serre-Pon=C3=A7on?= Date: Sat, 5 Apr 2025 17:17:51 +0800 Subject: [PATCH] Fix plugin lose track of current state --- plugin/dirdiff.vim | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/plugin/dirdiff.vim b/plugin/dirdiff.vim index 2389f7a..33cbe9a 100644 --- a/plugin/dirdiff.vim +++ b/plugin/dirdiff.vim @@ -470,6 +470,17 @@ function! DirDiffOpen() return endif + let line = getline(".") + let mode = 0 + if IsDiffer(line) + let mode = 2 + elseif IsOnly(line) + let mode = 1 + else + echo "There is no diff at the current line! " + return + endif + " First dehighlight the last marked line call DeHighlightLine() @@ -479,7 +490,6 @@ function! DirDiffOpen() " Change back to the right window call GotoDiffWindow() - let line = getline(".") let b:currentDiff = line(".") let previousFileA = exists("s:FilenameA") ? s:FilenameA : "" @@ -492,7 +502,7 @@ function! DirDiffOpen() let s:FilenameA = EscapeFileName(fileA) let s:FilenameB = EscapeFileName(fileB) - if IsOnly(line) + if mode == 1 " We open the file let fileSrc = ParseOnlySrc(line) if (fileSrc == "A") @@ -524,8 +534,7 @@ function! DirDiffOpen() exe("resize " . g:DirDiffWindowSize) exe (b:currentDiff) let s:LastMode = fileSrc - elseif IsDiffer(line) - + elseif mode == 2 if exists("s:LastMode") if s:LastMode == 2 call Drop(previousFileA) @@ -564,7 +573,7 @@ function! DirDiffOpen() exe ("normal z.") let s:LastMode = 2 else - echo "There is no diff at the current line!" + echo "should not happen" endif endfunction