Skip to content

Commit

Permalink
another approach with single line marker sequence
Browse files Browse the repository at this point in the history
Keeps single-line input behaviour, uses a marker sequence instead of actual newlines, converts markers to spaces for display
  • Loading branch information
randemgame committed Nov 16, 2024
1 parent d9493d8 commit 615fe18
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 26 deletions.
50 changes: 28 additions & 22 deletions ui/v2.5/src/components/Scenes/SceneDetails/SceneEditPanel.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, { useEffect, useState, useMemo } from "react";
import React, { useEffect, useState, useMemo, useRef } from "react";
import { FormattedMessage, useIntl } from "react-intl";
import { Button, Form, Col, Row, ButtonGroup } from "react-bootstrap";
import Mousetrap from "mousetrap";
Expand Down Expand Up @@ -64,6 +64,8 @@ export const SceneEditPanel: React.FC<IProps> = ({
}) => {
const intl = useIntl();
const Toast = useToast();
const titleInputRef = useRef<HTMLInputElement>(null); // Move ref hook to top


const [galleries, setGalleries] = useState<Gallery[]>([]);
const [performers, setPerformers] = useState<Performer[]>([]);
Expand Down Expand Up @@ -674,33 +676,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() {
const displayValue = formik.values.title.replace(/\n/g, ' ');
console.log("Rendering with value:", displayValue);

return (
<Form.Control
ref={titleInputRef}
className="text-input"
type="text"
value={titleInput}
onChange={(e) => {
const newValue = e.target.value;
setTitleInput(newValue);
formik.setFieldValue("title", newValue);
value={displayValue}
onChange={(e: React.ChangeEvent<HTMLInputElement>) => {
formik.setFieldValue("title", e.target.value);
}}
onKeyDown={(event: React.KeyboardEvent<HTMLInputElement>) => {
if (event.key === "Enter") {
event.preventDefault();
const cursorPosition = event.currentTarget.selectionStart ?? 0;
const newTitle = formik.values.title.substring(0, cursorPosition) +
'\n' +
formik.values.title.substring(cursorPosition);
console.log("New title:", newTitle);
formik.setFieldValue("title", newTitle);

// Safely restore cursor position
setTimeout(() => {
if (titleInputRef.current) {
titleInputRef.current.setSelectionRange(cursorPosition + 1, cursorPosition + 1);
}
}, 0);
}
}}
onKeyPress={handleTitleKeyPress}
style={{ whiteSpace: "pre-wrap" }}
isInvalid={!!formik.errors.title}
/>
);
}
Expand Down
8 changes: 4 additions & 4 deletions ui/v2.5/src/components/Scenes/styles.scss
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,10 @@
padding: 0.5rem 1rem 0 1rem;
}

input[type="text"] {
white-space: pre-wrap;
height: auto;
overflow-y: hidden;
.text-input {
white-space: normal !important;
overflow: hidden !important;
text-overflow: ellipsis !important;
}

.performer-tag-container,
Expand Down

0 comments on commit 615fe18

Please sign in to comment.