mirror of https://github.com/WerWolv/ImHex.git
fix: Saving not removing red highlighting
This commit is contained in:
parent
f113a2befe
commit
12ba05385b
|
@ -17,6 +17,7 @@ namespace hex::plugin::builtin {
|
|||
private:
|
||||
u64 m_selectedPatch = 0x00;
|
||||
PerProvider<u32> m_numOperations;
|
||||
PerProvider<u32> m_savedOperations;
|
||||
};
|
||||
|
||||
}
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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()) {
|
||||
if (!operation->shouldHighlight())
|
||||
continue;
|
||||
const auto stackSize = undoStack.getAppliedOperations().size();
|
||||
const auto savedStackSize = m_savedOperations.get(provider);
|
||||
|
||||
if (operation->getRegion().overlaps(Region { offset, 1}))
|
||||
return ImGuiExt::GetCustomColorU32(ImGuiCustomCol_Patches);
|
||||
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();
|
||||
});
|
||||
|
||||
|
|
Loading…
Reference in New Issue