A fully open source & end-to-end encrypted note taking alternative to Evernote.
TypeScript asp-net-coredotnet-coreelectronfosshacktoberfestnote-managmentnote-takingnote-taking-appnotebooknotesnotes-appopen-sourceopensourceprivacyproductivityreactreact-nativereactjsself-hosted
web: wrap & remove auto-resize of note title (#7290)
01zulfi2708bac4fb70
diff --git a/apps/web/src/components/editor/title-box.tsx b/apps/web/src/components/editor/title-box.tsxindex 222c16d04..de6bc624a 100644--- a/apps/web/src/components/editor/title-box.tsx+++ b/apps/web/src/components/editor/title-box.tsx@@ -17,25 +17,17 @@ You should have received a copy of the GNU General Public Licensealong with this program. If not, see <http://www.gnu.org/licenses/>.*/-import React, {- useCallback,- useEffect,- useLayoutEffect,- useMemo,- useRef,- useState-} from "react";-import { Input } from "@theme-ui/components";+import React, { useEffect, useLayoutEffect, useMemo, useRef } from "react";+import { Textarea } from "@theme-ui/components";import { useEditorStore } from "../../stores/editor-store";import { debounceWithId } from "@notesnook/common";-import useMobile from "../../hooks/use-mobile";-import useTablet from "../../hooks/use-tablet";import { useEditorConfig, useEditorManager } from "./manager";import { getFontById } from "@notesnook/editor";import { replaceDateTime } from "@notesnook/editor";import { useStore as useSettingsStore } from "../../stores/setting-store";import { AppEventManager, AppEvents } from "../../common/app-events";import { strings } from "@notesnook/intl";+import { NEWLINE_STRIP_REGEX } from "@notesnook/core";type TitleBoxProps = {id: string;@@ -44,12 +36,10 @@ type TitleBoxProps = {function TitleBox(props: TitleBoxProps) {const { readonly, id } = props;- const inputRef = useRef<HTMLInputElement>(null);+ const inputRef = useRef<HTMLTextAreaElement>(null);const pendingChanges = useRef(false);// const id = useStore((store) => store.session.id);const sessionType = useEditorStore((store) => store.getSession(id)?.type);- const isMobile = useMobile();- const isTablet = useTablet();const { editorConfig } = useEditorConfig();const dateFormat = useSettingsStore((store) => store.dateFormat);const timeFormat = useSettingsStore((store) => store.timeFormat);@@ -59,18 +49,6 @@ function TitleBox(props: TitleBoxProps) {[editorConfig.fontFamily]);- const updateFontSize = useCallback(- (length: number) => {- if (!inputRef.current) return;- const fontSize = textLengthToFontSize(- length,- isMobile || isTablet ? 1.625 : 2.625- );- inputRef.current.style.fontSize = `${fontSize}em`;- },- [isMobile, isTablet]- );-useLayoutEffect(() => {const session = useEditorStore.getState().getSession(id);if (!session || !("note" in session) || !session.note || !inputRef.current)@@ -84,13 +62,7 @@ function TitleBox(props: TitleBoxProps) {inputRef.current,(input) => (input.value = title || ""));- updateFontSize(title?.length || 0);- }, [sessionType, id, updateFontSize]);-- useEffect(() => {- if (!inputRef.current) return;- updateFontSize(inputRef.current.value.length);- }, [isTablet, isMobile, updateFontSize]);+ }, [sessionType, id]);useEffect(() => {const { unsubscribe } = AppEventManager.subscribe(@@ -109,7 +81,6 @@ function TitleBox(props: TitleBoxProps) {inputRef.current,(input) => (input.value = title));- updateFontSize(title.length);if (!preventSave) {pendingChanges.current = true;debouncedOnTitleChange(sessionId, sessionId, title, pendingChanges);@@ -120,10 +91,10 @@ function TitleBox(props: TitleBoxProps) {return () => {unsubscribe();};- }, [updateFontSize, id]);+ }, [id]);return (- <Input+ <Textarearef={inputRef}variant="clean"id="editor-title"@@ -132,18 +103,30 @@ function TitleBox(props: TitleBoxProps) {placeholder={strings.noteTitle()}readOnly={readonly}dir="auto"+ wrap="soft"+ rows={1}sx={{p: 0,fontFamily,fontSize: ["1.625em", "1.625em", "2.625em"],fontWeight: "heading",width: "100%",+ fieldSizing: "content",+ whiteSpace: "pre-wrap",+ resize: "none",+ overflow: "hidden","::placeholder": {color: "placeholder"}}}+ onKeyDown={(e) => {+ if (e.key === "Enter") {+ e.preventDefault();+ }+ }}onKeyUp={(e) => {if (e.key === "Enter") {+ e.preventDefault();const context = useEditorManager.getState().getEditor(id);if (!context) return;context.editor?.focus({ scrollIntoView: true });@@ -155,9 +138,8 @@ function TitleBox(props: TitleBoxProps) {e.target.value,dateFormat,timeFormat- );+ ).replace(NEWLINE_STRIP_REGEX, " ");debouncedOnTitleChange(id, id, e.target.value, pendingChanges);- updateFontSize(e.target.value.length);}}/>);@@ -178,16 +160,9 @@ function onTitleChange(const debouncedOnTitleChange = debounceWithId(onTitleChange, 100);-function textLengthToFontSize(length: number, max: number) {- const stepLength = 35;- const decreaseStep = 0.5;- const steps = length / stepLength;- return Math.max(1.2, Math.min(max, max - steps * decreaseStep));-}-function withSelectionPersist(- input: HTMLInputElement,- action: (input: HTMLInputElement) => void+ input: HTMLTextAreaElement,+ action: (input: HTMLTextAreaElement) => void) {const selection = {start: input.selectionStart,