Skip to content

Commit 3d0d054

Browse files
committed
Add more workaround to ensure handling the correct document
1 parent 54e8e40 commit 3d0d054

File tree

3 files changed

+26
-2
lines changed

3 files changed

+26
-2
lines changed

src/dllmain.cpp

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,14 +75,37 @@ extern "C" NPPAUTODETECTINDENT_API void beNotified(SCNotification *notifyCode)
7575
break;
7676
}
7777

78-
case NPPN_FILECLOSED:
78+
case NPPN_FILEBEFORECLOSE:
7979
{
8080
TCHAR path[MAX_PATH + 1] {};
8181
myPlugin->message()->sendNppMessage<>(NPPM_GETFULLCURRENTPATH, MAX_PATH, reinterpret_cast<LPARAM>(path));
8282
indentCache.erase(path);
8383
break;
8484
}
8585

86+
case NPPN_FILEBEFORESAVE:
87+
{
88+
const uptr_t bufferId = notifyCode->nmhdr.idFrom;
89+
TCHAR oldPath[MAX_PATH + 1] {};
90+
myPlugin->message()->sendNppMessage<>(NPPM_GETFULLCURRENTPATH, MAX_PATH, reinterpret_cast<LPARAM>(oldPath));
91+
92+
myPlugin->fileRenameMap[bufferId] = oldPath;
93+
break;
94+
}
95+
96+
case NPPN_FILESAVED:
97+
{
98+
const uptr_t bufferId = notifyCode->nmhdr.idFrom;
99+
const std::wstring oldPath = myPlugin->fileRenameMap[bufferId];
100+
myPlugin->fileRenameMap.erase(bufferId);
101+
102+
TCHAR newPath[MAX_PATH + 1] {};
103+
myPlugin->message()->sendNppMessage<>(NPPM_GETFULLCURRENTPATH, MAX_PATH, reinterpret_cast<LPARAM>(newPath));
104+
indentCache[newPath] = indentCache[oldPath];
105+
indentCache.erase(oldPath);
106+
break;
107+
}
108+
86109
case NPPN_BUFFERACTIVATED:
87110
{
88111
if (Settings::instance()->getDisablePlugin())

src/nppAutoDetectIndent.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121

2222
#include "settings.h"
2323

24-
#define PLUGIN_VERSION "1.5"
24+
#define PLUGIN_VERSION "1.6"
2525

2626
namespace
2727
{

src/nppAutoDetectIndent.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,7 @@ class MyPlugin
108108

109109
const std::array<FuncItem, 4> m_funcItems {};
110110
nppAutoDetectIndent::IndentCache indentCache;
111+
std::unordered_map<uptr_t, std::wstring> fileRenameMap; // <buffer id, old file path>
111112
nppAutoDetectIndent::NppSettings nppOriginalSettings;
112113

113114
static constexpr TCHAR *PLUGIN_NAME = TEXT("Auto Detect Indention");

0 commit comments

Comments
 (0)