Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions ios/PasteTextInput.mm
Original file line number Diff line number Diff line change
Expand Up @@ -597,9 +597,18 @@ - (void)_setAttributedString:(NSAttributedString *)attributedString
if ([self _textOf:attributedString equals:_backedTextInputView.attributedText]) {
return;
}

// Save current scroll position
CGPoint originalOffset = _backedTextInputView.contentOffset;

// Temporarily disable scrolling animations
BOOL originalScrollEnabled = _backedTextInputView.scrollEnabled;
_backedTextInputView.scrollEnabled = NO;

UITextRange *selectedRange = _backedTextInputView.selectedTextRange;
NSInteger oldTextLength = _backedTextInputView.attributedText.string.length;
_backedTextInputView.attributedText = attributedString;

if (selectedRange.empty) {
// Maintaining a cursor position relative to the end of the old text.
NSInteger offsetStart = [_backedTextInputView offsetFromPosition:_backedTextInputView.beginningOfDocument
Expand All @@ -612,6 +621,13 @@ - (void)_setAttributedString:(NSAttributedString *)attributedString
notifyDelegate:YES];
}
[self _restoreTextSelection];

// Restore scroll position immediately
[_backedTextInputView setContentOffset:originalOffset animated:NO];

// Re-enable scrolling with original state
_backedTextInputView.scrollEnabled = originalScrollEnabled;

_lastStringStateWasUpdatedWith = attributedString;
}

Expand Down