Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

enh: make inputbar scrollable #1932

Merged
merged 2 commits into from
Oct 3, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
100 changes: 61 additions & 39 deletions front/components/assistant/conversation/InputBar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -374,7 +374,7 @@ export function AssistantInputBar({
<div className="flex flex-1 flex-row items-center">
<div
className={classNames(
"relative flex flex-1 flex-row items-end items-stretch px-4",
"relative flex flex-1 flex-row items-stretch px-4",
"border-2 border-action-300 bg-white focus-within:border-action-400",
"rounded-xl drop-shadow-2xl transition-all duration-300",
isAnimating
Expand All @@ -393,7 +393,12 @@ export function AssistantInputBar({
Ask a question
</div>
<div
className={contentEditableClasses}
className={classNames(
contentEditableClasses,
"scrollbar-hide",
"overflow-y-auto",
"max-h-96"
)}
contentEditable={true}
ref={inputRef}
id={"dust-input-bar"}
Expand Down Expand Up @@ -442,14 +447,24 @@ export function AssistantInputBar({
node.textContent?.slice(0, offset) +
text +
node.textContent?.slice(offset);
}

// Move the cursor to the end of the past.
const newRange = document.createRange();
newRange.setStart(node, offset + text.length);
newRange.setEnd(node, offset + text.length);
selection.removeAllRanges();
selection.addRange(newRange);
// Scroll to the end of the input
if (inputRef.current) {
setTimeout(() => {
const element = inputRef.current;
if (element) {
element.scrollTop = element.scrollHeight;
}
}, 0);
}

// Move the cursor to the end of the paste.
const newRange = document.createRange();
newRange.setStart(node, offset + text.length);
newRange.setEnd(node, offset + text.length);
selection.removeAllRanges();
selection.addRange(newRange);
}}
onKeyDown={(e) => {
// We prevent the content editable from creating italics, bold and underline.
Expand Down Expand Up @@ -687,38 +702,45 @@ export function AssistantInputBar({
}}
></div>

<div className={classNames("z-10 flex flex-row space-x-4 pr-2")}>
<div className="flex flex-col justify-center">
<AssistantPicker
owner={owner}
onItemClick={(c) => {
// We construct the HTML for an AgentMention and inject it in the content
// editable with an extra space after it.
const mentionNode = getAgentMentionNode(c);
const contentEditable =
document.getElementById("dust-input-bar");
if (contentEditable && mentionNode) {
// Add mentionNode as last childe of contentEditable.
contentEditable.appendChild(mentionNode);
const afterTextNode = document.createTextNode(" ");
contentEditable.appendChild(afterTextNode);
contentEditable.focus();
moveCursorToEnd(contentEditable);
}
}}
assistants={activeAgents}
showBuilderButtons={true}
/>
<div
className={classNames(
"z-10 flex flex-row items-end space-x-4 pb-4 pl-2 pr-2"
)}
>
<div className="flex h-full flex-col justify-end">
<div className="flex flex-row items-center space-x-4 pr-2">
<AssistantPicker
owner={owner}
onItemClick={(c) => {
// We construct the HTML for an AgentMention and inject it in the content
// editable with an extra space after it.
const mentionNode = getAgentMentionNode(c);
const contentEditable =
document.getElementById("dust-input-bar");
if (contentEditable && mentionNode) {
// Add mentionNode as last childe of contentEditable.
contentEditable.appendChild(mentionNode);
const afterTextNode = document.createTextNode(" ");
contentEditable.appendChild(afterTextNode);
contentEditable.focus();
moveCursorToEnd(contentEditable);
}
}}
assistants={activeAgents}
showBuilderButtons={true}
/>

<IconButton
variant="primary"
icon={PaperAirplaneIcon}
size="md"
disabled={empty}
onClick={() => {
void handleSubmit();
}}
/>
</div>
</div>
<IconButton
variant="primary"
icon={PaperAirplaneIcon}
size="md"
disabled={empty}
onClick={() => {
void handleSubmit();
}}
/>
</div>
</div>
</div>
Expand Down
6 changes: 6 additions & 0 deletions front/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions front/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@
"sqlite3": "^5.1.4",
"sse.js": "^0.6.1",
"swr": "^2.0.2",
"tailwind-scrollbar-hide": "^1.1.7",
"tailwindcss": "^3.2.4",
"three": "^0.155.0",
"uuid": "^9.0.0"
Expand Down
2 changes: 1 addition & 1 deletion front/tailwind.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ module.exports = {
backgroundColor: ["dark"],
},
},
plugins: [require("@tailwindcss/forms")],
plugins: [require("@tailwindcss/forms"), require("tailwind-scrollbar-hide")],
content: [
"./pages/**/*.{js,ts,jsx,tsx}",
"./components/**/*.{js,ts,jsx,tsx}",
Expand Down