Skip to content

Commit

Permalink
prettier / validate / pressing enter in input field allows line breaks
Browse files Browse the repository at this point in the history
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
  • Loading branch information
randemgame committed Nov 17, 2024
1 parent 615fe18 commit 097d9f7
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 15 deletions.
24 changes: 12 additions & 12 deletions ui/v2.5/src/components/Scenes/SceneDetails/SceneEditPanel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,7 @@ export const SceneEditPanel: React.FC<IProps> = ({
}) => {
const intl = useIntl();
const Toast = useToast();
const titleInputRef = useRef<HTMLInputElement>(null); // Move ref hook to top

const titleInputRef = useRef<HTMLInputElement>(null);

const [galleries, setGalleries] = useState<Gallery[]>([]);
const [performers, setPerformers] = useState<Performer[]>([]);
Expand Down Expand Up @@ -677,9 +676,8 @@ export const SceneEditPanel: React.FC<IProps> = ({
}

function renderTitleField() {
const displayValue = formik.values.title.replace(/\n/g, ' ');
console.log("Rendering with value:", displayValue);

const displayValue = formik.values.title.replace(/\n/g, " ");

return (
<Form.Control
ref={titleInputRef}
Expand All @@ -693,16 +691,18 @@ export const SceneEditPanel: React.FC<IProps> = ({
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);
const newTitle =
formik.values.title.substring(0, cursorPosition) +
"\n" +
formik.values.title.substring(cursorPosition);
formik.setFieldValue("title", newTitle);

// Safely restore cursor position

setTimeout(() => {
if (titleInputRef.current) {
titleInputRef.current.setSelectionRange(cursorPosition + 1, cursorPosition + 1);
titleInputRef.current.setSelectionRange(
cursorPosition + 1,
cursorPosition + 1
);
}
}, 0);
}
Expand Down
6 changes: 3 additions & 3 deletions ui/v2.5/src/components/Scenes/styles.scss
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@
}

.text-input {
white-space: normal !important;
overflow: hidden !important;
text-overflow: ellipsis !important;
overflow: hidden;
text-overflow: ellipsis;
white-space: normal;
}

.performer-tag-container,
Expand Down

0 comments on commit 097d9f7

Please sign in to comment.