fix: Saving not removing red highlighting

This commit is contained in:
WerWolv 2024-02-15 21:54:41 +01:00
parent f113a2befe
commit 12ba05385b
3 changed files with 28 additions and 10 deletions

View file

@ -17,6 +17,7 @@ namespace hex::plugin::builtin {
private:
u64 m_selectedPatch = 0x00;
PerProvider<u32> m_numOperations;
PerProvider<u32> m_savedOperations;
};
}

View file

@ -57,15 +57,16 @@ namespace hex::plugin::builtin {
}
void FileProvider::save() {
m_file.flush();
#if defined(OS_WINDOWS)
FILETIME ft;
SYSTEMTIME st;
wolv::io::File file(m_path, wolv::io::File::Mode::Write);
if (file.isValid()) {
if (m_file.isValid()) {
GetSystemTime(&st);
if (SystemTimeToFileTime(&st, &ft)) {
auto fileHandle = HANDLE(_get_osfhandle(_fileno(file.getHandle())));
auto fileHandle = HANDLE(_get_osfhandle(_fileno(m_file.getHandle())));
SetFileTime(fileHandle, nullptr, nullptr, &ft);
}
}

View file

@ -38,7 +38,7 @@ namespace hex::plugin::builtin {
}
});
ImHexApi::HexEditor::addForegroundHighlightingProvider([](u64 offset, const u8* buffer, size_t, bool) -> std::optional<color_t> {
ImHexApi::HexEditor::addForegroundHighlightingProvider([this](u64 offset, const u8* buffer, size_t, bool) -> std::optional<color_t> {
hex::unused(buffer);
if (!ImHexApi::Provider::isValid())
@ -49,18 +49,34 @@ namespace hex::plugin::builtin {
offset -= provider->getBaseAddress();
const auto &undoStack = provider->getUndoStack();
for (const auto &operation : undoStack.getAppliedOperations()) {
const auto stackSize = undoStack.getAppliedOperations().size();
const auto savedStackSize = m_savedOperations.get(provider);
if (stackSize == savedStackSize) {
// Do nothing
} else if (stackSize > savedStackSize) {
for (const auto &operation : undoStack.getAppliedOperations() | std::views::drop(savedStackSize)) {
if (!operation->shouldHighlight())
continue;
if (operation->getRegion().overlaps(Region { offset, 1}))
return ImGuiExt::GetCustomColorU32(ImGuiCustomCol_Patches);
}
} else {
for (const auto &operation : undoStack.getUndoneOperations() | std::views::reverse | std::views::take(savedStackSize - stackSize)) {
if (!operation->shouldHighlight())
continue;
if (operation->getRegion().overlaps(Region { offset, 1}))
return ImGuiExt::GetCustomColorU32(ImGuiCustomCol_Patches);
}
}
return std::nullopt;
});
EventProviderSaved::subscribe([](auto *) {
EventProviderSaved::subscribe([this](prv::Provider *provider) {
m_savedOperations.get(provider) = provider->getUndoStack().getAppliedOperations().size();
EventHighlightingChanged::post();
});