Skip to content

Commit

Permalink
Fix cursor positioning with non-English characters and improve positi…
Browse files Browse the repository at this point in the history
…oning at the end of the line (#9355)
  • Loading branch information
Districh-ru authored Dec 21, 2024
1 parent 60b976b commit c12e38d
Showing 1 changed file with 12 additions and 3 deletions.
15 changes: 12 additions & 3 deletions src/fheroes2/dialog/dialog_selectcount.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -252,6 +252,9 @@ bool Dialog::inputString( const fheroes2::TextBase & title, const fheroes2::Text

display.render();

// We add extra 4 pixels to the click area width to help setting the cursor at the end of the line if it is fully filled with text characters.
const fheroes2::Rect textEditClickArea{ textInputArea.x, textInputArea.y, textInputArea.width + 4, textInputArea.height };

LocalEvent & le = LocalEvent::Get();

Game::AnimateResetDelay( Game::DelayType::CURSOR_BLINK_DELAY );
Expand All @@ -278,7 +281,7 @@ bool Dialog::inputString( const fheroes2::TextBase & title, const fheroes2::Text
return false;
}

if ( le.MouseClickLeft( buttonVirtualKB.area() ) || ( isInGameKeyboardRequired && le.MouseClickLeft( textInputArea ) ) ) {
if ( le.MouseClickLeft( buttonVirtualKB.area() ) || ( isInGameKeyboardRequired && le.MouseClickLeft( textEditClickArea ) ) ) {
if ( textLanguage.has_value() ) {
const fheroes2::LanguageSwitcher switcher( textLanguage.value() );
fheroes2::openVirtualKeyboard( result, charLimit );
Expand All @@ -304,8 +307,14 @@ bool Dialog::inputString( const fheroes2::TextBase & title, const fheroes2::Text
}
redraw = true;
}
else if ( le.MouseClickLeft( textInputArea ) ) {
charInsertPos = fheroes2::getTextInputCursorPosition( text, charInsertPos, le.getMouseCursorPos(), textInputArea );
else if ( le.MouseClickLeft( textEditClickArea ) ) {
if ( textLanguage.has_value() ) {
const fheroes2::LanguageSwitcher switcher( textLanguage.value() );
charInsertPos = fheroes2::getTextInputCursorPosition( text, charInsertPos, le.getMouseCursorPos(), textInputArea );
}
else {
charInsertPos = fheroes2::getTextInputCursorPosition( text, charInsertPos, le.getMouseCursorPos(), textInputArea );
}

redraw = true;
}
Expand Down

0 comments on commit c12e38d

Please sign in to comment.