You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@answer.apache.org by sh...@apache.org on 2024/03/18 03:03:07 UTC
(incubator-answer) branch feat/1.3.0/ui created (now be1d5fb4)
This is an automated email from the ASF dual-hosted git repository.
shuai pushed a change to branch feat/1.3.0/ui
in repository https://gitbox.apache.org/repos/asf/incubator-answer.git
at be1d5fb4 fix: editor fixes the issue where some line breaks are missing when the pasted content contains images
This branch includes the following new commits:
new be1d5fb4 fix: editor fixes the issue where some line breaks are missing when the pasted content contains images
The 1 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails. The revisions
listed as "add" were already present in the repository and have only
been added to this reference.
(incubator-answer) 01/01: fix: editor fixes the issue where some line breaks are missing when the pasted content contains images
Posted by sh...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
shuai pushed a commit to branch feat/1.3.0/ui
in repository https://gitbox.apache.org/repos/asf/incubator-answer.git
commit be1d5fb44566c469033ca2d93a6d2a08170f8dbe
Author: shuai <li...@sifou.com>
AuthorDate: Mon Mar 18 11:02:51 2024 +0800
fix: editor fixes the issue where some line breaks are missing when the pasted content contains images
---
ui/src/components/Editor/ToolBars/image.tsx | 20 ++++++++++++++++----
ui/src/i18n/init.ts | 8 ++++----
.../pages/Review/components/EditPostModal/index.tsx | 1 +
3 files changed, 21 insertions(+), 8 deletions(-)
diff --git a/ui/src/components/Editor/ToolBars/image.tsx b/ui/src/components/Editor/ToolBars/image.tsx
index 95737db6..1bc429a0 100644
--- a/ui/src/components/Editor/ToolBars/image.tsx
+++ b/ui/src/components/Editor/ToolBars/image.tsx
@@ -167,17 +167,29 @@ const Image = ({ editorInstance }) => {
}
event.preventDefault();
- const newHtml = new DOMParser()
+ let innerText = '';
+ const allPTag = new DOMParser()
.parseFromString(
htmlStr.replace(
/<img([\s\S]*?) src\s*=\s*(['"])([\s\S]*?)\2([^>]*)>/gi,
- `<p>\n\n</p>`,
+ `<p>\n\n</p>`,
),
'text/html',
)
- .querySelector('body')?.innerText as string;
+ .querySelectorAll('body p');
+
+ allPTag.forEach((p, index) => {
+ const text = p.textContent || '';
+ if (text !== '') {
+ if (index === allPTag.length - 1) {
+ innerText += `${p.textContent}`;
+ } else {
+ innerText += `${p.textContent}${text.endsWith('\n') ? '' : '\n\n'}`;
+ }
+ }
+ });
- editor.replaceSelection(newHtml);
+ editor.replaceSelection(innerText);
};
const handleClick = () => {
if (!link.value) {
diff --git a/ui/src/i18n/init.ts b/ui/src/i18n/init.ts
index 66d9576e..03f775cb 100644
--- a/ui/src/i18n/init.ts
+++ b/ui/src/i18n/init.ts
@@ -21,7 +21,7 @@ import { initReactI18next } from 'react-i18next';
import i18next from 'i18next';
import en_US from '@i18n/en_US.yaml';
-// import zh_CN from '@i18n/zh_CN.yaml';
+import zh_CN from '@i18n/zh_CN.yaml';
import { DEFAULT_LANG, LANG_RESOURCE_STORAGE_KEY } from '@/common/constants';
import Storage from '@/utils/storage';
@@ -34,9 +34,9 @@ const initResources = {
en_US: {
translation: en_US.ui,
},
- // zh_CN: {
- // translation: zh_CN.ui,
- // },
+ zh_CN: {
+ translation: zh_CN.ui,
+ },
};
const storageLang = Storage.get(LANG_RESOURCE_STORAGE_KEY);
diff --git a/ui/src/pages/Review/components/EditPostModal/index.tsx b/ui/src/pages/Review/components/EditPostModal/index.tsx
index e35a82ca..4190240c 100644
--- a/ui/src/pages/Review/components/EditPostModal/index.tsx
+++ b/ui/src/pages/Review/components/EditPostModal/index.tsx
@@ -76,6 +76,7 @@ const Index: FC<Props> = ({
if (bol) {
callback?.();
}
+ setFormData(initFormData);
handleClose();
setLoaded(false);
};