Skip to content

Commit

Permalink
Fix indention sometimes isn't applied correctly
Browse files Browse the repository at this point in the history
  • Loading branch information
Chocobo1 committed Aug 24, 2018
1 parent ef80b2c commit 54e8e40
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 11 deletions.
14 changes: 7 additions & 7 deletions src/dllmain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -77,9 +77,9 @@ extern "C" NPPAUTODETECTINDENT_API void beNotified(SCNotification *notifyCode)

case NPPN_FILECLOSED:
{
const uptr_t id = notifyCode->nmhdr.idFrom;

indentCache.erase(id);
TCHAR path[MAX_PATH + 1] {};
myPlugin->message()->sendNppMessage<>(NPPM_GETFULLCURRENTPATH, MAX_PATH, reinterpret_cast<LPARAM>(path));
indentCache.erase(path);
break;
}

Expand All @@ -88,12 +88,12 @@ extern "C" NPPAUTODETECTINDENT_API void beNotified(SCNotification *notifyCode)
if (Settings::instance()->getDisablePlugin())
break;

const uptr_t id = notifyCode->nmhdr.idFrom;
TCHAR path[MAX_PATH + 1] {};
myPlugin->message()->sendNppMessage<>(NPPM_GETFULLCURRENTPATH, MAX_PATH, reinterpret_cast<LPARAM>(path));

const auto iter = indentCache.find(id);
const auto iter = indentCache.find(path);
const nppAutoDetectIndent::IndentInfo info = (iter != indentCache.end()) ? iter->second : nppAutoDetectIndent::detectIndentInfo();

indentCache[id] = info;
indentCache[path] = info;
applyIndentInfo(info);
break;
}
Expand Down
7 changes: 4 additions & 3 deletions src/nppAutoDetectIndent.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@

#include "settings.h"

#define PLUGIN_VERSION "1.4"
#define PLUGIN_VERSION "1.5"

namespace
{
Expand Down Expand Up @@ -141,10 +141,11 @@ namespace MenuAction
}
else
{
const int id = plugin->message()->sendNppMessage<int>(NPPM_GETCURRENTBUFFERID, 0, 0);
TCHAR path[MAX_PATH + 1] {};
plugin->message()->sendNppMessage<>(NPPM_GETFULLCURRENTPATH, MAX_PATH, reinterpret_cast<LPARAM>(path));
const nppAutoDetectIndent::IndentInfo info = nppAutoDetectIndent::detectIndentInfo();

plugin->indentCache[id] = info;
plugin->indentCache[path] = info;
applyIndentInfo(info);
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/nppAutoDetectIndent.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ namespace nppAutoDetectIndent
NppSettings detectNppSettings();
void applyNppSettings(const NppSettings &settings);

using IndentCache = std::unordered_map<uptr_t, IndentInfo>; // <file name, IndentInfo>
using IndentCache = std::unordered_map<std::wstring, IndentInfo>; // <full file path, IndentInfo>
}

class MyPlugin
Expand Down

0 comments on commit 54e8e40

Please sign in to comment.