mirror of
https://github.com/WerWolv/ImHex
synced 2024-10-20 17:52:41 +00:00
fix: Saving not removing red highlighting
This commit is contained in:
parent
f113a2befe
commit
12ba05385b
|
@ -17,6 +17,7 @@ namespace hex::plugin::builtin {
|
||||||
private:
|
private:
|
||||||
u64 m_selectedPatch = 0x00;
|
u64 m_selectedPatch = 0x00;
|
||||||
PerProvider<u32> m_numOperations;
|
PerProvider<u32> m_numOperations;
|
||||||
|
PerProvider<u32> m_savedOperations;
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
|
@ -57,15 +57,16 @@ namespace hex::plugin::builtin {
|
||||||
}
|
}
|
||||||
|
|
||||||
void FileProvider::save() {
|
void FileProvider::save() {
|
||||||
|
m_file.flush();
|
||||||
|
|
||||||
#if defined(OS_WINDOWS)
|
#if defined(OS_WINDOWS)
|
||||||
FILETIME ft;
|
FILETIME ft;
|
||||||
SYSTEMTIME st;
|
SYSTEMTIME st;
|
||||||
|
|
||||||
wolv::io::File file(m_path, wolv::io::File::Mode::Write);
|
if (m_file.isValid()) {
|
||||||
if (file.isValid()) {
|
|
||||||
GetSystemTime(&st);
|
GetSystemTime(&st);
|
||||||
if (SystemTimeToFileTime(&st, &ft)) {
|
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);
|
SetFileTime(fileHandle, nullptr, nullptr, &ft);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -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);
|
hex::unused(buffer);
|
||||||
|
|
||||||
if (!ImHexApi::Provider::isValid())
|
if (!ImHexApi::Provider::isValid())
|
||||||
|
@ -49,18 +49,34 @@ namespace hex::plugin::builtin {
|
||||||
offset -= provider->getBaseAddress();
|
offset -= provider->getBaseAddress();
|
||||||
|
|
||||||
const auto &undoStack = provider->getUndoStack();
|
const auto &undoStack = provider->getUndoStack();
|
||||||
for (const auto &operation : undoStack.getAppliedOperations()) {
|
const auto stackSize = undoStack.getAppliedOperations().size();
|
||||||
if (!operation->shouldHighlight())
|
const auto savedStackSize = m_savedOperations.get(provider);
|
||||||
continue;
|
|
||||||
|
|
||||||
if (operation->getRegion().overlaps(Region { offset, 1}))
|
if (stackSize == savedStackSize) {
|
||||||
return ImGuiExt::GetCustomColorU32(ImGuiCustomCol_Patches);
|
// 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;
|
return std::nullopt;
|
||||||
});
|
});
|
||||||
|
|
||||||
EventProviderSaved::subscribe([](auto *) {
|
EventProviderSaved::subscribe([this](prv::Provider *provider) {
|
||||||
|
m_savedOperations.get(provider) = provider->getUndoStack().getAppliedOperations().size();
|
||||||
EventHighlightingChanged::post();
|
EventHighlightingChanged::post();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue