mirror of
https://github.com/revoltchat/revite.git
synced 2024-12-25 15:12:08 -05:00
Add auto-complete to message editor.
This commit is contained in:
parent
7e4406682f
commit
a628b0acd1
2 changed files with 18 additions and 2 deletions
|
@ -133,7 +133,7 @@ export const MessageContent = styled.div`
|
||||||
min-width: 0;
|
min-width: 0;
|
||||||
flex-grow: 1;
|
flex-grow: 1;
|
||||||
display: flex;
|
display: flex;
|
||||||
overflow: hidden;
|
// overflow: hidden;
|
||||||
font-size: .875rem;
|
font-size: .875rem;
|
||||||
flex-direction: column;
|
flex-direction: column;
|
||||||
justify-content: center;
|
justify-content: center;
|
||||||
|
|
|
@ -5,6 +5,7 @@ import { useContext, useEffect, useState } from "preact/hooks";
|
||||||
import { AppContext } from "../../../context/revoltjs/RevoltClient";
|
import { AppContext } from "../../../context/revoltjs/RevoltClient";
|
||||||
import { isTouchscreenDevice } from "../../../lib/isTouchscreenDevice";
|
import { isTouchscreenDevice } from "../../../lib/isTouchscreenDevice";
|
||||||
import { IntermediateContext, useIntermediate } from "../../../context/intermediate/Intermediate";
|
import { IntermediateContext, useIntermediate } from "../../../context/intermediate/Intermediate";
|
||||||
|
import AutoComplete, { useAutoComplete } from "../../../components/common/AutoComplete";
|
||||||
|
|
||||||
const EditorBase = styled.div`
|
const EditorBase = styled.div`
|
||||||
display: flex;
|
display: flex;
|
||||||
|
@ -13,6 +14,7 @@ const EditorBase = styled.div`
|
||||||
textarea {
|
textarea {
|
||||||
resize: none;
|
resize: none;
|
||||||
padding: 12px;
|
padding: 12px;
|
||||||
|
font-size: .875rem;
|
||||||
border-radius: 3px;
|
border-radius: 3px;
|
||||||
white-space: pre-wrap;
|
white-space: pre-wrap;
|
||||||
background: var(--secondary-header);
|
background: var(--secondary-header);
|
||||||
|
@ -70,16 +72,27 @@ export default function MessageEditor({ message, finish }: Props) {
|
||||||
return () => document.body.removeEventListener("keyup", keyUp);
|
return () => document.body.removeEventListener("keyup", keyUp);
|
||||||
}, [focusTaken]);
|
}, [focusTaken]);
|
||||||
|
|
||||||
|
const { onChange, onKeyUp, onKeyDown, onFocus, onBlur, ...autoCompleteProps } =
|
||||||
|
useAutoComplete(v => setContent(v ?? ''), {
|
||||||
|
users: { type: 'all' }
|
||||||
|
});
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<EditorBase>
|
<EditorBase>
|
||||||
|
<AutoComplete detached {...autoCompleteProps} />
|
||||||
<TextAreaAutoSize
|
<TextAreaAutoSize
|
||||||
forceFocus
|
forceFocus
|
||||||
maxRows={3}
|
maxRows={3}
|
||||||
padding={12}
|
padding={12}
|
||||||
value={content}
|
value={content}
|
||||||
maxLength={2000}
|
maxLength={2000}
|
||||||
onChange={ev => setContent(ev.currentTarget.value)}
|
onChange={ev => {
|
||||||
|
onChange(ev);
|
||||||
|
setContent(ev.currentTarget.value)
|
||||||
|
}}
|
||||||
onKeyDown={e => {
|
onKeyDown={e => {
|
||||||
|
if (onKeyDown(e)) return;
|
||||||
|
|
||||||
if (
|
if (
|
||||||
!e.shiftKey &&
|
!e.shiftKey &&
|
||||||
e.key === "Enter" &&
|
e.key === "Enter" &&
|
||||||
|
@ -89,6 +102,9 @@ export default function MessageEditor({ message, finish }: Props) {
|
||||||
save();
|
save();
|
||||||
}
|
}
|
||||||
}}
|
}}
|
||||||
|
onKeyUp={onKeyUp}
|
||||||
|
onFocus={onFocus}
|
||||||
|
onBlur={onBlur}
|
||||||
/>
|
/>
|
||||||
<span className="caption">
|
<span className="caption">
|
||||||
escape to <a onClick={finish}>cancel</a> ·
|
escape to <a onClick={finish}>cancel</a> ·
|
||||||
|
|
Loading…
Reference in a new issue