Skip to content

Commit

Permalink
Merge pull request #34076 from paultsimura/fix/33652-room-name-selection
Browse files Browse the repository at this point in the history
fix: Place cursor at the end of the replaced selection
  • Loading branch information
marcaaron authored Jan 11, 2024
2 parents e0f0e40 + 6071277 commit fe7d113
Showing 1 changed file with 4 additions and 7 deletions.
11 changes: 4 additions & 7 deletions src/components/RoomNameInput/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,18 +27,15 @@ function RoomNameInput({isFocused, autoFocus, disabled, errorText, forwardedRef,

// Prevent cursor jump behaviour:
// Check if newRoomNameWithHash is the same as modifiedRoomName
// If it is then the room name is valid (does not contain unallowed characters); no action required
// If not then the room name contains unvalid characters and we must adjust the cursor position manually
// If it is, then the room name is valid (does not contain forbidden characters) no action required
// If not, then the room name contains invalid characters, and we must adjust the cursor position manually
// Read more: https://github.com/Expensify/App/issues/12741
const oldRoomNameWithHash = value || '';
const newRoomNameWithHash = `${CONST.POLICY.ROOM_PREFIX}${roomName}`;
if (modifiedRoomName !== newRoomNameWithHash) {
const offset = modifiedRoomName.length - oldRoomNameWithHash.length;
const newSelection = {
start: selection.start + offset,
end: selection.end + offset,
};
setSelection(newSelection);
const newCursorPosition = selection.end + offset;
setSelection({start: newCursorPosition, end: newCursorPosition});
}
};

Expand Down

0 comments on commit fe7d113

Please sign in to comment.