prettier / validate / pressing enter in input field allows line breaks

couldn't figure out how to visually represent the line breaks in edit field (currently uses space character for new line)
line breaks are lost if any other change made to edit field. otherwise, works alright
This commit is contained in:
Herpes3000 2024-11-17 03:08:21 +02:00
parent 615fe18593
commit 097d9f7d73
2 changed files with 15 additions and 15 deletions

View file

@ -64,8 +64,7 @@ export const SceneEditPanel: React.FC<IProps> = ({
}) => { }) => {
const intl = useIntl(); const intl = useIntl();
const Toast = useToast(); const Toast = useToast();
const titleInputRef = useRef<HTMLInputElement>(null); // Move ref hook to top const titleInputRef = useRef<HTMLInputElement>(null);
const [galleries, setGalleries] = useState<Gallery[]>([]); const [galleries, setGalleries] = useState<Gallery[]>([]);
const [performers, setPerformers] = useState<Performer[]>([]); const [performers, setPerformers] = useState<Performer[]>([]);
@ -677,8 +676,7 @@ export const SceneEditPanel: React.FC<IProps> = ({
} }
function renderTitleField() { function renderTitleField() {
const displayValue = formik.values.title.replace(/\n/g, ' '); const displayValue = formik.values.title.replace(/\n/g, " ");
console.log("Rendering with value:", displayValue);
return ( return (
<Form.Control <Form.Control
@ -693,16 +691,18 @@ export const SceneEditPanel: React.FC<IProps> = ({
if (event.key === "Enter") { if (event.key === "Enter") {
event.preventDefault(); event.preventDefault();
const cursorPosition = event.currentTarget.selectionStart ?? 0; const cursorPosition = event.currentTarget.selectionStart ?? 0;
const newTitle = formik.values.title.substring(0, cursorPosition) + const newTitle =
'\n' + formik.values.title.substring(0, cursorPosition) +
"\n" +
formik.values.title.substring(cursorPosition); formik.values.title.substring(cursorPosition);
console.log("New title:", newTitle);
formik.setFieldValue("title", newTitle); formik.setFieldValue("title", newTitle);
// Safely restore cursor position
setTimeout(() => { setTimeout(() => {
if (titleInputRef.current) { if (titleInputRef.current) {
titleInputRef.current.setSelectionRange(cursorPosition + 1, cursorPosition + 1); titleInputRef.current.setSelectionRange(
cursorPosition + 1,
cursorPosition + 1
);
} }
}, 0); }, 0);
} }

View file

@ -24,9 +24,9 @@
} }
.text-input { .text-input {
white-space: normal !important; overflow: hidden;
overflow: hidden !important; text-overflow: ellipsis;
text-overflow: ellipsis !important; white-space: normal;
} }
.performer-tag-container, .performer-tag-container,