mirror of
https://github.com/WerWolv/ImHex.git
synced 2026-04-02 13:37:42 -05:00
fix: Crashes when getting tabs into text editor (#2008)
This time it may be for good. ### Implementation description As requested I added the preprocessing functionality into the pattern editor. I had to duplicate a few functions and update the c++ library to version 20. but now I can make sure the pattern editor doesn't see a tab again. I also removed the preprocessor from where it was before because it is not needed anymore. The changes were tested using a file that used tabs for all its white space. The file was pasted into the pattern editor and imported as well. I both cases no crashes occurred and the files had no tabs on them.
This commit is contained in:
@@ -1082,7 +1082,7 @@ namespace hex::plugin::builtin {
|
||||
if (!skipNewLine)
|
||||
m_consoleEditor.InsertText("\n");
|
||||
skipNewLine = false;
|
||||
m_consoleEditor.InsertText(preprocessText(m_console->at(lineCount + i)));
|
||||
m_consoleEditor.InsertText(m_console->at(lineCount + i));
|
||||
}
|
||||
|
||||
m_consoleNeedsUpdate = false;
|
||||
@@ -1812,7 +1812,7 @@ namespace hex::plugin::builtin {
|
||||
void ViewPatternEditor::loadPatternFile(const std::fs::path &path, prv::Provider *provider) {
|
||||
wolv::io::File file(path, wolv::io::File::Mode::Read);
|
||||
if (file.isValid()) {
|
||||
auto code = preprocessText(file.readString());
|
||||
auto code = file.readString();
|
||||
|
||||
this->evaluatePattern(code, provider);
|
||||
m_textEditor.SetText(code);
|
||||
@@ -1977,15 +1977,6 @@ namespace hex::plugin::builtin {
|
||||
});
|
||||
}
|
||||
|
||||
std::string ViewPatternEditor::preprocessText(const std::string &code) {
|
||||
std::string result = wolv::util::replaceStrings(code, "\r\n", "\n");
|
||||
result = wolv::util::replaceStrings(result, "\r", "\n");
|
||||
result = wolv::util::replaceTabsWithSpaces(result, 4);
|
||||
while (result.ends_with('\n'))
|
||||
result.pop_back();
|
||||
return result;
|
||||
}
|
||||
|
||||
void ViewPatternEditor::registerEvents() {
|
||||
RequestPatternEditorSelectionChange::subscribe(this, [this](u32 line, u32 column) {
|
||||
if (line == 0)
|
||||
@@ -2009,9 +2000,8 @@ namespace hex::plugin::builtin {
|
||||
});
|
||||
|
||||
RequestSetPatternLanguageCode::subscribe(this, [this](const std::string &code) {
|
||||
const std::string preprocessed = preprocessText(code);
|
||||
m_textEditor.SetText(preprocessed);
|
||||
m_sourceCode.set(ImHexApi::Provider::get(), preprocessed);
|
||||
m_textEditor.SetText(code);
|
||||
m_sourceCode.set(ImHexApi::Provider::get(), code);
|
||||
m_hasUnevaluatedChanges = true;
|
||||
});
|
||||
|
||||
@@ -2272,7 +2262,7 @@ namespace hex::plugin::builtin {
|
||||
.basePath = "pattern_source_code.hexpat",
|
||||
.required = false,
|
||||
.load = [this](prv::Provider *provider, const std::fs::path &basePath, const Tar &tar) {
|
||||
const auto sourceCode = preprocessText(tar.readString(basePath));
|
||||
const auto sourceCode = tar.readString(basePath);
|
||||
|
||||
m_sourceCode.set(provider, sourceCode);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user