Skip to content
Snippets Groups Projects
Unverified Commit 755df4db authored by Timothy Carambat's avatar Timothy Carambat Committed by GitHub
Browse files

auto highlight slash command on typing (#743)

parent 17c1913c
No related branches found
No related tags found
No related merge requests found
......@@ -2,7 +2,6 @@ import { CircleNotch, PaperPlaneRight } from "@phosphor-icons/react";
import React, { useState, useRef } from "react";
export default function PromptInput({
setttings,
message,
submit,
onChange,
......
......@@ -79,7 +79,6 @@ export default function ChatContainer({
<div className="h-full w-full relative">
<ChatHistory settings={settings} history={chatHistory} />
<PromptInput
settings={settings}
message={message}
submit={handleSubmit}
onChange={handleMessageChange}
......
......@@ -5,6 +5,7 @@ import SlashCommandsButton, {
useSlashCommands,
} from "./SlashCommands";
import { isMobile } from "react-device-detect";
import debounce from "lodash.debounce";
export default function PromptInput({
workspace,
......@@ -24,6 +25,13 @@ export default function PromptInput({
submit(e);
};
const checkForSlash = (e) => {
const input = e.target.value;
if (input === "/") setShowSlashCommand(true);
if (showSlashCommand) setShowSlashCommand(false);
return;
};
const captureEnter = (event) => {
if (event.keyCode == 13) {
if (!event.shiftKey) {
......@@ -42,6 +50,7 @@ export default function PromptInput({
: "1px";
};
const watchForSlash = debounce(checkForSlash, 300);
return (
<div className="w-full fixed md:absolute bottom-0 left-0 z-10 md:z-0 flex justify-center items-center">
<SlashCommands
......@@ -59,7 +68,10 @@ export default function PromptInput({
<textarea
onKeyUp={adjustTextArea}
onKeyDown={captureEnter}
onChange={onChange}
onChange={(e) => {
onChange(e);
watchForSlash(e);
}}
required={true}
disabled={inputDisabled}
onFocus={() => setFocused(true)}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment