From 4228c785f604591d98daba0c96c1bf4954fbb689 Mon Sep 17 00:00:00 2001 From: Guillaume Buisson <> Date: Mon, 8 Apr 2024 10:33:32 +0200 Subject: [PATCH] change right key behavior on text editor --- .../widgets/juce_TextEditor.cpp | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/modules/juce_gui_basics/widgets/juce_TextEditor.cpp b/modules/juce_gui_basics/widgets/juce_TextEditor.cpp index 8705d3503f52..812ed66fe585 100644 --- a/modules/juce_gui_basics/widgets/juce_TextEditor.cpp +++ b/modules/juce_gui_basics/widgets/juce_TextEditor.cpp @@ -2001,13 +2001,19 @@ bool TextEditor::moveCaretLeft (bool moveInWholeWordSteps, bool selecting) bool TextEditor::moveCaretRight (bool moveInWholeWordSteps, bool selecting) { - auto pos = getCaretPosition(); - - if (moveInWholeWordSteps) - pos = findWordBreakAfter (pos); + int pos; + if (!moveInWholeWordSteps && !selecting && !selection.isEmpty()) + { + pos = selection.getEnd(); + } else - ++pos; - + { + pos = getCaretPosition(); + if (moveInWholeWordSteps) + pos = findWordBreakAfter(pos); + else + ++pos; + } return moveCaretWithTransaction (pos, selecting); }