Skip to content

Commit

Permalink
JTextEditor: Fixed bug in GetCharRight() to work for first character …
Browse files Browse the repository at this point in the history
…on line; Fixed bug so original selection is fully cleared after undo/redo
  • Loading branch information
jafl committed Jun 27, 2024
1 parent 6fb3333 commit da1f7d3
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 8 deletions.
3 changes: 3 additions & 0 deletions libjcore/code/JCoreLibVersion.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,9 @@ static const char* kCurrentJCoreLibVersionStr = "4.2.0";
// JError:
// Optimized to store JUtf8Byte* when possible.
// *** Removed 2nd arg from ctor. Call SetMessage() instead.
// JTextEditor:
// Fixed bug in GetCharRight() to work for first character on line.
// Fixed bug so original selection is fully cleared after undo/redo.

// version 4.1.0:
//
Expand Down
17 changes: 9 additions & 8 deletions libjcore/code/JTextEditor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -434,16 +434,23 @@ JTextEditor::Receive
TextRange r = itsSelection;
r.charRange += cd;
r.byteRange += bd;

itsSelection.charRange += cd; // redraw correct range
itsSelection.byteRange += bd;
SetSelection(r, true, true);
}
else if (!itsSelection.IsEmpty() &&
r.charRange.first < itsSelection.charRange.first)
{
itsSelection.charRange += cd; // redraw correct range
itsSelection.byteRange += bd;
SetCaretLocation(CalcCaretLocation(r.GetFirst()));
}
else if (!itsSelection.IsEmpty() &&
r.charRange.first < itsSelection.charRange.last)
{
itsSelection.charRange.last += cd; // redraw correct range
itsSelection.byteRange.last += bd;
SetCaretLocation(CalcCaretLocation(itsSelection.GetFirst()));
}

Expand Down Expand Up @@ -2922,7 +2929,7 @@ JTextEditor::SetCaretLocation

itsText->DeactivateCurrentUndo();

const bool hadSelection = !itsSelection.IsEmpty();
const bool hadSelection = !itsSelection.IsEmpty();
const CaretLocation origCaretLoc = itsCaret;

if (hadSelection)
Expand Down Expand Up @@ -3618,13 +3625,7 @@ JTextEditor::GetCharRight
const
{
const TextIndex firstChar = GetLineStart(charLoc.lineIndex);

JCoordinate x = 0;
if (charLoc.location.charIndex > firstChar.charIndex)
{
x = GetStringWidth(firstChar, charLoc.location, nullptr);
}
return x;
return GetStringWidth(firstChar, charLoc.location, nullptr);
}

/******************************************************************************
Expand Down

0 comments on commit da1f7d3

Please sign in to comment.