1
0
mirror of synced 2024-09-23 19:18:24 +02:00

feat: Added per provider cursor position for the Pattern editor (#1861)

### Problem description
Currently, the pattern editor does not remember where the cursor is
located in each provider. For example, suppose you have 2 providers in
your project, and you scrolled down to line 200 in the first pattern to
make some changes and remembered that the code you want to insert is in
the second provider. Then you switch to the second provider, look for
the code and find it in line 235. Switch back to the first one, and you
are at the beginning of the file. So you again look for the line to edit
paste it to realize that it needs code a few lines before the place you
found it. You switch to the second provider, and you are at the top
again. This gets annoying very fast.

### Implementation description

This PR ensures that, when you return to the pattern in the editor for
any of the opened providers, the cursor will still be at the same place
it was when you switched to a different one. Each provider pattern saves
its cursor position and returns to it when you switch to that provider.
It does that by creating a PerProvider variable and using it when
providers are first opened to set it to the origin and when switching
providers it first saves the position of the old provider and then loads
and sets the saved position of the new provider.

---------

Co-authored-by: Nik <werwolv98@gmail.com>
This commit is contained in:
paxcut 2024-09-15 06:28:37 -07:00 committed by GitHub
parent d88252c6fd
commit 866b956680
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 11 additions and 6 deletions

View File

@ -248,6 +248,7 @@ namespace hex::plugin::builtin {
std::mutex m_logMutex; std::mutex m_logMutex;
PerProvider<TextEditor::Coordinates> m_cursorPosition;
PerProvider<std::optional<pl::core::err::PatternLanguageError>> m_lastEvaluationError; PerProvider<std::optional<pl::core::err::PatternLanguageError>> m_lastEvaluationError;
PerProvider<std::vector<pl::core::err::CompileError>> m_lastCompileError; PerProvider<std::vector<pl::core::err::CompileError>> m_lastCompileError;
PerProvider<std::vector<const pl::core::ast::ASTNode*>> m_callStack; PerProvider<std::vector<const pl::core::ast::ASTNode*>> m_callStack;

View File

@ -566,7 +566,7 @@ namespace hex::plugin::builtin {
} }
if (m_hasUnevaluatedChanges && m_runningEvaluators == 0 && m_runningParsers == 0) { if (m_hasUnevaluatedChanges && m_runningEvaluators == 0 && m_runningParsers == 0) {
if ((std::chrono::steady_clock::now() - m_lastEditorChangeTime) > std::chrono::seconds(1)) { if ((std::chrono::steady_clock::now() - m_lastEditorChangeTime) > std::chrono::seconds(1LL)) {
m_hasUnevaluatedChanges = false; m_hasUnevaluatedChanges = false;
auto code = m_textEditor.GetText(); auto code = m_textEditor.GetText();
@ -1735,7 +1735,7 @@ namespace hex::plugin::builtin {
*m_breakpointHit = true; *m_breakpointHit = true;
m_resetDebuggerVariables = true; m_resetDebuggerVariables = true;
while (*m_breakpointHit) { while (*m_breakpointHit) {
std::this_thread::sleep_for(std::chrono::milliseconds(100)); std::this_thread::sleep_for(std::chrono::milliseconds(100LL));
} }
}); });
@ -1758,7 +1758,7 @@ namespace hex::plugin::builtin {
m_dangerousFunctionCalled = true; m_dangerousFunctionCalled = true;
while (m_dangerousFunctionsAllowed == DangerousFunctionPerms::Ask) { while (m_dangerousFunctionsAllowed == DangerousFunctionPerms::Ask) {
std::this_thread::sleep_for(std::chrono::milliseconds(100)); std::this_thread::sleep_for(std::chrono::milliseconds(100LL));
} }
return m_dangerousFunctionsAllowed == DangerousFunctionPerms::Allow; return m_dangerousFunctionsAllowed == DangerousFunctionPerms::Allow;
@ -1852,15 +1852,19 @@ namespace hex::plugin::builtin {
m_envVarEntries->emplace_back(0, "", i128(0), EnvVarType::Integer); m_envVarEntries->emplace_back(0, "", i128(0), EnvVarType::Integer);
m_debuggerDrawer.get(provider) = std::make_unique<ui::PatternDrawer>(); m_debuggerDrawer.get(provider) = std::make_unique<ui::PatternDrawer>();
m_cursorPosition.get(provider) = TextEditor::Coordinates(0, 0);
}); });
EventProviderChanged::subscribe(this, [this](prv::Provider *oldProvider, prv::Provider *newProvider) { EventProviderChanged::subscribe(this, [this](prv::Provider *oldProvider, prv::Provider *newProvider) {
if (oldProvider != nullptr) if (oldProvider != nullptr) {
m_sourceCode.set(oldProvider, m_textEditor.GetText()); m_sourceCode.set(oldProvider, m_textEditor.GetText());
m_cursorPosition.set(m_textEditor.GetCursorPosition(),oldProvider);
}
if (newProvider != nullptr) if (newProvider != nullptr) {
m_textEditor.SetText(m_sourceCode.get(newProvider)); m_textEditor.SetText(m_sourceCode.get(newProvider));
else m_textEditor.SetCursorPosition(m_cursorPosition.get(newProvider));
} else
m_textEditor.SetText(""); m_textEditor.SetText("");
}); });