MM-24029 Fix date re-selection on search bar (#4441)
Picking a new date string (tapping a date on the autocomplete calendar) to replace an already populated date string in the search bar, leaves the search text garbled. This was because of incorrect handling of the tap cursor position in the search box. Co-authored-by: Amit Uttam <changingrainbows@gmail.com>
This commit is contained in:
parent
56806a9d9f
commit
cf3ff99cd8
1 changed files with 11 additions and 3 deletions
|
|
@ -60,13 +60,21 @@ export default class DateSuggestion extends PureComponent {
|
|||
completeMention = (day) => {
|
||||
const mention = day.dateString;
|
||||
const {cursorPosition, onChangeText, value} = this.props;
|
||||
const mentionPart = value.substring(0, cursorPosition);
|
||||
|
||||
// Substring to first space after current cursor position.
|
||||
// If there is none, cursor is at the end of the date segment already.
|
||||
let dateSegmentEnd = value.indexOf(' ', cursorPosition);
|
||||
if (dateSegmentEnd === -1) {
|
||||
dateSegmentEnd = cursorPosition;
|
||||
}
|
||||
const mentionPart = value.substring(0, dateSegmentEnd);
|
||||
|
||||
const flags = mentionPart.match(ALL_SEARCH_FLAGS_REGEX);
|
||||
const currentFlag = flags[flags.length - 1];
|
||||
let completedDraft = mentionPart.replace(DATE_MENTION_SEARCH_REGEX, `${currentFlag} ${mention} `);
|
||||
|
||||
if (value.length > cursorPosition) {
|
||||
completedDraft += value.substring(cursorPosition);
|
||||
if (value.length > dateSegmentEnd) {
|
||||
completedDraft += value.substring(dateSegmentEnd + 1); // accounting for extra space character
|
||||
}
|
||||
|
||||
onChangeText(completedDraft, true);
|
||||
|
|
|
|||
Loading…
Reference in a new issue