Skip to content

Commit

Permalink
*Updated global search.
Browse files Browse the repository at this point in the history
  • Loading branch information
paladin-t committed Oct 30, 2023
1 parent ca330fe commit 435118f
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 55 deletions.
2 changes: 1 addition & 1 deletion src/editing.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -845,7 +845,7 @@ bool find(
if (ImGui::IsItemHovered()) {
VariableGuard<decltype(style.WindowPadding)> guardWindowPadding(&style.WindowPadding, style.WindowPadding, ImVec2(WIDGETS_TOOLTIP_PADDING, WIDGETS_TOOLTIP_PADDING));

ImGui::SetTooltip(ws->theme()->tooltipEditing_GlobalSearch());
ImGui::SetTooltip(ws->theme()->tooltipEditing_GlobalSearchForCode());
}

ImGui::SameLine();
Expand Down
89 changes: 37 additions & 52 deletions src/editor_code.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -72,11 +72,22 @@ class EditorCodeImpl : public EditorCode, public ImGui::CodeEditor {
} _tools;

static struct Shared {
struct Cache {
typedef std::vector<Cache> Array;

std::string text;
bool valid = false;

Cache() {
}
Cache(const std::string &txt, bool valid_) : text(txt), valid(valid_) {
}
};

bool finding = false;
Editing::Tools::Marker marker;
mutable std::string* wordPtr = nullptr;
mutable Editing::Tools::TextPages* cachePtr = nullptr;
mutable Text::Array* cacheStr = nullptr;
mutable Cache::Array* cacheStr = nullptr;

Shared() {
}
Expand All @@ -97,35 +108,17 @@ class EditorCodeImpl : public EditorCode, public ImGui::CodeEditor {
return *wordPtr;
}

const Editing::Tools::TextPages &cache(Text::Array** strs) const {
if (strs)
*strs = nullptr;

if (cachePtr == nullptr)
cachePtr = new Editing::Tools::TextPages();

const Cache::Array &cache(void) const {
if (cacheStr == nullptr)
cacheStr = new Text::Array();

if (strs)
*strs = cacheStr;
cacheStr = new Cache::Array();

return *cachePtr;
return *cacheStr;
}
Editing::Tools::TextPages &cache(Text::Array** strs) {
if (strs)
*strs = nullptr;

if (cachePtr == nullptr)
cachePtr = new Editing::Tools::TextPages();

Cache::Array &cache(void) {
if (cacheStr == nullptr)
cacheStr = new Text::Array();
cacheStr = new Cache::Array();

if (strs)
*strs = cacheStr;

return *cachePtr;
return *cacheStr;
}

void clear(void) {
Expand All @@ -135,10 +128,6 @@ class EditorCodeImpl : public EditorCode, public ImGui::CodeEditor {
delete wordPtr;
wordPtr = nullptr;
}
if (cachePtr) {
delete cachePtr;
cachePtr = nullptr;
}
if (cacheStr) {
delete cacheStr;
cacheStr = nullptr;
Expand Down Expand Up @@ -612,8 +601,8 @@ class EditorCodeImpl : public EditorCode, public ImGui::CodeEditor {
Coordinates srcBegin, srcEnd;
GetSelection(srcBegin, srcEnd);

Text::Array* strings = nullptr;
Editing::Tools::TextPages &cache = _shared.cache(&strings);
Shared::Cache::Array &strings = _shared.cache();
Editing::Tools::TextPages cache;
do {
LockGuard<RecursiveMutex>::UniquePtr acquired;
Project* prj = project->acquire(acquired);
Expand All @@ -637,10 +626,8 @@ class EditorCodeImpl : public EditorCode, public ImGui::CodeEditor {
const char* txt = editor->text(&len);
std::string str;
str.assign(txt, len);
if (_index < (int)strings->size() && _index < (int)cache.size()) {
(*strings)[_index] = txt;
cache[_index] = &strings->back();
}
if (_index < (int)strings.size())
strings[_index] = Shared::Cache(txt, true);
} else {
asset->prepare(Asset::EDITING, true);
Object::Ptr obj = asset->object(Asset::EDITING);
Expand All @@ -656,12 +643,16 @@ class EditorCodeImpl : public EditorCode, public ImGui::CodeEditor {
const char* txt = code->text(&len);
std::string str;
str.assign(txt, len);
if (_index < (int)strings->size() && _index < (int)cache.size()) {
(*strings)[_index] = txt;
cache[_index] = &strings->back();
}
if (_index < (int)strings.size())
strings[_index] = Shared::Cache(txt, true);
}
} while (false);
for (Shared::Cache &str : strings) {
if (str.valid)
cache.push_back(&str.text);
else
cache.push_back(nullptr);
}
_tools.marker = Editing::Tools::Marker(
Editing::Tools::Marker::Coordinates(_index, srcBegin.Line, srcBegin.Column),
Editing::Tools::Marker::Coordinates(_index, srcEnd.Line, srcEnd.Column)
Expand Down Expand Up @@ -773,14 +764,11 @@ class EditorCodeImpl : public EditorCode, public ImGui::CodeEditor {

virtual void lostFocus(class Renderer* /* rnd */, const class Project* /* project */) override {
_index = -1;
Text::Array* strings = nullptr;
Editing::Tools::TextPages &cache = _shared.cache(&strings);
strings->clear();
cache.clear();
Shared::Cache::Array &strings = _shared.cache();
strings.clear();
}
virtual void gainFocus(class Renderer* /* rnd */, const class Project* project) override {
Text::Array* strings = nullptr;
Editing::Tools::TextPages &cache = _shared.cache(&strings);
Shared::Cache::Array &strings = _shared.cache();
do {
LockGuard<RecursiveMutex>::UniquePtr acquired;
Project* prj = project->acquire(acquired);
Expand All @@ -793,8 +781,7 @@ class EditorCodeImpl : public EditorCode, public ImGui::CodeEditor {
break;

if (asset->type() != Code::TYPE()) {
strings->push_back("");
cache.push_back(nullptr);
strings.push_back(Shared::Cache("", false));

continue;
}
Expand All @@ -812,8 +799,7 @@ class EditorCodeImpl : public EditorCode, public ImGui::CodeEditor {
const char* txt = editor->text(&len);
std::string str;
str.assign(txt, len);
strings->push_back(txt);
cache.push_back(&strings->back());
strings.push_back(Shared::Cache(txt, true));
} else {
asset->prepare(Asset::EDITING, true);
Object::Ptr obj = asset->object(Asset::EDITING);
Expand All @@ -829,8 +815,7 @@ class EditorCodeImpl : public EditorCode, public ImGui::CodeEditor {
const char* txt = code->text(&len);
std::string str;
str.assign(txt, len);
strings->push_back(txt);
cache.push_back(&strings->back());
strings.push_back(Shared::Cache(txt, true));
}
}
} while (false);
Expand Down
2 changes: 1 addition & 1 deletion src/theme.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -373,7 +373,7 @@ bool Theme::open(class Renderer* rnd) {
tooltipEditing_CaseSensitive("Case-sensitive");
tooltipEditing_DeleteAnimation("Delete animation");
tooltipEditing_DeleteFrame("Delete frame");
tooltipEditing_GlobalSearch("Global search");
tooltipEditing_GlobalSearchForCode("Global search (for code)");
tooltipEditing_InsertFrame("Insert frame");
tooltipEditing_MatchWholeWords("Match whole words");
tooltipEditing_RenameAnimation("Rename animation");
Expand Down
2 changes: 1 addition & 1 deletion src/theme.h
Original file line number Diff line number Diff line change
Expand Up @@ -303,7 +303,7 @@ class Theme {
BITTY_PROPERTY_READONLY(std::string, tooltipEditing_CaseSensitive)
BITTY_PROPERTY_READONLY(std::string, tooltipEditing_DeleteAnimation)
BITTY_PROPERTY_READONLY(std::string, tooltipEditing_DeleteFrame)
BITTY_PROPERTY_READONLY(std::string, tooltipEditing_GlobalSearch)
BITTY_PROPERTY_READONLY(std::string, tooltipEditing_GlobalSearchForCode)
BITTY_PROPERTY_READONLY(std::string, tooltipEditing_InsertFrame)
BITTY_PROPERTY_READONLY(std::string, tooltipEditing_MatchWholeWords)
BITTY_PROPERTY_READONLY(std::string, tooltipEditing_RenameAnimation)
Expand Down

0 comments on commit 435118f

Please sign in to comment.