Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 11 additions & 9 deletions TextEditor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -336,16 +336,14 @@ TextEditor::Coordinates TextEditor::ScreenPosToCoordinates(const ImVec2& aPositi
{
auto& line = mLines.at(lineNo);

int columnIndex = 0;
std::string cumulatedString = "";
float columnWidth = 0.0f;
float columnX = 0.0f;
int delta = 0;


// First we find the hovered column coord.
while (mTextStart + columnX - (aInsertionMode ? 0.5f : 0.0f) * columnWidth < local.x && (size_t)columnIndex < line.size())
for (size_t columnIndex = 0; columnIndex < line.size(); ++columnIndex)
{
columnCoord += delta;
float columnWidth = 0.0f;
int delta = 0;

if (line[columnIndex].mChar == '\t')
{
float oldX = columnX;
Expand All @@ -365,7 +363,11 @@ TextEditor::Coordinates TextEditor::ScreenPosToCoordinates(const ImVec2& aPositi
columnX += columnWidth;
delta = 1;
}
++columnIndex;

if (mTextStart + columnX - (aInsertionMode ? 0.5f : 0.0f) * columnWidth < local.x)
columnCoord += delta;
else
break;
}

// Then we reduce by 1 column coord if cursor is on the left side of the hovered column.
Expand Down Expand Up @@ -1122,7 +1124,7 @@ void TextEditor::Render()
if (local.x >= mTextStart)
{
auto pos = ScreenPosToCoordinates(mpos);
printf("Coord(%d, %d)\n", pos.mLine, pos.mColumn);
//printf("Coord(%d, %d)\n", pos.mLine, pos.mColumn);
auto id = GetWordAt(pos);
if (!id.empty())
{
Expand Down