File tree Expand file tree Collapse file tree 1 file changed +4
-2
lines changed
Expand file tree Collapse file tree 1 file changed +4
-2
lines changed Original file line number Diff line number Diff line change @@ -115,9 +115,10 @@ TextSelect::Selection TextSelect::getSelection() const {
115115void TextSelect::handleMouseDown (const ImVec2& cursorPosStart) {
116116 const float textHeight = ImGui::GetTextLineHeightWithSpacing ();
117117 ImVec2 mousePos = ImGui::GetMousePos () - cursorPosStart;
118+ std::size_t numLines = getNumLines ();
118119
119120 // Get Y position of mouse cursor, in terms of line number (capped to the index of the last line)
120- std::size_t y = std::min (static_cast <std::size_t >(std::floor (mousePos.y / textHeight)), getNumLines () - 1 );
121+ std::size_t y = std::min (static_cast <std::size_t >(std::floor (mousePos.y / textHeight)), numLines - 1 );
121122 if (y < 0 ) return ;
122123
123124 std::string_view currentLine = getLineAtIdx (y);
@@ -127,8 +128,9 @@ void TextSelect::handleMouseDown(const ImVec2& cursorPosStart) {
127128 if (int mouseClicks = ImGui::GetMouseClickedCount (ImGuiMouseButton_Left); mouseClicks > 0 ) {
128129 if (mouseClicks % 3 == 0 ) {
129130 // Triple click - select line
131+ bool atLastLine = y == (numLines - 1 );
130132 selectStart = { 0 , y };
131- selectEnd = { utf8Length (currentLine), y };
133+ selectEnd = { atLastLine ? utf8Length (currentLine) : 0 , atLastLine ? y : y + 1 };
132134 } else if (mouseClicks % 2 == 0 ) {
133135 // Double click - select word
134136 // Initialize start and end iterators to current cursor position
You can’t perform that action at this time.
0 commit comments