@@ -170,6 +170,7 @@ void TextEditor::render(const char* title, const ImVec2& size, bool border) {
170170 ImGui::PushStyleVar (ImGuiStyleVar_ItemSpacing, ImVec2 (0 .0f , 0 .0f ));
171171 ImGui::PushStyleColor (ImGuiCol_ChildBg, ImGui::ColorConvertU32ToFloat4 (palette.get (Color::background)));
172172 ImGui::BeginChild (title, size, border, ImGuiWindowFlags_NoMove | ImGuiWindowFlags_HorizontalScrollbar | ImGuiWindowFlags_NoNavInputs);
173+ lastRenderOrigin = ImGui::GetCursorScreenPos ();
173174
174175 // handle keyboard and mouse inputs
175176 handleKeyboardInputs ();
@@ -1306,6 +1307,30 @@ std::string TextEditor::getCursorText(size_t cursor) const {
13061307}
13071308
13081309
1310+ //
1311+ // TextEditor::GetWordAtScreenPos
1312+ //
1313+
1314+ std::string TextEditor::GetWordAtScreenPos (const ImVec2& screenPos) const {
1315+ // Convert screen position to local coordinates using the origin saved during last Render()
1316+ auto local = screenPos - lastRenderOrigin;
1317+
1318+ // Convert to text coordinates using the same logic as handleMouseInteractions()
1319+ Coordinate glyphCoordinate;
1320+ Coordinate cursorCoordinate;
1321+ document.normalizeCoordinate (
1322+ local.y / glyphSize.y ,
1323+ (local.x - textOffset) / glyphSize.x ,
1324+ glyphCoordinate,
1325+ cursorCoordinate);
1326+
1327+ // Find word boundaries and extract text
1328+ auto start = document.findWordStart (glyphCoordinate);
1329+ auto end = document.findWordEnd (glyphCoordinate);
1330+ return document.getSectionText (start, end);
1331+ }
1332+
1333+
13091334//
13101335// TextEditor::makeCursorVisible
13111336//
0 commit comments