From a86117f613673edd39f517b00b572fd1d2d12c6d Mon Sep 17 00:00:00 2001 From: Kazuki H <58931401+Kaz205@users.noreply.github.com> Date: Mon, 19 Feb 2024 09:54:47 +0900 Subject: [PATCH] feat: add new line if the cursor is on a character when adding a tag (#2960) --- .../MemoEditor/ActionButton/TagSelector.tsx | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/web/src/components/MemoEditor/ActionButton/TagSelector.tsx b/web/src/components/MemoEditor/ActionButton/TagSelector.tsx index e3660be4..186c87ea 100644 --- a/web/src/components/MemoEditor/ActionButton/TagSelector.tsx +++ b/web/src/components/MemoEditor/ActionButton/TagSelector.tsx @@ -32,7 +32,16 @@ const TagSelector = (props: Props) => { }); const handleTagClick = (tag: string) => { - editorRef.current?.insertText(`#${tag} `); + const current = editorRef.current; + if (current === null) return; + + const line = current.getLine(current.getCursorLineNumber()); + const lastCharOfLine = line.slice(-1); + + if (lastCharOfLine !== " " && lastCharOfLine !== " " && line !== "") { + current.insertText("\n"); + } + current.insertText(`#${tag} `); }; return (