行を複製

守矢諏訪子 <suwako@076.moe>、2026-06-29 01:58
コミット 6ca9eff36c9368fc62ac643ccd3274988b389881 ・親 7e5b0dd ・ファイルを見る

7個のファイル、+50 -21

@@ -63,9 +63,10 @@
6363 m_Code = code;
6464 m_Editor.SetText(code);
6565 }
66- void RenderStatusBar(TextEditor editor);
66+ void RenderStatusBar();
6767
6868 void SetTitle(const string &title) { m_Title = title; }
69+ const string &GetTitle() const { return m_Title; }
6970
7071 private:
7172 Info *m_Info;
@@ -42,6 +42,8 @@
4242 #include <backends/imgui_impl_glfw.h>
4343 #include <backends/imgui_impl_opengl3.h>
4444
45+class TextEditor;
46+
4547 namespace glfwpp {
4648 class Window;
4749 } // namespace glfwpp
@@ -63,4 +65,6 @@
6365 ImFont *m_CjkFont;
6466 ImFont *m_MonoFont;
6567 }; // class GuiEngine
68+
69+ void DuplicateLine(TextEditor &editor);
6670 } // namespace gui
変更 main.cc
@@ -44,6 +44,7 @@
4444 #include <iostream>
4545
4646 #include <imgui.h>
47+#include <imgui_internal.h>
4748 #include <backends/imgui_impl_glfw.h>
4849 #include <backends/imgui_impl_opengl3.h>
4950
@@ -626,6 +627,7 @@
626627 bool ctrlMod = (window.GetKey(GLFW_KEY_LEFT_CONTROL) == GLFW_PRESS || window.GetKey(GLFW_KEY_RIGHT_CONTROL) == GLFW_PRESS);
627628 bool shiftMod = (window.GetKey(GLFW_KEY_LEFT_SHIFT) == GLFW_PRESS || window.GetKey(GLFW_KEY_RIGHT_SHIFT) == GLFW_PRESS);
628629 //bool altMod = (window.GetKey(GLFW_KEY_LEFT_ALT) == GLFW_PRESS || window.GetKey(GLFW_KEY_RIGHT_ALT) == GLFW_PRESS);
630+ bool isTab = window.GetKey(GLFW_KEY_TAB) == GLFW_PRESS;
629631
630632 bool isNewKey = (window.GetKey(GLFW_KEY_N) == GLFW_PRESS && ctrlMod);
631633 bool isOpenKey = (window.GetKey(GLFW_KEY_O) == GLFW_PRESS && ctrlMod);
@@ -251,6 +251,8 @@
251251 createWord(db, 2, "editcopy", "Copy");
252252 createWord(db, 1, "editpaste", "貼り付け(P)");
253253 createWord(db, 2, "editpaste", "Paste");
254+ createWord(db, 1, "editselectall", "全て洗濯(A)");
255+ createWord(db, 2, "editselectall", "Select All");
254256 createWord(db, 1, "editduplicate", "行を複製(D)");
255257 createWord(db, 2, "editduplicate", "Duplicate");
256258 createWord(db, 1, "settings", "設定(S)");
@@ -35,6 +35,8 @@
3535 OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
3636 */
3737 #include <gui/editor.hh>
38+#include <gui/guiengine.hh>
39+#include <iostream>
3840
3941 namespace gui {
4042 Editor::Editor(Info *info, string title, string renderName, string code, Languages lang, ImFont *cjkFont, ImFont *monoFont) : m_Info(info) {
@@ -81,20 +83,19 @@
8183 ImGui::PopFont();
8284
8385 // CTRL + D
84- //if (ImGui::IsWindowFocused(ImGuiFocusedFlags_RootAndChildWindows)) {
85- // bool ctrl = ImGui::GetIO().KeyCtrl;
86+ if (ImGui::IsWindowFocused(ImGuiFocusedFlags_RootAndChildWindows)) {
87+ bool ctrl = ImGui::GetIO().KeyCtrl;
8688
87- // if (ctrl && ImGui::IsKeyPressed(ImGuiKey_D, false)) {
88- // auto cursor = m_Editor.GetCurrentCursorPosition();
89- // auto lines = m_Editor.GetLineText(cursor.line);
90- // }
91- //}
89+ if (ctrl && ImGui::IsKeyPressed(ImGuiKey_D, false)) {
90+ DuplicateLine(m_Editor);
91+ }
92+ }
9293
93- //RenderStatusBar(m_Editor);
94+ //RenderStatusBar();
9495 ImGui::End();
9596 }
9697
97- void Editor::RenderStatusBar(TextEditor editor) {
98+ void Editor::RenderStatusBar() {
9899 static const char *languages[] = { "Lua", "GLSL", "HLSL" };
99100
100101 static const TextEditor::Language *definitions[] = {
@@ -103,7 +104,7 @@
103104 TextEditor::Language::Hlsl(),
104105 };
105106
106- std::string language = editor.GetLanguageName();
107+ std::string language = m_Editor.GetLanguageName();
107108
108109 ImGui::PushStyleColor(ImGuiCol_ChildBg, ImVec4(0.15f, 0.15f, 0.15f, 1.0f));
109110 ImGui::BeginChild("StatusBar", ImVec2(0.0f, 0.0f), ImGuiChildFlags_Borders);
@@ -114,7 +115,7 @@
114115 bool selected = (language == languages[n]);
115116
116117 if (ImGui::Selectable(languages[n], selected)) {
117- editor.SetLanguage(definitions[n]);
118+ m_Editor.SetLanguage(definitions[n]);
118119 //buildAutocompleteTrie();
119120 }
120121
@@ -131,13 +132,11 @@
131132
132133 int line;
133134 int column;
134- int tabSize = editor.GetTabSize();
135+ int tabSize = m_Editor.GetTabSize();
135136 float glyphWidth = ImGui::CalcTextSize("#").x;
136- editor.GetCurrentCursor(line, column);
137+ m_Editor.GetCurrentCursor(line, column);
137138
138- // determine status message
139139 char status[256];
140-
141140 auto statusSize = std::snprintf(
142141 status,
143142 sizeof(status),
@@ -38,6 +38,7 @@
3838 #include <util/glfwpp.hh>
3939 #include <NotoSansCJKjp-Regular.h>
4040 #include <NotoMono-Regular.h>
41+#include <TextEditor.h>
4142
4243 namespace gui {
4344 GuiEngine::GuiEngine(glfwpp::Window *window) {
@@ -76,5 +77,26 @@
7677 return ImGui::IsWindowFocused(ImGuiFocusedFlags_RootAndChildWindows)
7778 && !ImGui::GetIO().WantTextInput
7879 && ImGui::IsKeyPressed(ImGuiKey_Escape);
80+ }
81+
82+ void DuplicateLine(TextEditor &editor) {
83+ if (ImGui::IsWindowFocused(ImGuiFocusedFlags_RootAndChildWindows)) {
84+ bool ctrl = ImGui::GetIO().KeyCtrl;
85+
86+ if (ctrl && ImGui::IsKeyPressed(ImGuiKey_D, false)) {
87+ cstr clipboard = ImGui::GetClipboardText();
88+ string copyClip = clipboard ? clipboard : "";
89+ auto cursor = editor.GetCurrentCursorPosition();
90+ auto lines = editor.GetLineText(cursor.line);
91+ auto eol = lines.size();
92+
93+ editor.SelectLine(cursor.line);
94+ editor.Copy();
95+ editor.Paste();
96+ editor.Paste();
97+ editor.SetCursor(cursor.line + 1, cursor.column);
98+ ImGui::SetClipboardText(copyClip.c_str());
99+ }
100+ }
79101 }
80102 } // namespace gui
@@ -41,6 +41,7 @@
4141 #include <backends/imgui_impl_glfw.h>
4242 #include <backends/imgui_impl_opengl3.h>
4343 #include <database/locale.hh>
44+//#include <gui/guiengine.hh>
4445 #include <ctime>
4546
4647 namespace gui {
@@ -175,11 +176,9 @@
175176 if (ImGui::MenuItem(info.i18n->GetWord("editselectall").c_str(), "Ctrl+A", false, info.activeEditor)) {
176177 info.activeEditor->SelectAll();
177178 }
178- if (ImGui::MenuItem(info.i18n->GetWord("editduplicate").c_str(), "Ctrl+D", false, info.activeEditor)) {
179- //info.activeEditor->GetLineText(info.activeEditor->GetLineHeight());
180- //info.activeEditor->Copy();
181- //info.activeEditor->Paste();
182- }
179+ //if (ImGui::MenuItem(info.i18n->GetWord("editduplicate").c_str(), "Ctrl+D", false, info.activeEditor)) {
180+ // DuplicateLine(*info.activeEditor);
181+ //}
183182 ImGui::Separator();
184183 if (ImGui::MenuItem(info.i18n->GetWord("settings").c_str(), "Ctrl+,")) {
185184 info.isSettings = true;