mirror of
https://github.com/juce-framework/JUCE.git
synced 2026-01-10 23:44:24 +00:00
Fix to TextEditor caret positioning
This commit is contained in:
parent
e180dbb3f2
commit
d73f9bdd74
2 changed files with 13 additions and 7 deletions
|
|
@ -1338,12 +1338,17 @@ void TextEditor::scrollEditorToPositionCaret (const int desiredCaretX,
|
|||
}
|
||||
|
||||
Rectangle<int> TextEditor::getCaretRectangle()
|
||||
{
|
||||
return getCaretRectangleFloat().getSmallestIntegerContainer();
|
||||
}
|
||||
|
||||
Rectangle<float> TextEditor::getCaretRectangleFloat() const
|
||||
{
|
||||
Point<float> anchor;
|
||||
auto cursorHeight = currentFont.getHeight(); // (in case the text is empty and the call below doesn't set this value)
|
||||
getCharPosition (caretPosition, anchor, cursorHeight);
|
||||
|
||||
return { roundToInt (anchor.x), roundToInt (anchor.y), 2, roundToInt (cursorHeight) };
|
||||
return { anchor.x, anchor.y, 2.0f, cursorHeight };
|
||||
}
|
||||
|
||||
//==============================================================================
|
||||
|
|
@ -1837,7 +1842,7 @@ bool TextEditor::moveCaretUp (bool selecting)
|
|||
if (! isMultiLine())
|
||||
return moveCaretToStartOfLine (selecting);
|
||||
|
||||
auto caretPos = getCaretRectangle().toFloat();
|
||||
auto caretPos = getCaretRectangleFloat();
|
||||
return moveCaretWithTransaction (indexAtPosition (caretPos.getX(), caretPos.getY() - 1.0f), selecting);
|
||||
}
|
||||
|
||||
|
|
@ -1846,7 +1851,7 @@ bool TextEditor::moveCaretDown (bool selecting)
|
|||
if (! isMultiLine())
|
||||
return moveCaretToEndOfLine (selecting);
|
||||
|
||||
auto caretPos = getCaretRectangle().toFloat();
|
||||
auto caretPos = getCaretRectangleFloat();
|
||||
return moveCaretWithTransaction (indexAtPosition (caretPos.getX(), caretPos.getBottom() + 1.0f), selecting);
|
||||
}
|
||||
|
||||
|
|
@ -1855,7 +1860,7 @@ bool TextEditor::pageUp (bool selecting)
|
|||
if (! isMultiLine())
|
||||
return moveCaretToStartOfLine (selecting);
|
||||
|
||||
auto caretPos = getCaretRectangle().toFloat();
|
||||
auto caretPos = getCaretRectangleFloat();
|
||||
return moveCaretWithTransaction (indexAtPosition (caretPos.getX(), caretPos.getY() - viewport->getViewHeight()), selecting);
|
||||
}
|
||||
|
||||
|
|
@ -1864,7 +1869,7 @@ bool TextEditor::pageDown (bool selecting)
|
|||
if (! isMultiLine())
|
||||
return moveCaretToEndOfLine (selecting);
|
||||
|
||||
auto caretPos = getCaretRectangle().toFloat();
|
||||
auto caretPos = getCaretRectangleFloat();
|
||||
return moveCaretWithTransaction (indexAtPosition (caretPos.getX(), caretPos.getBottom() + viewport->getViewHeight()), selecting);
|
||||
}
|
||||
|
||||
|
|
@ -1892,7 +1897,7 @@ bool TextEditor::moveCaretToTop (bool selecting)
|
|||
|
||||
bool TextEditor::moveCaretToStartOfLine (bool selecting)
|
||||
{
|
||||
auto caretPos = getCaretRectangle().toFloat();
|
||||
auto caretPos = getCaretRectangleFloat();
|
||||
return moveCaretWithTransaction (indexAtPosition (0.0f, caretPos.getY()), selecting);
|
||||
}
|
||||
|
||||
|
|
@ -1903,7 +1908,7 @@ bool TextEditor::moveCaretToEnd (bool selecting)
|
|||
|
||||
bool TextEditor::moveCaretToEndOfLine (bool selecting)
|
||||
{
|
||||
auto caretPos = getCaretRectangle().toFloat();
|
||||
auto caretPos = getCaretRectangleFloat();
|
||||
return moveCaretWithTransaction (indexAtPosition ((float) textHolder->getWidth(), caretPos.getY()), selecting);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -749,6 +749,7 @@ private:
|
|||
void reinsert (int insertIndex, const OwnedArray<UniformTextSection>&);
|
||||
void remove (Range<int>, UndoManager*, int caretPositionToMoveTo);
|
||||
void getCharPosition (int index, Point<float>&, float& lineHeight) const;
|
||||
Rectangle<float> getCaretRectangleFloat() const;
|
||||
void updateCaretPosition();
|
||||
void updateValueFromText();
|
||||
void textWasChangedByValue();
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue