Skip to content
This repository was archived by the owner on Sep 11, 2024. It is now read-only.

Commit 6367860

Browse files
authored
Revert "Mentions as links rte (#10422)" (#10458)
This reverts commit 1af7108.
1 parent 58a4003 commit 6367860

File tree

11 files changed

+23
-585
lines changed

11 files changed

+23
-585
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@
6161
"dependencies": {
6262
"@babel/runtime": "^7.12.5",
6363
"@matrix-org/analytics-events": "^0.5.0",
64-
"@matrix-org/matrix-wysiwyg": "^1.4.0",
64+
"@matrix-org/matrix-wysiwyg": "^1.1.1",
6565
"@matrix-org/react-sdk-module-api": "^0.0.4",
6666
"@sentry/browser": "^7.0.0",
6767
"@sentry/tracing": "^7.0.0",

res/css/views/rooms/wysiwyg_composer/_SendWysiwygComposer.pcss

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -84,10 +84,3 @@ limitations under the License.
8484
border-color: $quaternary-content;
8585
}
8686
}
87-
88-
.mx_SendWysiwygComposer_AutoCompleteWrapper {
89-
position: relative;
90-
> .mx_Autocomplete {
91-
min-width: 100%;
92-
}
93-
}

res/css/views/rooms/wysiwyg_composer/components/_Editor.pcss

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -100,11 +100,6 @@ limitations under the License.
100100
padding: unset;
101101
}
102102
}
103-
104-
/* this selector represents what will become a pill */
105-
a[data-mention-type] {
106-
cursor: text;
107-
}
108103
}
109104

110105
.mx_WysiwygComposer_Editor_content_placeholder::before {

src/components/views/rooms/wysiwyg_composer/components/WysiwygAutocomplete.tsx

Lines changed: 0 additions & 137 deletions
This file was deleted.

src/components/views/rooms/wysiwyg_composer/components/WysiwygComposer.tsx

Lines changed: 7 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -14,21 +14,15 @@ See the License for the specific language governing permissions and
1414
limitations under the License.
1515
*/
1616

17-
import React, { memo, MutableRefObject, ReactNode, useEffect, useRef } from "react";
17+
import React, { memo, MutableRefObject, ReactNode, useEffect } from "react";
1818
import { useWysiwyg, FormattingFunctions } from "@matrix-org/matrix-wysiwyg";
1919
import classNames from "classnames";
2020

21-
import Autocomplete from "../../Autocomplete";
22-
import { WysiwygAutocomplete } from "./WysiwygAutocomplete";
2321
import { FormattingButtons } from "./FormattingButtons";
2422
import { Editor } from "./Editor";
2523
import { useInputEventProcessor } from "../hooks/useInputEventProcessor";
2624
import { useSetCursorPosition } from "../hooks/useSetCursorPosition";
2725
import { useIsFocused } from "../hooks/useIsFocused";
28-
import { useRoomContext } from "../../../../../contexts/RoomContext";
29-
import defaultDispatcher from "../../../../../dispatcher/dispatcher";
30-
import { Action } from "../../../../../dispatcher/actions";
31-
import { parsePermalink } from "../../../../../utils/permalinks/Permalinks";
3226

3327
interface WysiwygComposerProps {
3428
disabled?: boolean;
@@ -53,53 +47,21 @@ export const WysiwygComposer = memo(function WysiwygComposer({
5347
rightComponent,
5448
children,
5549
}: WysiwygComposerProps) {
56-
const { room } = useRoomContext();
57-
const autocompleteRef = useRef<Autocomplete | null>(null);
50+
const inputEventProcessor = useInputEventProcessor(onSend, initialContent);
5851

59-
const inputEventProcessor = useInputEventProcessor(onSend, autocompleteRef, initialContent);
60-
const { ref, isWysiwygReady, content, actionStates, wysiwyg, suggestion } = useWysiwyg({
61-
initialContent,
62-
inputEventProcessor,
63-
});
64-
const { isFocused, onFocus } = useIsFocused();
65-
66-
const isReady = isWysiwygReady && !disabled;
67-
const computedPlaceholder = (!content && placeholder) || undefined;
68-
69-
useSetCursorPosition(!isReady, ref);
52+
const { ref, isWysiwygReady, content, actionStates, wysiwyg } = useWysiwyg({ initialContent, inputEventProcessor });
7053

7154
useEffect(() => {
7255
if (!disabled && content !== null) {
7356
onChange?.(content);
7457
}
7558
}, [onChange, content, disabled]);
7659

77-
useEffect(() => {
78-
function handleClick(e: Event): void {
79-
e.preventDefault();
80-
if (
81-
e.target &&
82-
e.target instanceof HTMLAnchorElement &&
83-
e.target.getAttribute("data-mention-type") === "user"
84-
) {
85-
const parsedLink = parsePermalink(e.target.href);
86-
if (room && parsedLink?.userId)
87-
defaultDispatcher.dispatch({
88-
action: Action.ViewUser,
89-
member: room.getMember(parsedLink.userId),
90-
});
91-
}
92-
}
93-
94-
const mentions = ref.current?.querySelectorAll("a[data-mention-type]");
95-
if (mentions) {
96-
mentions.forEach((mention) => mention.addEventListener("click", handleClick));
97-
}
60+
const isReady = isWysiwygReady && !disabled;
61+
useSetCursorPosition(!isReady, ref);
9862

99-
return () => {
100-
if (mentions) mentions.forEach((mention) => mention.removeEventListener("click", handleClick));
101-
};
102-
}, [ref, room, content]);
63+
const { isFocused, onFocus } = useIsFocused();
64+
const computedPlaceholder = (!content && placeholder) || undefined;
10365

10466
return (
10567
<div
@@ -108,7 +70,6 @@ export const WysiwygComposer = memo(function WysiwygComposer({
10870
onFocus={onFocus}
10971
onBlur={onFocus}
11072
>
111-
<WysiwygAutocomplete ref={autocompleteRef} suggestion={suggestion} handleMention={wysiwyg.mention} />
11273
<FormattingButtons composer={wysiwyg} actionStates={actionStates} />
11374
<Editor
11475
ref={ref}

src/components/views/rooms/wysiwyg_composer/hooks/useInputEventProcessor.ts

Lines changed: 1 addition & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -32,11 +32,9 @@ import { useMatrixClientContext } from "../../../../../contexts/MatrixClientCont
3232
import { isCaretAtEnd, isCaretAtStart } from "../utils/selection";
3333
import { getEventsFromEditorStateTransfer, getEventsFromRoom } from "../utils/event";
3434
import { endEditing } from "../utils/editing";
35-
import Autocomplete from "../../Autocomplete";
3635

3736
export function useInputEventProcessor(
3837
onSend: () => void,
39-
autocompleteRef: React.RefObject<Autocomplete>,
4038
initialContent?: string,
4139
): (event: WysiwygEvent, composer: Wysiwyg, editor: HTMLElement) => WysiwygEvent | null {
4240
const roomContext = useRoomContext();
@@ -53,10 +51,6 @@ export function useInputEventProcessor(
5351
const send = (): void => {
5452
event.stopPropagation?.();
5553
event.preventDefault?.();
56-
// do not send the message if we have the autocomplete open, regardless of settings
57-
if (autocompleteRef?.current && !autocompleteRef.current.state.hide) {
58-
return;
59-
}
6054
onSend();
6155
};
6256

@@ -71,13 +65,12 @@ export function useInputEventProcessor(
7165
roomContext,
7266
composerContext,
7367
mxClient,
74-
autocompleteRef,
7568
);
7669
} else {
7770
return handleInputEvent(event, send, isCtrlEnterToSend);
7871
}
7972
},
80-
[isCtrlEnterToSend, onSend, initialContent, roomContext, composerContext, mxClient, autocompleteRef],
73+
[isCtrlEnterToSend, onSend, initialContent, roomContext, composerContext, mxClient],
8174
);
8275
}
8376

@@ -92,51 +85,12 @@ function handleKeyboardEvent(
9285
roomContext: IRoomState,
9386
composerContext: ComposerContextState,
9487
mxClient: MatrixClient,
95-
autocompleteRef: React.RefObject<Autocomplete>,
9688
): KeyboardEvent | null {
9789
const { editorStateTransfer } = composerContext;
9890
const isEditing = Boolean(editorStateTransfer);
9991
const isEditorModified = isEditing ? initialContent !== composer.content() : composer.content().length !== 0;
10092
const action = getKeyBindingsManager().getMessageComposerAction(event);
10193

102-
const autocompleteIsOpen = autocompleteRef?.current && !autocompleteRef.current.state.hide;
103-
104-
// we need autocomplete to take priority when it is open for using enter to select
105-
if (autocompleteIsOpen) {
106-
let handled = false;
107-
const autocompleteAction = getKeyBindingsManager().getAutocompleteAction(event);
108-
const component = autocompleteRef.current;
109-
if (component && component.countCompletions() > 0) {
110-
switch (autocompleteAction) {
111-
case KeyBindingAction.ForceCompleteAutocomplete:
112-
case KeyBindingAction.CompleteAutocomplete:
113-
autocompleteRef.current.onConfirmCompletion();
114-
handled = true;
115-
break;
116-
case KeyBindingAction.PrevSelectionInAutocomplete:
117-
autocompleteRef.current.moveSelection(-1);
118-
handled = true;
119-
break;
120-
case KeyBindingAction.NextSelectionInAutocomplete:
121-
autocompleteRef.current.moveSelection(1);
122-
handled = true;
123-
break;
124-
case KeyBindingAction.CancelAutocomplete:
125-
autocompleteRef.current.onEscape(event as {} as React.KeyboardEvent);
126-
handled = true;
127-
break;
128-
default:
129-
break; // don't return anything, allow event to pass through
130-
}
131-
}
132-
133-
if (handled) {
134-
event.preventDefault();
135-
event.stopPropagation();
136-
return event;
137-
}
138-
}
139-
14094
switch (action) {
14195
case KeyBindingAction.SendMessage:
14296
send();

test/components/views/rooms/wysiwyg_composer/SendWysiwygComposer-test.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -93,15 +93,15 @@ describe("SendWysiwygComposer", () => {
9393
customRender(jest.fn(), jest.fn(), false, true);
9494

9595
// Then
96-
expect(await screen.findByTestId("WysiwygComposer")).toBeInTheDocument();
96+
await waitFor(() => expect(screen.getByTestId("WysiwygComposer")).toBeTruthy());
9797
});
9898

99-
it("Should render PlainTextComposer when isRichTextEnabled is at false", async () => {
99+
it("Should render PlainTextComposer when isRichTextEnabled is at false", () => {
100100
// When
101101
customRender(jest.fn(), jest.fn(), false, false);
102102

103103
// Then
104-
expect(await screen.findByTestId("PlainTextComposer")).toBeInTheDocument();
104+
expect(screen.getByTestId("PlainTextComposer")).toBeTruthy();
105105
});
106106

107107
describe.each([{ isRichTextEnabled: true }, { isRichTextEnabled: false }])(

0 commit comments

Comments
 (0)