ignore hashtag suggestions if they vary only in case (#16460)
* ignore hashtag suggestions if they vary only in case * remove console.logs and unused args * consistently add space when dismissing suggestions * linting
This commit is contained in:
parent
794d9d267d
commit
65ee707755
2 changed files with 34 additions and 7 deletions
|
@ -37,6 +37,7 @@ export const THUMBNAIL_UPLOAD_PROGRESS = 'THUMBNAIL_UPLOAD_PROGRESS';
|
||||||
export const COMPOSE_SUGGESTIONS_CLEAR = 'COMPOSE_SUGGESTIONS_CLEAR';
|
export const COMPOSE_SUGGESTIONS_CLEAR = 'COMPOSE_SUGGESTIONS_CLEAR';
|
||||||
export const COMPOSE_SUGGESTIONS_READY = 'COMPOSE_SUGGESTIONS_READY';
|
export const COMPOSE_SUGGESTIONS_READY = 'COMPOSE_SUGGESTIONS_READY';
|
||||||
export const COMPOSE_SUGGESTION_SELECT = 'COMPOSE_SUGGESTION_SELECT';
|
export const COMPOSE_SUGGESTION_SELECT = 'COMPOSE_SUGGESTION_SELECT';
|
||||||
|
export const COMPOSE_SUGGESTION_IGNORE = 'COMPOSE_SUGGESTION_IGNORE';
|
||||||
export const COMPOSE_SUGGESTION_TAGS_UPDATE = 'COMPOSE_SUGGESTION_TAGS_UPDATE';
|
export const COMPOSE_SUGGESTION_TAGS_UPDATE = 'COMPOSE_SUGGESTION_TAGS_UPDATE';
|
||||||
|
|
||||||
export const COMPOSE_TAG_HISTORY_UPDATE = 'COMPOSE_TAG_HISTORY_UPDATE';
|
export const COMPOSE_TAG_HISTORY_UPDATE = 'COMPOSE_TAG_HISTORY_UPDATE';
|
||||||
|
@ -534,13 +535,25 @@ export function selectComposeSuggestion(position, token, suggestion, path) {
|
||||||
startPosition = position;
|
startPosition = position;
|
||||||
}
|
}
|
||||||
|
|
||||||
dispatch({
|
// We don't want to replace hashtags that vary only in case due to accessibility, but we need to fire off an event so that
|
||||||
type: COMPOSE_SUGGESTION_SELECT,
|
// the suggestions are dismissed and the cursor moves forward.
|
||||||
position: startPosition,
|
if (suggestion.type !== 'hashtag' || token.slice(1).localeCompare(suggestion.name, undefined, { sensitivity: 'accent' }) !== 0) {
|
||||||
token,
|
dispatch({
|
||||||
completion,
|
type: COMPOSE_SUGGESTION_SELECT,
|
||||||
path,
|
position: startPosition,
|
||||||
});
|
token,
|
||||||
|
completion,
|
||||||
|
path,
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
dispatch({
|
||||||
|
type: COMPOSE_SUGGESTION_IGNORE,
|
||||||
|
position: startPosition,
|
||||||
|
token,
|
||||||
|
completion,
|
||||||
|
path,
|
||||||
|
});
|
||||||
|
}
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -21,6 +21,7 @@ import {
|
||||||
COMPOSE_SUGGESTIONS_CLEAR,
|
COMPOSE_SUGGESTIONS_CLEAR,
|
||||||
COMPOSE_SUGGESTIONS_READY,
|
COMPOSE_SUGGESTIONS_READY,
|
||||||
COMPOSE_SUGGESTION_SELECT,
|
COMPOSE_SUGGESTION_SELECT,
|
||||||
|
COMPOSE_SUGGESTION_IGNORE,
|
||||||
COMPOSE_SUGGESTION_TAGS_UPDATE,
|
COMPOSE_SUGGESTION_TAGS_UPDATE,
|
||||||
COMPOSE_TAG_HISTORY_UPDATE,
|
COMPOSE_TAG_HISTORY_UPDATE,
|
||||||
COMPOSE_SENSITIVITY_CHANGE,
|
COMPOSE_SENSITIVITY_CHANGE,
|
||||||
|
@ -165,6 +166,17 @@ const insertSuggestion = (state, position, token, completion, path) => {
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const ignoreSuggestion = (state, position, token, completion, path) => {
|
||||||
|
return state.withMutations(map => {
|
||||||
|
map.updateIn(path, oldText => `${oldText.slice(0, position + token.length)} ${oldText.slice(position + token.length)}`);
|
||||||
|
map.set('suggestion_token', null);
|
||||||
|
map.set('suggestions', ImmutableList());
|
||||||
|
map.set('focusDate', new Date());
|
||||||
|
map.set('caretPosition', position + token.length + 1);
|
||||||
|
map.set('idempotencyKey', uuid());
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
const sortHashtagsByUse = (state, tags) => {
|
const sortHashtagsByUse = (state, tags) => {
|
||||||
const personalHistory = state.get('tagHistory');
|
const personalHistory = state.get('tagHistory');
|
||||||
|
|
||||||
|
@ -398,6 +410,8 @@ export default function compose(state = initialState, action) {
|
||||||
return state.set('suggestions', ImmutableList(normalizeSuggestions(state, action))).set('suggestion_token', action.token);
|
return state.set('suggestions', ImmutableList(normalizeSuggestions(state, action))).set('suggestion_token', action.token);
|
||||||
case COMPOSE_SUGGESTION_SELECT:
|
case COMPOSE_SUGGESTION_SELECT:
|
||||||
return insertSuggestion(state, action.position, action.token, action.completion, action.path);
|
return insertSuggestion(state, action.position, action.token, action.completion, action.path);
|
||||||
|
case COMPOSE_SUGGESTION_IGNORE:
|
||||||
|
return ignoreSuggestion(state, action.position, action.token, action.completion, action.path);
|
||||||
case COMPOSE_SUGGESTION_TAGS_UPDATE:
|
case COMPOSE_SUGGESTION_TAGS_UPDATE:
|
||||||
return updateSuggestionTags(state, action.token);
|
return updateSuggestionTags(state, action.token);
|
||||||
case COMPOSE_TAG_HISTORY_UPDATE:
|
case COMPOSE_TAG_HISTORY_UPDATE:
|
||||||
|
|
Loading…
Reference in a new issue