From 88f147f3b4e72fa33f3d128eb45b91d41a48bef5 Mon Sep 17 00:00:00 2001 From: Badi Ifaoui Date: Tue, 28 Nov 2023 12:42:48 +0100 Subject: [PATCH] feat(#2): disable commands --- components.json | 4 ++- src/components/views/rooms/Autocomplete.tsx | 31 +++++++++++++++++++ src/editor/commands.tsx | 34 +++++++++++++++++++++ 3 files changed, 68 insertions(+), 1 deletion(-) create mode 100644 src/components/views/rooms/Autocomplete.tsx create mode 100644 src/editor/commands.tsx diff --git a/components.json b/components.json index cc5046ed69..607f7adbdf 100644 --- a/components.json +++ b/components.json @@ -1,5 +1,7 @@ { "src/components/views/auth/AuthFooter.tsx": "src/components/views/auth/VectorAuthFooter.tsx", "src/components/views/auth/AuthHeaderLogo.tsx": "src/components/views/auth/VectorAuthHeaderLogo.tsx", - "src/components/views/auth/AuthPage.tsx": "src/components/views/auth/VectorAuthPage.tsx" + "src/components/views/auth/AuthPage.tsx": "src/components/views/auth/VectorAuthPage.tsx", + "src/components/views/rooms/Autocomplete.tsx": "src/components/views/rooms/Autocomplete.tsx", + "src/editor/commands.tsx": "src/editor/commands.tsx" } diff --git a/src/components/views/rooms/Autocomplete.tsx b/src/components/views/rooms/Autocomplete.tsx new file mode 100644 index 0000000000..d23fd170bc --- /dev/null +++ b/src/components/views/rooms/Autocomplete.tsx @@ -0,0 +1,31 @@ +import React from "react"; + +export const generateCompletionDomId = (n: number): string => `mx_Autocomplete_Completion_${n}`; + +export default class Autocomplete extends React.PureComponent { + public constructor(props: {} | Readonly<{}>) { + super(props); + + this.state = { + // list of completionResults, each containing completions + completions: [], + + // array of completions, so we can look up current selection by offset quickly + completionList: [], + + // how far down the completion list we are (THIS IS 1-INDEXED!) + selectionOffset: 1, + + // whether we should show completions if they're available + shouldShowCompletions: true, + + hide: false, + + forceComplete: false, + }; + } + + public render(): React.ReactNode { + return null; + } +} diff --git a/src/editor/commands.tsx b/src/editor/commands.tsx new file mode 100644 index 0000000000..e655e81171 --- /dev/null +++ b/src/editor/commands.tsx @@ -0,0 +1,34 @@ +import { IContent, MatrixClient } from "matrix-js-sdk/src/matrix"; +import { Command, getCommand } from "matrix-react-sdk/src/SlashCommands"; +import EditorModel from "matrix-react-sdk/src/editor/model"; +import { Type } from "matrix-react-sdk/src/editor/parts"; + +export function isSlashCommand(model: EditorModel): boolean { + return false; +} + +export function getSlashCommand(model: EditorModel): [Command | undefined, string | undefined, string] { + const commandText = model.parts.reduce((text, part) => { + // use mxid to textify user pills in a command and room alias/id for room pills + if (part.type === Type.UserPill || part.type === Type.RoomPill) { + return text + part.resourceId; + } + return text + part.text; + }, ""); + const { cmd, args } = getCommand(commandText); + return [cmd, args, commandText]; +} + +export async function runSlashCommand( + matrixClient: MatrixClient, + cmd: Command, + args: string | undefined, + roomId: string, + threadId: string | null, +): Promise<[content: IContent | null, success: boolean]> { + return [null, false]; +} + +export async function shouldSendAnyway(commandText: string): Promise { + return true; +}