提交 9c635990 编写于 作者: 璃白.'s avatar 璃白. 🌻

fix

上级 44c32ed7
...@@ -48,6 +48,7 @@ ...@@ -48,6 +48,7 @@
:rows="rows" :rows="rows"
:html.sync="html" :html.sync="html"
:id="textareaId" :id="textareaId"
:ref="'md_textarea' + id"
@tab="$refs['md_header' + id].tab()" @tab="$refs['md_header' + id].tab()"
@submit="submit" @submit="submit"
v-else v-else
......
...@@ -31,9 +31,6 @@ export default { ...@@ -31,9 +31,6 @@ export default {
} }
}, },
mounted() { mounted() {
setTimeout(() => {
// this.resetMinHeight();
}, 0);
this.addClass(); this.addClass();
}, },
updated() { updated() {
...@@ -46,39 +43,6 @@ export default { ...@@ -46,39 +43,6 @@ export default {
if (!previewDom) return; if (!previewDom) return;
previewDom.className = "md_hljs"; previewDom.className = "md_hljs";
}, 0); }, 0);
},
transferMarkdown(val) {
marked.setOptions({
highlight: function(code, lang, callback) {
const html = require("highlight.js").highlightAuto(code).value;
return html;
}
});
const str = val + "";
// if (!str.trim()) return;
const html = marked(str);
this.$emit("update:html", html);
},
resetMinHeight() {
console.log("resetHeight");
const textEl = document.getElementById(this.id);
if (!textEl) return;
const height = textEl.offsetHeight;
console.log("编辑区高度", height);
this.htmlMinHeight = height;
}
},
watch: {
text: {
immediate: true,
handler: function(val) {
setTimeout(() => {
// this.resetMinHeight();
}, 0);
// this.transferMarkdown(val);
}
} }
} }
}; };
......
...@@ -88,11 +88,16 @@ export default { ...@@ -88,11 +88,16 @@ export default {
document.addEventListener("mouseup", this.checkSelection); document.addEventListener("mouseup", this.checkSelection);
}, },
mounted() { mounted() {
setTimeout(() => { this.resetPreviewMinHeight();
this.resetMinHeight();
}, 0);
}, },
watch: { watch: {
isFocus: {
handler: function(val) {
if (val) {
this.resetPreviewMinHeight();
}
}
},
text: { text: {
immediate: true, immediate: true,
handler: function(val) { handler: function(val) {
...@@ -111,7 +116,7 @@ export default { ...@@ -111,7 +116,7 @@ export default {
document.body.style.overflow = "auto"; document.body.style.overflow = "auto";
} }
setTimeout(() => { setTimeout(() => {
this.reSizeHeight(); this.reSizeTextareaHeight();
}, 0); }, 0);
} }
}, },
...@@ -120,7 +125,7 @@ export default { ...@@ -120,7 +125,7 @@ export default {
handler: function() { handler: function() {
setTimeout(() => { setTimeout(() => {
if (!this.autoSize) return; if (!this.autoSize) return;
this.reSizeHeight(); this.reSizeTextareaHeight();
}, 0); }, 0);
} }
} }
...@@ -139,15 +144,13 @@ export default { ...@@ -139,15 +144,13 @@ export default {
} }
}, },
methods: { methods: {
resetMinHeight() { resetPreviewMinHeight() {
console.log("resetHeight"); setTimeout(() => {
const textEl = document.getElementById(this.id);
const textEl = document.getElementById(this.id); if (!textEl) return;
if (!textEl) return; const height = textEl.offsetHeight;
const height = textEl.offsetHeight; this.$emit("update:htmlMinHeight", height);
console.log("编辑区高度", height); }, 0);
this.$emit("update:htmlMinHeight", height);
// this.htmlMinHeight = height;
}, },
transferMarkdown(val) { transferMarkdown(val) {
marked.setOptions({ marked.setOptions({
...@@ -165,7 +168,7 @@ export default { ...@@ -165,7 +168,7 @@ export default {
this.$emit("update:textLength", this.textContent.length); this.$emit("update:textLength", this.textContent.length);
this.emitText(); this.emitText();
}, },
reSizeHeight() { reSizeTextareaHeight() {
const textEl = document.getElementById(this.id); const textEl = document.getElementById(this.id);
if (!textEl) return; if (!textEl) return;
const fontSize = getComputedStyle(textEl).getPropertyValue("font-size"); const fontSize = getComputedStyle(textEl).getPropertyValue("font-size");
......
...@@ -205,10 +205,21 @@ export default { ...@@ -205,10 +205,21 @@ export default {
const startStr = " "; const startStr = " ";
const endStr = ""; const endStr = "";
const originalText = this.text; const originalText = this.text;
const selectionInfo = this.selectionInfo; const cursorPoint = getPosition(this.id);
console.log(cursorPoint);
const selectionInfo = {
selectionStart: cursorPoint,
selectionEnd: cursorPoint
};
const newText = formatText(originalText, selectionInfo, startStr, endStr); const newText = formatText(originalText, selectionInfo, startStr, endStr);
const len = newText.length - originalText.length; const len = newText.length - originalText.length;
// const len = 0; // const len = 0;
this.$emit("update:selectionInfo", {
selectorId: "",
selectionStart: cursorPoint.selectionStart + len,
selectionEnd: cursorPoint.selectionEnd + len
});
this.updateText(newText, len); this.updateText(newText, len);
}, },
setShowPreview(val) { setShowPreview(val) {
...@@ -222,8 +233,8 @@ export default { ...@@ -222,8 +233,8 @@ export default {
this.$emit("update:selectionInfo", { this.$emit("update:selectionInfo", {
selectorId: "", selectorId: "",
selectionStart: cursorPoint, selectionStart: "",
selectionEnd: cursorPoint selectionEnd: ""
}); });
console.log(cursorPoint); console.log(cursorPoint);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册