|
@@ -222,17 +222,22 @@ const EditorComp = defineComponent({
|
|
|
|
|
|
editorRefVal.model.document.on("change:data", () => {
|
|
editorRefVal.model.document.on("change:data", () => {
|
|
let value = editorRefVal?.getData();
|
|
let value = editorRefVal?.getData();
|
|
- console.log(value);
|
|
|
|
if (comp.value.text !== value) {
|
|
if (comp.value.text !== value) {
|
|
if (!value) {
|
|
if (!value) {
|
|
- preTag.value = comp.value.text;
|
|
|
|
|
|
+ const tagReg =
|
|
|
|
+ /(<(p|h2|h3)[\s\S]*?>)(<span[\s\S]*?>)?([\s\S]*?)(<\/span>)?(<\/(p|h2|h3)>)/gi;
|
|
|
|
+ const blocks = comp.value.text.match(tagReg);
|
|
|
|
+ if (!blocks) {
|
|
|
|
+ return;
|
|
|
|
+ }
|
|
|
|
+ preTag.value = blocks[0];
|
|
}
|
|
}
|
|
if (!comp.value.text && preTag.value) {
|
|
if (!comp.value.text && preTag.value) {
|
|
const text = value?.replace(/<[^>]+>/g, "");
|
|
const text = value?.replace(/<[^>]+>/g, "");
|
|
- const spanTagReg =
|
|
|
|
- /([\s\S]*?<span[\s\S]*?>)([\s\S]*?)(<\/span>[\s\S]*?)/gi;
|
|
|
|
|
|
+ const tagReg =
|
|
|
|
+ /(<(p|h2|h3)[\s\S]*?>)(<span[\s\S]*?>)?([\s\S]*?)(<\/span>)?(<\/(p|h2|h3)>)/gi;
|
|
|
|
|
|
- value = preTag.value?.replace(spanTagReg, `$1${text}$3`);
|
|
|
|
|
|
+ value = preTag.value?.replace(tagReg, `$1$3${text}$5$6`);
|
|
editorRefVal?.setData(value || "");
|
|
editorRefVal?.setData(value || "");
|
|
editorRefVal?.focus();
|
|
editorRefVal?.focus();
|
|
const selection = window.getSelection();
|
|
const selection = window.getSelection();
|