MM-51013 Remove unneeded code from original version of Markdown hotkeys (#23823)

Automatic Merge
Этот коммит содержится в:
Harrison Healey
2023-06-26 08:47:28 -04:00
коммит произвёл GitHub
родитель a5867074e5
Коммит 94a3c41c59
14 изменённых файлов: 0 добавлений и 180 удалений

Просмотреть файл

@@ -28,7 +28,6 @@ exports[`components/TextBox should match snapshot with additional, optional prop
onKeyPress={[Function]}
onKeyUp={[Function]}
onMouseUp={[Function]}
onSelect={[Function]}
openWhenEmpty={true}
placeholder="placeholder text"
providers={
@@ -142,7 +141,6 @@ exports[`components/TextBox should match snapshot with required props 1`] = `
onKeyPress={[Function]}
onKeyUp={[Function]}
onMouseUp={[Function]}
onSelect={[Function]}
placeholder="placeholder text"
providers={
Array [
@@ -236,7 +234,6 @@ exports[`components/TextBox should throw error when new property is too long 1`]
onKeyPress={[Function]}
onKeyUp={[Function]}
onMouseUp={[Function]}
onSelect={[Function]}
placeholder="placeholder text"
providers={
Array [
@@ -330,7 +327,6 @@ exports[`components/TextBox should throw error when value is too long 1`] = `
onKeyPress={[Function]}
onKeyUp={[Function]}
onMouseUp={[Function]}
onSelect={[Function]}
placeholder="placeholder text"
providers={
Array [

Просмотреть файл

@@ -43,7 +43,6 @@ exports[`components/AdvancedCreateComment should match snapshot when cannot post
handleKeyDown={[Function]}
handleMouseUpKeyUp={[Function]}
handlePostError={[Function]}
handleSelect={[Function]}
handleSubmit={[Function]}
handleUploadError={[Function]}
handleUploadProgress={[Function]}
@@ -110,7 +109,6 @@ exports[`components/AdvancedCreateComment should match snapshot, comment with me
handleKeyDown={[Function]}
handleMouseUpKeyUp={[Function]}
handlePostError={[Function]}
handleSelect={[Function]}
handleSubmit={[Function]}
handleUploadError={[Function]}
handleUploadProgress={[Function]}
@@ -184,7 +182,6 @@ exports[`components/AdvancedCreateComment should match snapshot, emoji picker di
handleKeyDown={[Function]}
handleMouseUpKeyUp={[Function]}
handlePostError={[Function]}
handleSelect={[Function]}
handleSubmit={[Function]}
handleUploadError={[Function]}
handleUploadProgress={[Function]}
@@ -251,7 +248,6 @@ exports[`components/AdvancedCreateComment should match snapshot, empty comment 1
handleKeyDown={[Function]}
handleMouseUpKeyUp={[Function]}
handlePostError={[Function]}
handleSelect={[Function]}
handleSubmit={[Function]}
handleUploadError={[Function]}
handleUploadProgress={[Function]}
@@ -325,7 +321,6 @@ exports[`components/AdvancedCreateComment should match snapshot, non-empty messa
handleKeyDown={[Function]}
handleMouseUpKeyUp={[Function]}
handlePostError={[Function]}
handleSelect={[Function]}
handleSubmit={[Function]}
handleUploadError={[Function]}
handleUploadProgress={[Function]}

Просмотреть файл

@@ -826,10 +826,6 @@ class AdvancedCreateComment extends React.PureComponent<Props, State> {
});
};
handleSelect = (e: React.SyntheticEvent<TextboxElement>) => {
Utils.adjustSelection(this.textboxRef.current?.getInputBox(), e);
};
handleKeyDown = (e: React.KeyboardEvent<TextboxElement>) => {
const ctrlOrMetaKeyPressed = e.ctrlKey || e.metaKey;
const lastMessageReactionKeyCombo = ctrlOrMetaKeyPressed && e.shiftKey && Keyboard.isKeyPressed(e, KeyCodes.BACK_SLASH);
@@ -1237,7 +1233,6 @@ class AdvancedCreateComment extends React.PureComponent<Props, State> {
handlePostError={this.handlePostError}
emitTypingEvent={this.emitTypingEvent}
handleMouseUpKeyUp={this.handleMouseUpKeyUp}
handleSelect={this.handleSelect}
handleKeyDown={this.handleKeyDown}
postMsgKeyPress={this.commentMsgKeyPress}
handleChange={this.handleChange}

Просмотреть файл

@@ -47,7 +47,6 @@ exports[`components/advanced_create_post Show tutorial 1`] = `
handleKeyDown={[Function]}
handleMouseUpKeyUp={[Function]}
handlePostError={[Function]}
handleSelect={[Function]}
handleSubmit={[Function]}
handleUploadError={[Function]}
handleUploadProgress={[Function]}
@@ -126,7 +125,6 @@ exports[`components/advanced_create_post should match snapshot for center textbo
handleKeyDown={[Function]}
handleMouseUpKeyUp={[Function]}
handlePostError={[Function]}
handleSelect={[Function]}
handleSubmit={[Function]}
handleUploadError={[Function]}
handleUploadProgress={[Function]}
@@ -205,7 +203,6 @@ exports[`components/advanced_create_post should match snapshot when cannot post
handleKeyDown={[Function]}
handleMouseUpKeyUp={[Function]}
handlePostError={[Function]}
handleSelect={[Function]}
handleSubmit={[Function]}
handleUploadError={[Function]}
handleUploadProgress={[Function]}
@@ -284,7 +281,6 @@ exports[`components/advanced_create_post should match snapshot when file upload
handleKeyDown={[Function]}
handleMouseUpKeyUp={[Function]}
handlePostError={[Function]}
handleSelect={[Function]}
handleSubmit={[Function]}
handleUploadError={[Function]}
handleUploadProgress={[Function]}
@@ -363,7 +359,6 @@ exports[`components/advanced_create_post should match snapshot, can post; previe
handleKeyDown={[Function]}
handleMouseUpKeyUp={[Function]}
handlePostError={[Function]}
handleSelect={[Function]}
handleSubmit={[Function]}
handleUploadError={[Function]}
handleUploadProgress={[Function]}
@@ -442,7 +437,6 @@ exports[`components/advanced_create_post should match snapshot, can post; previe
handleKeyDown={[Function]}
handleMouseUpKeyUp={[Function]}
handlePostError={[Function]}
handleSelect={[Function]}
handleSubmit={[Function]}
handleUploadError={[Function]}
handleUploadProgress={[Function]}
@@ -521,7 +515,6 @@ exports[`components/advanced_create_post should match snapshot, cannot post; pre
handleKeyDown={[Function]}
handleMouseUpKeyUp={[Function]}
handlePostError={[Function]}
handleSelect={[Function]}
handleSubmit={[Function]}
handleUploadError={[Function]}
handleUploadProgress={[Function]}
@@ -600,7 +593,6 @@ exports[`components/advanced_create_post should match snapshot, cannot post; pre
handleKeyDown={[Function]}
handleMouseUpKeyUp={[Function]}
handlePostError={[Function]}
handleSelect={[Function]}
handleSubmit={[Function]}
handleUploadError={[Function]}
handleUploadProgress={[Function]}
@@ -679,7 +671,6 @@ exports[`components/advanced_create_post should match snapshot, init 1`] = `
handleKeyDown={[Function]}
handleMouseUpKeyUp={[Function]}
handlePostError={[Function]}
handleSelect={[Function]}
handleSubmit={[Function]}
handleUploadError={[Function]}
handleUploadProgress={[Function]}
@@ -763,7 +754,6 @@ exports[`components/advanced_create_post should match snapshot, post priority di
handleKeyDown={[Function]}
handleMouseUpKeyUp={[Function]}
handlePostError={[Function]}
handleSelect={[Function]}
handleSubmit={[Function]}
handleUploadError={[Function]}
handleUploadProgress={[Function]}
@@ -850,7 +840,6 @@ exports[`components/advanced_create_post should match snapshot, post priority en
handleKeyDown={[Function]}
handleMouseUpKeyUp={[Function]}
handlePostError={[Function]}
handleSelect={[Function]}
handleSubmit={[Function]}
handleUploadError={[Function]}
handleUploadProgress={[Function]}
@@ -947,7 +936,6 @@ exports[`components/advanced_create_post should match snapshot, post priority en
handleKeyDown={[Function]}
handleMouseUpKeyUp={[Function]}
handlePostError={[Function]}
handleSelect={[Function]}
handleSubmit={[Function]}
handleUploadError={[Function]}
handleUploadProgress={[Function]}

Просмотреть файл

@@ -1457,35 +1457,6 @@ describe('components/advanced_create_post', () => {
'post_textbox',
);
/**
* TODO@all: move this test to advanced_text_editor.test.tsx and rewrite it according to the component
*
* it is not possible to test for this here since we only shallow render
*
* @see: https://mattermost.atlassian.net/browse/MM-44343
*/
// it('should adjust selection to correct text', () => {
// const value = 'Jalebi _Fafda_ and Sambharo';
// const wrapper = shallow(advancedCreatePost({draft: {...draftProp, message: value}}));
//
// const setSelectionRangeFn = jest.fn();
// wrapper.instance().textboxRef = {
// current: {
// getInputBox: jest.fn(() => {
// return {
// focus: jest.fn(),
// setSelectionRange: setSelectionRangeFn,
// };
// }),
// },
// };
//
// const textbox = wrapper.find(Textbox);
// const e = makeSelectionEvent(value, 7, 14);
// textbox.props().onSelect(e);
// expect(setSelectionRangeFn).toHaveBeenCalledWith(8, 13);
// });
it('should match snapshot, can post; preview enabled', () => {
const wrapper = shallow(advancedCreatePost({canPost: true, isMarkdownPreviewEnabled: true}));

Просмотреть файл

@@ -1127,10 +1127,6 @@ class AdvancedCreatePost extends React.PureComponent<Props, State> {
});
};
handleSelect = (e: React.SyntheticEvent<Element, Event>) => {
Utils.adjustSelection(this.textboxRef.current?.getInputBox(), e as React.KeyboardEvent<HTMLInputElement>);
};
handleKeyDown = (e: React.KeyboardEvent<TextboxElement>) => {
const messageIsEmpty = this.state.message.length === 0;
const draftMessageIsEmpty = this.props.draft.message.length === 0;
@@ -1612,7 +1608,6 @@ class AdvancedCreatePost extends React.PureComponent<Props, State> {
handlePostError={this.handlePostError}
emitTypingEvent={this.emitTypingEvent}
handleMouseUpKeyUp={this.handleMouseUpKeyUp}
handleSelect={this.handleSelect}
handleKeyDown={this.handleKeyDown}
postMsgKeyPress={this.postMsgKeyPress}
handleChange={this.handleChange}

Просмотреть файл

@@ -78,7 +78,6 @@ type Props = {
handlePostError: (postError: React.ReactNode) => void;
emitTypingEvent: () => void;
handleMouseUpKeyUp: (e: React.MouseEvent<TextboxElement> | React.KeyboardEvent<TextboxElement>) => void;
handleSelect: (e: React.SyntheticEvent<TextboxElement>) => void;
handleKeyDown: (e: React.KeyboardEvent<TextboxElement>) => void;
postMsgKeyPress: (e: React.KeyboardEvent<TextboxElement>) => void;
handleChange: (e: React.ChangeEvent<TextboxElement>) => void;
@@ -136,7 +135,6 @@ const AdvanceTextEditor = ({
handlePostError,
emitTypingEvent,
handleMouseUpKeyUp,
handleSelect,
handleKeyDown,
postMsgKeyPress,
handleChange,
@@ -473,7 +471,6 @@ const AdvanceTextEditor = ({
onChange={handleChange}
onKeyPress={postMsgKeyPress}
onKeyDown={handleKeyDown}
onSelect={handleSelect}
onMouseUp={handleMouseUpKeyUp}
onKeyUp={handleMouseUpKeyUp}
onComposition={emitTypingEvent}

Просмотреть файл

@@ -349,12 +349,6 @@ const EditPost = ({editingPost, actions, canEditPost, config, channelId, draft,
}
};
const handleSelect = (e: React.SyntheticEvent<TextboxElement>) => {
if (textboxRef.current) {
Utils.adjustSelection(textboxRef.current.getInputBox(), e);
}
};
const handleChange = (e: React.ChangeEvent<TextboxElement>) => {
const message = e.target.value;
@@ -490,7 +484,6 @@ const EditPost = ({editingPost, actions, canEditPost, config, channelId, draft,
onChange={handleChange}
onKeyPress={handleEditKeyPress}
onKeyDown={handleKeyDown}
onSelect={handleSelect}
onHeightChange={handleHeightChange}
handlePostError={handlePostError}
onPaste={handlePaste}

Просмотреть файл

@@ -44,13 +44,6 @@ const ForwardPostCommentInput = ({channelId, canForwardPost, comment, permaLinkL
// we do not allow sending the forwarding when hitting enter
const postMsgKeyPress = () => {};
const handleSelect = (e: React.SyntheticEvent<Element, Event>) => {
Utils.adjustSelection(
textboxRef?.current?.getInputBox(),
e as React.KeyboardEvent<HTMLInputElement>,
);
};
const handleChange = useCallback(
(e: React.ChangeEvent<TextboxElement>) => {
const message = e.target.value;
@@ -138,7 +131,6 @@ const ForwardPostCommentInput = ({channelId, canForwardPost, comment, permaLinkL
onChange={handleChange}
onKeyPress={postMsgKeyPress}
onKeyDown={handleKeyDown}
onSelect={handleSelect}
onHeightChange={onHeightChange}
handlePostError={onError}
value={comment}

Просмотреть файл

@@ -97,7 +97,6 @@ export default class SuggestionBox extends React.PureComponent {
onKeyPress: PropTypes.func,
onComposition: PropTypes.func,
onSelect: PropTypes.func,
onSearchTypeSelected: PropTypes.func,
/**
@@ -624,12 +623,6 @@ export default class SuggestionBox extends React.PureComponent {
}
};
handleSelect = (e) => {
if (this.props.onSelect) {
this.props.onSelect(e);
}
};
focusInputOnEscape = () => {
if (this.inputRef.current) {
document.dispatchEvent(new CustomEvent(
@@ -840,7 +833,6 @@ export default class SuggestionBox extends React.PureComponent {
onCompositionUpdate={this.handleCompositionUpdate}
onCompositionEnd={this.handleCompositionEnd}
onKeyDown={this.handleKeyDown}
onSelect={this.handleSelect}
/>
{(this.props.openWhenEmpty || this.props.value.length >= this.props.requiredCharacters) && this.state.presentationType === 'text' && (
<SuggestionListComponent

Просмотреть файл

@@ -65,7 +65,6 @@ describe('components/TextBox', () => {
onComposition={() => {}}
onHeightChange={() => {}}
onKeyDown={() => {}}
onSelect={() => {}}
onMouseUp={() => {}}
onKeyUp={() => {}}
onBlur={() => {}}

Просмотреть файл

@@ -40,7 +40,6 @@ export type Props = {
onWidthChange?: (width: number) => void;
createMessage: string;
onKeyDown?: (e: KeyboardEvent<TextboxElement>) => void;
onSelect?: (e: React.SyntheticEvent<TextboxElement>) => void;
onMouseUp?: (e: React.MouseEvent<TextboxElement>) => void;
onKeyUp?: (e: React.KeyboardEvent<TextboxElement>) => void;
onBlur?: (e: FocusEvent<TextboxElement>) => void;
@@ -229,8 +228,6 @@ export default class Textbox extends React.PureComponent<Props> {
this.props.onKeyDown?.(e as KeyboardEvent<TextboxElement>);
};
handleSelect = (e: React.SyntheticEvent<TextboxElement>) => this.props.onSelect?.(e);
handleMouseUp = (e: MouseEvent<TextboxElement>) => this.props.onMouseUp?.(e);
handleKeyUp = (e: KeyboardEvent<TextboxElement>) => this.props.onKeyUp?.(e);
@@ -318,7 +315,6 @@ export default class Textbox extends React.PureComponent<Props> {
placeholder={this.props.createMessage}
onChange={this.handleChange}
onKeyPress={this.props.onKeyPress}
onSelect={this.handleSelect}
onKeyDown={this.handleKeyDown}
onMouseUp={this.handleMouseUp}
onKeyUp={this.handleKeyUp}

Просмотреть файл

@@ -9,10 +9,8 @@ import store from 'stores/redux_store.jsx';
import Constants, {ValidationErrors} from 'utils/constants';
import * as Utils from 'utils/utils';
import * as lineBreakHelpers from 'tests/helpers/line_break_helpers.js';
import {makeSelectionEvent} from 'tests/helpers/markdown_hotkey_helpers.js';
import * as ua from 'tests/helpers/user_agent_mocks';
import {UserProfile} from '@mattermost/types/users';
import {TextboxElement} from 'components/textbox';
describe('Utils.getDisplayNameByUser', () => {
afterEach(() => {
@@ -422,68 +420,6 @@ describe('Utils.insertLineBreakFromKeyEvent', () => {
});
});
describe('Utils.adjustSelection', () => {
test('adjustSelection fixes selection to correct text', () => {
// "_Fafda_" is selected
const e = makeSelectionEvent('Jalebi _Fafda_ and Sambharo', 7, 14);
const input = {
focus: jest.fn(),
setSelectionRange: jest.fn(),
} as unknown as HTMLInputElement;
Utils.adjustSelection(input, e as React.KeyboardEvent<TextboxElement>);
expect(input.setSelectionRange).toHaveBeenCalledWith(8, 13);
});
test('adjustSelection does not fix selection when selected text does not end with "_"', () => {
// "_Fafda" is selected
const e = makeSelectionEvent('Jalebi _Fafda and Sambharo', 7, 13);
const input = {
focus: jest.fn(),
setSelectionRange: jest.fn(),
} as unknown as HTMLInputElement;
Utils.adjustSelection(input, e as React.KeyboardEvent<TextboxElement>);
expect(input.setSelectionRange).not.toHaveBeenCalled();
});
test('adjustSelection does not fix selection when selected text does start end with "_"', () => {
// "Fafda_" is selected
const e = makeSelectionEvent('Jalebi Fafda_ and Sambharo', 7, 13);
const input = {
focus: jest.fn(),
setSelectionRange: jest.fn(),
} as unknown as HTMLInputElement;
Utils.adjustSelection(input, e as React.KeyboardEvent<TextboxElement>);
expect(input.setSelectionRange).not.toHaveBeenCalled();
});
test('adjustSelection fixes selection at start of text', () => {
// "_Jalebi_" is selected
const e = makeSelectionEvent('_Jalebi_ Fafda and Sambharo', 0, 8);
const input = {
focus: jest.fn(),
setSelectionRange: jest.fn(),
} as unknown as HTMLInputElement;
Utils.adjustSelection(input, e as React.KeyboardEvent<TextboxElement>);
expect(input.setSelectionRange).toHaveBeenCalledWith(1, 7);
});
test('adjustSelection fixes selection at end of text', () => {
// "_Sambharo_" is selected
const e = makeSelectionEvent('Jalebi Fafda and _Sambharo_', 17, 27);
const input = {
focus: jest.fn(),
setSelectionRange: jest.fn(),
} as unknown as HTMLInputElement;
Utils.adjustSelection(input, e as React.KeyboardEvent<TextboxElement>);
expect(input.setSelectionRange).toHaveBeenCalledWith(18, 26);
});
});
describe('Utils.copyTextAreaToDiv', () => {
const textArea = document.createElement('textarea');

Просмотреть файл

@@ -1608,31 +1608,6 @@ export function getClosestParent(elem: HTMLElement, selector: string) {
return null;
}
/**
* Adjust selection to correct text when there is Italic markdown (_) around selected text.
*/
export function adjustSelection(inputBox: HTMLInputElement, e: React.SyntheticEvent<TextboxElement>) {
const el = e.target as TextboxElement;
const {selectionEnd, selectionStart, value} = el;
if (selectionStart === selectionEnd) {
// nothing selected.
return;
}
e.preventDefault();
const firstUnderscore = value.charAt(selectionStart!) === '_';
const lastUnderscore = value.charAt(selectionEnd! - 1) === '_';
const spaceBefore = value.charAt(selectionStart! - 1) === ' ';
const spaceAfter = value.charAt(selectionEnd!) === ' ';
if (firstUnderscore && lastUnderscore && (spaceBefore || spaceAfter)) {
setSelectionRange(inputBox, selectionStart! + 1, selectionEnd! - 1);
}
}
export function getNextBillingDate() {
const nextBillingDate = moment().add(1, 'months').startOf('month');
return nextBillingDate.format('MMM D, YYYY');