Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
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
4 changes: 3 additions & 1 deletion src/components/mention-input.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ const MentionInput: FC<MentionInputProps> = (

onSelectionChange,

deleteFullMentioned,

...textInputProps
},
) => {
Expand All @@ -54,7 +56,7 @@ const MentionInput: FC<MentionInputProps> = (
* @param changedText
*/
const onChangeInput = (changedText: string) => {
onChange(generateValueFromPartsAndChangedText(parts, plainText, changedText));
onChange(generateValueFromPartsAndChangedText(parts, plainText, changedText, deleteFullMentioned));
};

/**
Expand Down
2 changes: 2 additions & 0 deletions src/types/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,8 @@ type MentionInputProps = Omit<TextInputProps, 'onChange'> & {
inputRef?: Ref<TextInput>;

containerStyle?: StyleProp<ViewStyle>;

deleteFullMentioned?: boolean;
};

export type {
Expand Down
14 changes: 13 additions & 1 deletion src/utils/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ const getMentionPartSuggestionKeywords = (
* @param originalText original plain text
* @param changedText changed plain text
*/
const generateValueFromPartsAndChangedText = (parts: Part[], originalText: string, changedText: string) => {
const generateValueFromPartsAndChangedText = (parts: Part[], originalText: string, changedText: string, deleteFullMentioned? :string) => {
const changes = diffChars(originalText, changedText) as CharactersDiffChange[];

let newParts: Part[] = [];
Expand Down Expand Up @@ -222,6 +222,10 @@ const generateValueFromPartsAndChangedText = (parts: Part[], originalText: strin
default: {
if (change.count !== 0) {
newParts = newParts.concat(getPartsInterval(parts, cursor, change.count));

if (deleteFullMentioned && originalText.length > changedText.length) {
newParts = removeFullMentionPart(parts, newParts);
}

cursor += change.count;
}
Expand All @@ -234,6 +238,14 @@ const generateValueFromPartsAndChangedText = (parts: Part[], originalText: strin
return getValueFromParts(newParts);
};

const removeFullMentionPart = (parts: Part[], newParts: Part[]): Part[] =>
parts.filter((item1) => {
const correspondingItem2 = newParts.find((item2) => item1.text === item2.text);

// If item1 has data.id and correspondingItem2 doesn't have data.id, remove item1
return !(item1.data?.id && !correspondingItem2?.data?.id);
});

/**
* Method for adding suggestion to the parts and generating value. We should:
* - Find part with plain text where we were tracking mention typing using selection state
Expand Down