Skip to content

Commit

Permalink
Fix text input cursor setting for multi-line text input with many spa…
Browse files Browse the repository at this point in the history
…ces at the line end (#9319)
  • Loading branch information
Districh-ru authored Dec 12, 2024
1 parent 23aedf7 commit 1265680
Show file tree
Hide file tree
Showing 6 changed files with 297 additions and 288 deletions.
5 changes: 3 additions & 2 deletions src/fheroes2/dialog/dialog_selectcount.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -210,8 +210,9 @@ bool Dialog::inputString( const fheroes2::TextBase & title, const fheroes2::Text
bool isCursorVisible = true;
const fheroes2::FontType fontType( fheroes2::FontType::normalWhite() );
fheroes2::Text text( insertCharToString( result, charInsertPos, isCursorVisible ? '_' : '\x7F' ), fontType, textLanguage );
text.keepLineTrailingSpaces();
if ( !isMultiLine ) {
text.fitToOneRow( textInputArea.width, false );
text.fitToOneRow( textInputArea.width );
}
text.drawInRoi( textInputArea.x, textInputArea.y + 2, textInputArea.width, display, textInputArea );

Expand Down Expand Up @@ -343,7 +344,7 @@ bool Dialog::inputString( const fheroes2::TextBase & title, const fheroes2::Text
text.set( insertCharToString( result, charInsertPos, isCursorVisible ? '_' : '\x7F' ), fontType, textLanguage );

if ( !isMultiLine ) {
text.fitToOneRow( textInputArea.width, false );
text.fitToOneRow( textInputArea.width );
}

textBackground.restore();
Expand Down
6 changes: 4 additions & 2 deletions src/fheroes2/dialog/dialog_selectfile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,8 @@ namespace

fheroes2::Text currentFilename( filename, isEditing ? fheroes2::FontType::normalWhite() : fheroes2::FontType::normalYellow() );
// Do not ignore spaces at the end.
currentFilename.fitToOneRow( maxFileNameWidth, false );
currentFilename.keepLineTrailingSpaces();
currentFilename.fitToOneRow( maxFileNameWidth );

currentFilename.draw( field.x + 4 + ( maxFileNameWidth - currentFilename.width() ) / 2, field.y + 4, display );
}
Expand Down Expand Up @@ -198,7 +199,8 @@ namespace
dsty += 2;

fheroes2::Text text{ std::move( savname ), font };
text.fitToOneRow( maxFileNameWidth, false );
text.keepLineTrailingSpaces();
text.fitToOneRow( maxFileNameWidth );
text.draw( dstx + 4 + ( maxFileNameWidth - text.width() ) / 2, dsty, display );

redrawDateTime( display, info.timestamp, dstx + maxFileNameWidth + 9, dsty, font );
Expand Down
Loading

0 comments on commit 1265680

Please sign in to comment.