|
@@ -123,6 +123,7 @@ const EditorComp = defineComponent({
|
|
blurCanceler?.();
|
|
blurCanceler?.();
|
|
});
|
|
});
|
|
const preHeight = ref<number>(0);
|
|
const preHeight = ref<number>(0);
|
|
|
|
+ const preTag = ref();
|
|
const initHeight = () => {
|
|
const initHeight = () => {
|
|
const dom: HTMLElement | null = document.querySelector(
|
|
const dom: HTMLElement | null = document.querySelector(
|
|
`#editor_${props.compId}`
|
|
`#editor_${props.compId}`
|
|
@@ -220,11 +221,28 @@ const EditorComp = defineComponent({
|
|
selection?.addRange(range);
|
|
selection?.addRange(range);
|
|
|
|
|
|
editorRefVal.model.document.on("change:data", () => {
|
|
editorRefVal.model.document.on("change:data", () => {
|
|
- const value = editorRefVal?.getData();
|
|
|
|
-
|
|
|
|
|
|
+ let value = editorRefVal?.getData();
|
|
|
|
+ console.log(value);
|
|
if (comp.value.text !== value) {
|
|
if (comp.value.text !== value) {
|
|
- actions.updateCompData(comp, "value.text", value);
|
|
|
|
|
|
+ if (!value) {
|
|
|
|
+ preTag.value = comp.value.text;
|
|
|
|
+ }
|
|
|
|
+ if (!comp.value.text && preTag.value) {
|
|
|
|
+ const text = value?.replace(/<[^>]+>/g, "");
|
|
|
|
+ const spanTagReg =
|
|
|
|
+ /([\s\S]*?<span[\s\S]*?>)([\s\S]*?)(<\/span>[\s\S]*?)/gi;
|
|
|
|
|
|
|
|
+ value = preTag.value?.replace(spanTagReg, `$1${text}$3`);
|
|
|
|
+ editorRefVal?.setData(value || "");
|
|
|
|
+ editorRefVal?.focus();
|
|
|
|
+ const selection = window.getSelection();
|
|
|
|
+ nextTick(() => {
|
|
|
|
+ if (selection?.focusNode) {
|
|
|
|
+ selection?.setPosition(selection?.focusNode, text?.length);
|
|
|
|
+ }
|
|
|
|
+ });
|
|
|
|
+ }
|
|
|
|
+ actions.updateCompData(comp, "value.text", value);
|
|
nextTick(() => {
|
|
nextTick(() => {
|
|
const element = editorRefVal?.ui.view.editable.element || null;
|
|
const element = editorRefVal?.ui.view.editable.element || null;
|
|
if (!element) {
|
|
if (!element) {
|