Skip to content
Open
Show file tree
Hide file tree
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
2 changes: 1 addition & 1 deletion CONTRIBUTING
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,6 @@ Whem contributing, please follow the following guidelines. I will keep it update
- Please submit to the 'dev' branch first for testing, and it will be merged to 'main' if it seems to work fine. I would like try keep 'master' in a good working condition, as more and more people are using it.
- Please send your submissions in small, well defined requests, i. e. do not accumulate many unrelated changes in one large pull request. Keep your submissions as small as possible, it will make everyone's life easier.
- Avoid using ImGui internal since it would make the source fragile against internal changes in ImGui.
- Try to keep the perormance high within the render function. Try to avoid doing anything which leads to memory allocations (like using temporary std::string, std::vector variables), or complex algorithm. If you really have to, try to amortise it between frames.
- Try to keep the performance high within the render function. Try to avoid doing anything which leads to memory allocations (like using temporary std::string, std::vector variables), or complex algorithm. If you really have to, try to amortise it between frames.

Thank you. :)
30 changes: 15 additions & 15 deletions TextEditor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1149,7 +1149,7 @@ void TextEditor::Render()
}


ImGui::Dummy(ImVec2((longest + 2), mLines.size() * mCharAdvance.y));
ImGui::Dummy(ImVec2((longest + 2 + 4.0f * mCharAdvance.x), mLines.size() * mCharAdvance.y));

if (mScrollToCursor)
{
Expand Down Expand Up @@ -2479,23 +2479,23 @@ void TextEditor::EnsureCursorVisible()
auto height = ImGui::GetWindowHeight();
auto width = ImGui::GetWindowWidth();

auto top = 1 + (int)ceil(scrollY / mCharAdvance.y);
auto bottom = (int)ceil((scrollY + height) / mCharAdvance.y);

auto left = (int)ceil(scrollX / mCharAdvance.x);
auto right = (int)ceil((scrollX + width) / mCharAdvance.x);

auto pos = GetActualCursorCoordinates();
auto len = TextDistanceToLineStart(pos);

if (pos.mLine < top)
ImGui::SetScrollY(std::max(0.0f, (pos.mLine - 1) * mCharAdvance.y));
if (pos.mLine > bottom - 4)
ImGui::SetScrollY(std::max(0.0f, (pos.mLine + 4) * mCharAdvance.y - height));
if (len + mTextStart < left + 4)
ImGui::SetScrollX(std::max(0.0f, len + mTextStart - 4));
if (len + mTextStart > right - 4)
ImGui::SetScrollX(std::max(0.0f, len + mTextStart + 4 - width));
float padX = std::min(4.0f * mCharAdvance.x, width * 0.25f);

float cursorPosY = pos.mLine * mCharAdvance.y;
float cursorPosX = len + mTextStart;

if (cursorPosY < scrollY)
ImGui::SetScrollY(std::max(0.0f, cursorPosY));
if (cursorPosY + mCharAdvance.y > scrollY + height)
ImGui::SetScrollY(std::max(0.0f, cursorPosY + mCharAdvance.y - height));

if (cursorPosX < scrollX + padX)
ImGui::SetScrollX(std::max(0.0f, cursorPosX - padX));
if (cursorPosX > scrollX + width - padX)
ImGui::SetScrollX(std::max(0.0f, cursorPosX - width + padX));
}

int TextEditor::GetPageSize() const
Expand Down