aboutsummaryrefslogtreecommitdiff
path: root/source/EditorCommandPalette.cpp
blob: 02ff65a5fb2447652af708e80875a0a306c42b3c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
#include "EditorCommandPalette.hpp"

#include "FuzzyMatch.hpp"

#include <imgui.h>
#include <algorithm>
#include <cstring>
#include <limits>
#include <utility>

#define IMGUI_DEFINE_MATH_OPERATORS
#include <imgui_internal.h>

namespace ImCmd {
// =================================================================
// Private forward decls
// =================================================================

struct StackFrame;
class ExecutionManager;

struct SearchResult;
class SearchManager;

struct CommandOperationRegister;
struct CommandOperationUnregister;
struct CommandOperation;
struct Context;

struct ItemExtraData;
struct Instance;

// =================================================================
// Private interface
// =================================================================

struct StackFrame {
	std::vector<std::string> Options;
	int SelectedOption = -1;
};

class ExecutionManager {
private:
	Instance* m_Instance;
	Command* m_ExecutingCommand = nullptr;
	std::vector<StackFrame> m_CallStack;

public:
	ExecutionManager(Instance& instance)
		: m_Instance{ &instance } {}

	int GetItemCount() const;
	const char* GetItem(int idx) const;
	void SelectItem(int idx);

	void PushOptions(std::vector<std::string> options);
};

struct SearchResult {
	int ItemIndex;
	int Score;
	int MatchCount;
	uint8_t Matches[32];
};

class SearchManager {
private:
	Instance* m_Instance;

public:
	std::vector<SearchResult> SearchResults;
	char SearchText[std::numeric_limits<uint8_t>::max() + 1];

public:
	SearchManager(Instance& instance)
		: m_Instance{ &instance } {
		std::memset(SearchText, 0, sizeof(SearchText));
	}

	int GetItemCount() const;
	const char* GetItem(int idx) const;

	bool IsActive() const;

	void SetSearchText(const char* text);
	void ClearSearchText();
	void RefreshSearchResults();
};

struct CommandOperationRegister {
	Command Candidate;
};

struct CommandOperationUnregister {
	const char* Name;
};

struct CommandOperation {
	enum OpType {
		OpType_Register,
		OpType_Unregister,
	};

	OpType Type;
	int Index;
};

struct Context {
	ImGuiStorage Instances;
	Instance* CurrentCommandPalette = nullptr;
	std::vector<Command> Commands;
	std::vector<CommandOperationRegister> PendingRegisterOps;
	std::vector<CommandOperationUnregister> PendingUnregisterOps;
	std::vector<CommandOperation> PendingOps;
	ImFont* Fonts[ImCmdTextType_COUNT] = {};
	ImU32 FontColors[ImCmdTextType_COUNT] = {};
	int CommandStorageLocks = 0;
	bool HasFontColorOverride[ImCmdTextType_COUNT] = {};
	bool IsExecuting = false;
	bool IsTerminating = false;

	struct
	{
		bool ItemSelected = false;
	} LastCommandPaletteStatus;

	struct
	{
		const char* NewSearchText = nullptr;
		bool FocusSearchBox = false;
	} NextCommandPaletteActions;

	void RegisterCommand(Command command) {
		auto location = std::lower_bound(
			Commands.begin(),
			Commands.end(),
			command,
			[](const Command& a, const Command& b) -> bool {
				return strcmp(a.Name, b.Name) < 0;
			});
		Commands.insert(location, std::move(command));
	}

	bool UnregisterCommand(const char* name) {
		struct Comparator {
			bool operator()(const Command& command, const char* str) const {
				return strcmp(command.Name, str) < 0;
			}

			bool operator()(const char* str, const Command& command) const {
				return strcmp(str, command.Name) < 0;
			}
		};

		auto range = std::equal_range(Commands.begin(), Commands.end(), name, Comparator{});
		Commands.erase(range.first, range.second);

		return range.first != range.second;
	}

	bool CommitOps() {
		if (IsCommandStorageLocked()) {
			return false;
		}

		for (auto& operation : PendingOps) {
			switch (operation.Type) {
				case CommandOperation::OpType_Register: {
					auto& op = PendingRegisterOps[operation.Index];
					RegisterCommand(std::move(op.Candidate));
				} break;

				case CommandOperation::OpType_Unregister: {
					auto& op = PendingUnregisterOps[operation.Index];
					UnregisterCommand(op.Name);
				} break;
			}
		}

		bool had_action = !PendingOps.empty();
		PendingRegisterOps.clear();
		PendingUnregisterOps.clear();
		PendingOps.clear();

		return had_action;
	}

	bool IsCommandStorageLocked() const {
		return CommandStorageLocks > 0;
	}
};

struct ItemExtraData {
	bool Hovered = false;
	bool Held = false;
};

struct Instance {
	ExecutionManager Session;
	SearchManager Search;
	std::vector<ItemExtraData> ExtraData;

	int CurrentSelectedItem = 0;

	struct
	{
		bool RefreshSearch = false;
		bool ClearSearch = false;
	} PendingActions;

	Instance()
		: Session(*this)
		, Search(*this) {}
};

static Context gContext;

// =================================================================
// Private implementation
// =================================================================

int ExecutionManager::GetItemCount() const {
	if (m_ExecutingCommand) {
		return static_cast<int>(m_CallStack.back().Options.size());
	} else {
		return static_cast<int>(gContext.Commands.size());
	}
}

const char* ExecutionManager::GetItem(int idx) const {
	if (m_ExecutingCommand) {
		return m_CallStack.back().Options[idx].c_str();
	} else {
		return gContext.Commands[idx].Name;
	}
}

template <class... Ts>
static void InvokeSafe(const std::function<void(Ts...)>& func, Ts... args) {
	if (func) {
		func(std::forward<Ts>(args)...);
	}
}

void ExecutionManager::SelectItem(int idx) {
	auto cmd = m_ExecutingCommand;
	size_t initial_call_stack_height = m_CallStack.size();
	if (cmd == nullptr) {
		cmd = m_ExecutingCommand = &gContext.Commands[idx];
		++gContext.CommandStorageLocks;

		gContext.IsExecuting = true;
		InvokeSafe(m_ExecutingCommand->InitialCallback); // Calls ::Prompt()
		gContext.IsExecuting = false;
	} else {
		m_CallStack.back().SelectedOption = idx;

		gContext.IsExecuting = true;
		InvokeSafe(cmd->SubsequentCallback, idx); // Calls ::Prompt()
		gContext.IsExecuting = false;
	}

	size_t final_call_stack_height = m_CallStack.size();
	if (initial_call_stack_height == final_call_stack_height) {

		gContext.IsTerminating = true;
		InvokeSafe(m_ExecutingCommand->TerminatingCallback); // Shouldn't call ::Prompt()
		gContext.IsTerminating = false;

		m_ExecutingCommand = nullptr;
		m_CallStack.clear();
		--gContext.CommandStorageLocks;

		// If the executed command involved subcommands...
		if (final_call_stack_height > 0) {
			m_Instance->PendingActions.ClearSearch = true;
			m_Instance->CurrentSelectedItem = 0;
		}

		gContext.LastCommandPaletteStatus.ItemSelected = true;
	} else {
		// Something new is prompted
		// It doesn't make sense for "current selected item" to persists through completely different set of options
		m_Instance->PendingActions.ClearSearch = true;
		m_Instance->CurrentSelectedItem = 0;
	}
}

void ExecutionManager::PushOptions(std::vector<std::string> options) {
	m_CallStack.push_back({});
	auto& frame = m_CallStack.back();

	frame.Options = std::move(options);

	m_Instance->PendingActions.ClearSearch = true;
}

int SearchManager::GetItemCount() const {
	return static_cast<int>(SearchResults.size());
}

const char* SearchManager::GetItem(int idx) const {
	int actualIdx = SearchResults[idx].ItemIndex;
	return m_Instance->Session.GetItem(actualIdx);
}

bool SearchManager::IsActive() const {
	return SearchText[0] != '\0';
}

void SearchManager::SetSearchText(const char* text) {
	// Note: must detect clang first because clang-cl.exe defines both _MSC_VER and __clang__, but only accepts #pragma clang
#if defined(__GNUC__)
#	pragma GCC diagnostic push
#	pragma GCC diagnostic ignored "-Wdeprecated-declarations"
#elif defined(__clang__)
#	pragma clang diagnostic push
#	pragma clang diagnostic ignored "-Wdeprecated-declarations"
#elif defined(_MSC_VER)
#	pragma warning(push)
#	pragma warning(disable : 4996)
#endif
	// Copy at most IM_ARRAYSIZE(SearchText) chars from `text` to `SearchText`
	std::strncpy(SearchText, text, IM_ARRAYSIZE(SearchText));
#if defined(__GNUC__)
#	pragma GCC diagnostic pop
#elif defined(__clang__)
#	pragma clang diagnostic pop
#elif defined(_MSC_VER)
#	pragma warning(pop)
#endif
	RefreshSearchResults();
}

void SearchManager::ClearSearchText() {
	std::memset(SearchText, 0, IM_ARRAYSIZE(SearchText));
	SearchResults.clear();
}

void SearchManager::RefreshSearchResults() {
	m_Instance->CurrentSelectedItem = 0;
	SearchResults.clear();

	int item_count = m_Instance->Session.GetItemCount();
	for (int i = 0; i < item_count; ++i) {
		const char* text = m_Instance->Session.GetItem(i);
		SearchResult result;
		if (FuzzyMatch::Search(SearchText, text, result.Score, result.Matches, IM_ARRAYSIZE(result.Matches), result.MatchCount)) {
			result.ItemIndex = i;
			SearchResults.push_back(result);
		}
	}

	std::sort(
		SearchResults.begin(),
		SearchResults.end(),
		[](const SearchResult& a, const SearchResult& b) -> bool {
			// We want the biggest element first
			return a.Score > b.Score;
		});
}

// =================================================================
// API implementation
// =================================================================

void AddCommand(Command command) {
	if (gContext.IsCommandStorageLocked()) {
		gContext.PendingRegisterOps.push_back(CommandOperationRegister{ std::move(command) });
		CommandOperation op;
		op.Type = CommandOperation::OpType_Register;
		op.Index = static_cast<int>(gContext.PendingRegisterOps.size()) - 1;
		gContext.PendingOps.push_back(op);
	} else {
		gContext.RegisterCommand(std::move(command));
	}

	if (auto current = gContext.CurrentCommandPalette) {
		current->PendingActions.RefreshSearch = true;
	}
}

void RemoveCommand(const char* name) {
	if (gContext.IsCommandStorageLocked()) {
		gContext.PendingUnregisterOps.push_back(CommandOperationUnregister{ name });
		CommandOperation op;
		op.Type = CommandOperation::OpType_Unregister;
		op.Index = static_cast<int>(gContext.PendingUnregisterOps.size()) - 1;
		gContext.PendingOps.push_back(op);
	} else {
		gContext.UnregisterCommand(name);
	}

	if (auto current = gContext.CurrentCommandPalette) {
		current->PendingActions.RefreshSearch = true;
	}
}

void SetStyleFont(ImCmdTextType type, ImFont* font) {
	gContext.Fonts[type] = font;
}

void SetStyleColor(ImCmdTextType type, ImU32 color) {
	gContext.FontColors[type] = color;
	gContext.HasFontColorOverride[type] = true;
}

void ClearStyleColor(ImCmdTextType type) {
	gContext.HasFontColorOverride[type] = false;
}

void SetNextCommandPaletteSearch(const char* text) {
	IM_ASSERT(text != nullptr);
	gContext.NextCommandPaletteActions.NewSearchText = text;
}

void SetNextCommandPaletteSearchBoxFocused() {
	gContext.NextCommandPaletteActions.FocusSearchBox = true;
}

void ShowCommandPalette(const char* name) {
	auto& gi = *[&]() {
		auto id = ImHashStr(name);
		if (auto ptr = gContext.Instances.GetVoidPtr(id)) {
			return reinterpret_cast<Instance*>(ptr);
		} else {
			auto instance = new Instance();
			gContext.Instances.SetVoidPtr(id, instance);
			return instance;
		}
	}();

	float width = ImGui::GetWindowContentRegionMax().x - ImGui::GetWindowContentRegionMin().x;
	float search_result_window_height = 400.0f; // TODO config

	// BEGIN this command palette
	gContext.CurrentCommandPalette = &gi;
	ImGui::PushID(name);

	gContext.LastCommandPaletteStatus = {};

	// BEGIN processing PendingActions
	bool refresh_search = gi.PendingActions.RefreshSearch;
	refresh_search |= gContext.CommitOps();

	if (auto text = gContext.NextCommandPaletteActions.NewSearchText) {
		refresh_search = false;
		if (text[0] == '\0') {
			gi.Search.ClearSearchText();
		} else {
			gi.Search.SetSearchText(text);
		}
	} else if (gi.PendingActions.ClearSearch) {
		refresh_search = false;
		gi.Search.ClearSearchText();
	}

	if (refresh_search) {
		gi.Search.RefreshSearchResults();
	}

	gi.PendingActions = {};
	// END procesisng PendingActions

	if (gContext.NextCommandPaletteActions.FocusSearchBox) {
		// Focus the search box when user first brings command palette window up
		// Note: this only affects the next frame
		ImGui::SetKeyboardFocusHere(0);
	}
	ImGui::SetNextItemWidth(width);
	if (ImGui::InputText("##SearchBox", gi.Search.SearchText, IM_ARRAYSIZE(gi.Search.SearchText))) {
		// Search string updated, update search results
		gi.Search.RefreshSearchResults();
	}

	ImGui::BeginChild("SearchResults", ImVec2(width, search_result_window_height));

	auto window = ImGui::GetCurrentWindow();
	auto draw_list = window->DrawList;

	auto font_regular = gContext.Fonts[ImCmdTextType_Regular];
	if (!font_regular) {
		font_regular = ImGui::GetDrawListSharedData()->Font;
	}
	auto font_highlight = gContext.Fonts[ImCmdTextType_Highlight];
	if (!font_highlight) {
		font_highlight = ImGui::GetDrawListSharedData()->Font;
	}

	ImU32 text_color_regular;
	ImU32 text_color_highlight;
	if (gContext.HasFontColorOverride[ImCmdTextType_Regular]) {
		text_color_regular = gContext.FontColors[ImCmdTextType_Regular];
	} else {
		text_color_regular = ImGui::GetColorU32(ImGuiCol_Text);
	}
	if (gContext.HasFontColorOverride[ImCmdTextType_Highlight]) {
		text_color_highlight = gContext.FontColors[ImCmdTextType_Highlight];
	} else {
		text_color_highlight = ImGui::GetColorU32(ImGuiCol_Text);
	}

	auto item_hovered_color = ImGui::GetColorU32(ImGuiCol_HeaderHovered);
	auto item_active_color = ImGui::GetColorU32(ImGuiCol_HeaderActive);
	auto item_selected_color = ImGui::GetColorU32(ImGuiCol_Header);

	int item_count;
	if (gi.Search.IsActive()) {
		item_count = gi.Search.GetItemCount();
	} else {
		item_count = gi.Session.GetItemCount();
	}

	if (gi.ExtraData.size() < item_count) {
		gi.ExtraData.resize(item_count);
	}

	// Flag used to delay item selection until after the loop ends
	bool select_focused_item = false;
	for (int i = 0; i < item_count; ++i) {
		auto id = window->GetID(static_cast<int>(i));

		ImVec2 size{
			ImGui::GetContentRegionAvail().x,
			ImMax(font_regular->FontSize, font_highlight->FontSize),
		};
		ImRect rect{
			window->DC.CursorPos,
			window->DC.CursorPos + ImGui::CalcItemSize(size, 0.0f, 0.0f),
		};

		bool& hovered = gi.ExtraData[i].Hovered;
		bool& held = gi.ExtraData[i].Held;
		if (held && hovered) {
			draw_list->AddRectFilled(rect.Min, rect.Max, item_active_color);
		} else if (hovered) {
			draw_list->AddRectFilled(rect.Min, rect.Max, item_hovered_color);
		} else if (gi.CurrentSelectedItem == i) {
			draw_list->AddRectFilled(rect.Min, rect.Max, item_selected_color);
		}

		if (gi.Search.IsActive()) {
			// Iterating search results: draw text with highlights at matched chars

			auto& search_result = gi.Search.SearchResults[i];
			auto text = gi.Search.GetItem(i);

			auto text_pos = window->DC.CursorPos;
			int range_begin;
			int range_end;
			int last_range_end = 0;

			auto DrawCurrentRange = [&]() {
				if (range_begin != last_range_end) {
					// Draw normal text between last highlighted range end and current highlighted range start
					auto begin = text + last_range_end;
					auto end = text + range_begin;
					draw_list->AddText(text_pos, text_color_regular, begin, end);

					auto segment_size = font_regular->CalcTextSizeA(font_regular->FontSize, std::numeric_limits<float>::max(), 0.0f, begin, end);
					text_pos.x += segment_size.x;
				}

				auto begin = text + range_begin;
				auto end = text + range_end;
				draw_list->AddText(font_highlight, font_highlight->FontSize, text_pos, text_color_highlight, begin, end);

				auto segment_size = font_highlight->CalcTextSizeA(font_highlight->FontSize, std::numeric_limits<float>::max(), 0.0f, begin, end);
				text_pos.x += segment_size.x;
			};

			IM_ASSERT(search_result.MatchCount >= 1);
			range_begin = search_result.Matches[0];
			range_end = range_begin;

			int last_char_idx = -1;
			for (int j = 0; j < search_result.MatchCount; ++j) {
				int char_idx = search_result.Matches[j];

				if (char_idx == last_char_idx + 1) {
					// These 2 indices are equal, extend our current range by 1
					++range_end;
				} else {
					DrawCurrentRange();
					last_range_end = range_end;
					range_begin = char_idx;
					range_end = char_idx + 1;
				}

				last_char_idx = char_idx;
			}

			// Draw the remaining range (if any)
			if (range_begin != range_end) {
				DrawCurrentRange();
			}

			// Draw the text after the last range (if any)
			draw_list->AddText(text_pos, text_color_regular, text + range_end); // Draw until \0
		} else {
			// Iterating everything else: draw text as-is, there is no highlights

			auto text = gi.Session.GetItem(i);
			auto text_pos = window->DC.CursorPos;
			draw_list->AddText(text_pos, text_color_regular, text);
		}

		ImGui::ItemSize(rect);
		if (!ImGui::ItemAdd(rect, id)) {
			continue;
		}
		if (ImGui::ButtonBehavior(rect, id, &hovered, &held)) {
			gi.CurrentSelectedItem = i;
			select_focused_item = true;
		}
	}

	if (ImGui::IsKeyPressed(ImGui::GetKeyIndex(ImGuiKey_UpArrow))) {
		gi.CurrentSelectedItem = ImMax(gi.CurrentSelectedItem - 1, 0);
	} else if (ImGui::IsKeyPressed(ImGui::GetKeyIndex(ImGuiKey_DownArrow))) {
		gi.CurrentSelectedItem = ImMin(gi.CurrentSelectedItem + 1, item_count - 1);
	}
	if (ImGui::IsKeyPressed(ImGui::GetKeyIndex(ImGuiKey_Enter)) || select_focused_item) {
		if (gi.Search.IsActive() && !gi.Search.SearchResults.empty()) {
			auto idx = gi.Search.SearchResults[gi.CurrentSelectedItem].ItemIndex;
			gi.Session.SelectItem(idx);
		} else {
			gi.Session.SelectItem(gi.CurrentSelectedItem);
		}
	}

	ImGui::EndChild();

	gContext.NextCommandPaletteActions = {};

	ImGui::PopID();
	gContext.CurrentCommandPalette = nullptr;
	// END this command palette
}

bool IsAnyItemSelected() {
	return gContext.LastCommandPaletteStatus.ItemSelected;
}

void RemoveCache(const char* name) {
	auto& instances = gContext.Instances;
	auto id = ImHashStr(name);
	if (auto ptr = instances.GetVoidPtr(id)) {
		auto instance = reinterpret_cast<Instance*>(ptr);
		instances.SetVoidPtr(id, nullptr);
		delete instance;
	}
}

void RemoveAllCaches() {
	auto& instances = gContext.Instances;
	for (auto& entry : instances.Data) {
		auto instance = reinterpret_cast<Instance*>(entry.val_p);
		entry.val_p = nullptr;
		delete instance;
	}
	instances = {};
}

void SetNextWindowAffixedTop(ImGuiCond cond) {
	auto viewport = ImGui::GetMainViewport()->Size;

	// Center window horizontally, align top vertically
	ImGui::SetNextWindowPos(ImVec2(viewport.x / 2, 0), cond, ImVec2(0.5f, 0.0f));
}

void ShowCommandPaletteWindow(const char* name, bool* p_open) {
	auto viewport = ImGui::GetMainViewport()->Size;

	SetNextWindowAffixedTop();
	ImGui::SetNextWindowSize(ImVec2(viewport.x * 0.3f, 0.0f));
	ImGui::Begin(name, nullptr, ImGuiWindowFlags_NoMove | ImGuiWindowFlags_NoResize | ImGuiWindowFlags_NoTitleBar);

	if (ImGui::IsWindowAppearing()) {
		SetNextCommandPaletteSearchBoxFocused();
	}

	ShowCommandPalette(name);

	if (IsAnyItemSelected()) {
		*p_open = false;
	}
	if (!ImGui::IsWindowFocused(ImGuiFocusedFlags_ChildWindows)) {
		// Close popup when user unfocused the command palette window (clicking elsewhere)
		*p_open = false;
	}

	ImGui::End();
}

void Prompt(std::vector<std::string> options) {
	IM_ASSERT(gContext.CurrentCommandPalette != nullptr);
	IM_ASSERT(gContext.IsExecuting);
	IM_ASSERT(!gContext.IsTerminating);

	auto& gi = *gContext.CurrentCommandPalette;
	gi.Session.PushOptions(std::move(options));
}
} // namespace ImCmd