行を複製
守矢諏訪子 <suwako@076.moe>、2026-06-29 01:58
コミット 6ca9eff36c9368fc62ac643ccd3274988b389881
・親 7e5b0dd
・ファイルを見る
7個のファイル、+50 -21
| @@ -63,9 +63,10 @@ | ||
| 63 | 63 | m_Code = code; |
| 64 | 64 | m_Editor.SetText(code); |
| 65 | 65 | } |
| 66 | - void RenderStatusBar(TextEditor editor); | |
| 66 | + void RenderStatusBar(); | |
| 67 | 67 | |
| 68 | 68 | void SetTitle(const string &title) { m_Title = title; } |
| 69 | + const string &GetTitle() const { return m_Title; } | |
| 69 | 70 | |
| 70 | 71 | private: |
| 71 | 72 | Info *m_Info; |
| @@ -42,6 +42,8 @@ | ||
| 42 | 42 | #include <backends/imgui_impl_glfw.h> |
| 43 | 43 | #include <backends/imgui_impl_opengl3.h> |
| 44 | 44 | |
| 45 | +class TextEditor; | |
| 46 | + | |
| 45 | 47 | namespace glfwpp { |
| 46 | 48 | class Window; |
| 47 | 49 | } // namespace glfwpp |
| @@ -63,4 +65,6 @@ | ||
| 63 | 65 | ImFont *m_CjkFont; |
| 64 | 66 | ImFont *m_MonoFont; |
| 65 | 67 | }; // class GuiEngine |
| 68 | + | |
| 69 | + void DuplicateLine(TextEditor &editor); | |
| 66 | 70 | } // namespace gui |
変更
main.cc
| @@ -44,6 +44,7 @@ | ||
| 44 | 44 | #include <iostream> |
| 45 | 45 | |
| 46 | 46 | #include <imgui.h> |
| 47 | +#include <imgui_internal.h> | |
| 47 | 48 | #include <backends/imgui_impl_glfw.h> |
| 48 | 49 | #include <backends/imgui_impl_opengl3.h> |
| 49 | 50 | |
| @@ -626,6 +627,7 @@ | ||
| 626 | 627 | bool ctrlMod = (window.GetKey(GLFW_KEY_LEFT_CONTROL) == GLFW_PRESS || window.GetKey(GLFW_KEY_RIGHT_CONTROL) == GLFW_PRESS); |
| 627 | 628 | bool shiftMod = (window.GetKey(GLFW_KEY_LEFT_SHIFT) == GLFW_PRESS || window.GetKey(GLFW_KEY_RIGHT_SHIFT) == GLFW_PRESS); |
| 628 | 629 | //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; | |
| 629 | 631 | |
| 630 | 632 | bool isNewKey = (window.GetKey(GLFW_KEY_N) == GLFW_PRESS && ctrlMod); |
| 631 | 633 | bool isOpenKey = (window.GetKey(GLFW_KEY_O) == GLFW_PRESS && ctrlMod); |
| @@ -251,6 +251,8 @@ | ||
| 251 | 251 | createWord(db, 2, "editcopy", "Copy"); |
| 252 | 252 | createWord(db, 1, "editpaste", "貼り付け(P)"); |
| 253 | 253 | createWord(db, 2, "editpaste", "Paste"); |
| 254 | + createWord(db, 1, "editselectall", "全て洗濯(A)"); | |
| 255 | + createWord(db, 2, "editselectall", "Select All"); | |
| 254 | 256 | createWord(db, 1, "editduplicate", "行を複製(D)"); |
| 255 | 257 | createWord(db, 2, "editduplicate", "Duplicate"); |
| 256 | 258 | createWord(db, 1, "settings", "設定(S)"); |
| @@ -35,6 +35,8 @@ | ||
| 35 | 35 | OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
| 36 | 36 | */ |
| 37 | 37 | #include <gui/editor.hh> |
| 38 | +#include <gui/guiengine.hh> | |
| 39 | +#include <iostream> | |
| 38 | 40 | |
| 39 | 41 | namespace gui { |
| 40 | 42 | Editor::Editor(Info *info, string title, string renderName, string code, Languages lang, ImFont *cjkFont, ImFont *monoFont) : m_Info(info) { |
| @@ -81,20 +83,19 @@ | ||
| 81 | 83 | ImGui::PopFont(); |
| 82 | 84 | |
| 83 | 85 | // 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; | |
| 86 | 88 | |
| 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 | + } | |
| 92 | 93 | |
| 93 | - //RenderStatusBar(m_Editor); | |
| 94 | + //RenderStatusBar(); | |
| 94 | 95 | ImGui::End(); |
| 95 | 96 | } |
| 96 | 97 | |
| 97 | - void Editor::RenderStatusBar(TextEditor editor) { | |
| 98 | + void Editor::RenderStatusBar() { | |
| 98 | 99 | static const char *languages[] = { "Lua", "GLSL", "HLSL" }; |
| 99 | 100 | |
| 100 | 101 | static const TextEditor::Language *definitions[] = { |
| @@ -103,7 +104,7 @@ | ||
| 103 | 104 | TextEditor::Language::Hlsl(), |
| 104 | 105 | }; |
| 105 | 106 | |
| 106 | - std::string language = editor.GetLanguageName(); | |
| 107 | + std::string language = m_Editor.GetLanguageName(); | |
| 107 | 108 | |
| 108 | 109 | ImGui::PushStyleColor(ImGuiCol_ChildBg, ImVec4(0.15f, 0.15f, 0.15f, 1.0f)); |
| 109 | 110 | ImGui::BeginChild("StatusBar", ImVec2(0.0f, 0.0f), ImGuiChildFlags_Borders); |
| @@ -114,7 +115,7 @@ | ||
| 114 | 115 | bool selected = (language == languages[n]); |
| 115 | 116 | |
| 116 | 117 | if (ImGui::Selectable(languages[n], selected)) { |
| 117 | - editor.SetLanguage(definitions[n]); | |
| 118 | + m_Editor.SetLanguage(definitions[n]); | |
| 118 | 119 | //buildAutocompleteTrie(); |
| 119 | 120 | } |
| 120 | 121 | |
| @@ -131,13 +132,11 @@ | ||
| 131 | 132 | |
| 132 | 133 | int line; |
| 133 | 134 | int column; |
| 134 | - int tabSize = editor.GetTabSize(); | |
| 135 | + int tabSize = m_Editor.GetTabSize(); | |
| 135 | 136 | float glyphWidth = ImGui::CalcTextSize("#").x; |
| 136 | - editor.GetCurrentCursor(line, column); | |
| 137 | + m_Editor.GetCurrentCursor(line, column); | |
| 137 | 138 | |
| 138 | - // determine status message | |
| 139 | 139 | char status[256]; |
| 140 | - | |
| 141 | 140 | auto statusSize = std::snprintf( |
| 142 | 141 | status, |
| 143 | 142 | sizeof(status), |
| @@ -38,6 +38,7 @@ | ||
| 38 | 38 | #include <util/glfwpp.hh> |
| 39 | 39 | #include <NotoSansCJKjp-Regular.h> |
| 40 | 40 | #include <NotoMono-Regular.h> |
| 41 | +#include <TextEditor.h> | |
| 41 | 42 | |
| 42 | 43 | namespace gui { |
| 43 | 44 | GuiEngine::GuiEngine(glfwpp::Window *window) { |
| @@ -76,5 +77,26 @@ | ||
| 76 | 77 | return ImGui::IsWindowFocused(ImGuiFocusedFlags_RootAndChildWindows) |
| 77 | 78 | && !ImGui::GetIO().WantTextInput |
| 78 | 79 | && 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 | + } | |
| 79 | 101 | } |
| 80 | 102 | } // namespace gui |
| @@ -41,6 +41,7 @@ | ||
| 41 | 41 | #include <backends/imgui_impl_glfw.h> |
| 42 | 42 | #include <backends/imgui_impl_opengl3.h> |
| 43 | 43 | #include <database/locale.hh> |
| 44 | +//#include <gui/guiengine.hh> | |
| 44 | 45 | #include <ctime> |
| 45 | 46 | |
| 46 | 47 | namespace gui { |
| @@ -175,11 +176,9 @@ | ||
| 175 | 176 | if (ImGui::MenuItem(info.i18n->GetWord("editselectall").c_str(), "Ctrl+A", false, info.activeEditor)) { |
| 176 | 177 | info.activeEditor->SelectAll(); |
| 177 | 178 | } |
| 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 | + //} | |
| 183 | 182 | ImGui::Separator(); |
| 184 | 183 | if (ImGui::MenuItem(info.i18n->GetWord("settings").c_str(), "Ctrl+,")) { |
| 185 | 184 | info.isSettings = true; |