You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@answer.apache.org by ro...@apache.org on 2024/04/09 03:29:43 UTC

(incubator-answer) branch refactor/editor updated: Add placeholder functionality to the editor

This is an automated email from the ASF dual-hosted git repository.

robin0716 pushed a commit to branch refactor/editor
in repository https://gitbox.apache.org/repos/asf/incubator-answer.git


The following commit(s) were added to refs/heads/refactor/editor by this push:
     new 04b0313f Add placeholder functionality to the editor
04b0313f is described below

commit 04b0313f94f65b7947e1d692d956d49533edaed9
Author: robin <ro...@rnode.me>
AuthorDate: Tue Apr 9 11:29:29 2024 +0800

    Add placeholder functionality to the editor
---
 ui/src/components/Editor/utils/index.ts | 12 +++++++++---
 1 file changed, 9 insertions(+), 3 deletions(-)

diff --git a/ui/src/components/Editor/utils/index.ts b/ui/src/components/Editor/utils/index.ts
index 6debb3dc..9c65a923 100644
--- a/ui/src/components/Editor/utils/index.ts
+++ b/ui/src/components/Editor/utils/index.ts
@@ -22,7 +22,13 @@ import { useEffect, useState } from 'react';
 
 import type { Position } from 'codemirror';
 import { EditorSelection, EditorState, StateEffect } from '@codemirror/state';
-import { EditorView, keymap, KeyBinding, Command } from '@codemirror/view';
+import {
+  EditorView,
+  keymap,
+  KeyBinding,
+  Command,
+  placeholder,
+} from '@codemirror/view';
 import { markdown } from '@codemirror/lang-markdown';
 import type CodeMirror from 'codemirror';
 import 'codemirror/lib/codemirror.css';
@@ -305,7 +311,7 @@ const createEditorUtils = (editor: EditorView & ExtendEditor) => {
 };
 export const useEditor = ({
   editorRef,
-  placeholder,
+  placeholder: placeholderText,
   autoFocus,
   onChange,
   onFocus,
@@ -333,7 +339,7 @@ export const useEditor = ({
       },
     });
     let startState = EditorState.create({
-      extensions: [markdown(), theme],
+      extensions: [markdown(), theme, placeholder(placeholderText)],
     });
 
     const view = new EditorView({