Skip to content

Commit

Permalink
Actually do what previous commit said
Browse files Browse the repository at this point in the history
Add JavaScript Key Event Handling: Capture the Enter key press within the title input field to insert a newline character.
  • Loading branch information
randemgame committed Nov 16, 2024
1 parent b4f9c5e commit d9493d8
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 1 deletion.
Empty file.
37 changes: 36 additions & 1 deletion ui/v2.5/src/components/Scenes/SceneDetails/SceneEditPanel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -674,6 +674,37 @@ export const SceneEditPanel: React.FC<IProps> = ({
return renderInputField("details", "textarea", "details", props);
}

const [titleInput, setTitleInput] = useState(scene.title ?? "");

const handleTitleKeyPress = (
event: React.KeyboardEvent<HTMLInputElement>
) => {
if (event.key === "Enter") {
event.preventDefault();
const newTitle = titleInput + "\n";
setTitleInput(newTitle);
formik.setFieldValue("title", newTitle);
}
};

function renderTitleField() {
return (
<Form.Control
className="text-input"
type="text"
value={titleInput}
onChange={(e) => {
const newValue = e.target.value;
setTitleInput(newValue);
formik.setFieldValue("title", newValue);
}}
onKeyPress={handleTitleKeyPress}
style={{ whiteSpace: "pre-wrap" }}
isInvalid={!!formik.errors.title}
/>
);
}

return (
<div id="scene-edit-details">
<Prompt
Expand Down Expand Up @@ -730,7 +761,11 @@ export const SceneEditPanel: React.FC<IProps> = ({
</Row>
<Row className="form-container px-3">
<Col lg={7} xl={12}>
{renderInputField("title", "textarea")}
{renderField(
"title",
intl.formatMessage({ id: "title" }),
renderTitleField()
)}
{renderInputField("code", "text", "scene_code")}

{renderURLListField("urls", onScrapeSceneURL, urlScrapable)}
Expand Down

0 comments on commit d9493d8

Please sign in to comment.