From 0b2ac330c89f355017e839dd0e6bcb8202ac8c5c Mon Sep 17 00:00:00 2001 From: yutent Date: Tue, 19 Sep 2023 10:06:05 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96=E8=A1=A8=E6=A0=BC=E5=88=92?= =?UTF-8?q?=E9=80=89=E6=80=A7=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/editor/index.js | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/src/editor/index.js b/src/editor/index.js index 799fd52..9d72021 100644 --- a/src/editor/index.js +++ b/src/editor/index.js @@ -79,6 +79,10 @@ function getX(i) { return i % 9 } +function getIndex(x, y) { + return x + y * 9 +} + class Editor extends Component { static watches = ['value'] @@ -505,6 +509,11 @@ class Editor extends Component { this.restoreSelection() this.exec(ACTTION.image, link) this.saveSelection() + + // 修正插入的图片,宽度不得超出容器 + this.$refs.editor.querySelectorAll('img').forEach(_ => { + _.style.maxWidth = '100%' + }) } } }) @@ -662,6 +671,8 @@ class Editor extends Component { let idx = +ev.target.dataset.idx let x = getX(idx) let y = getY(idx) + // 避免每次遍历完所有的节点 + let max = Math.max(getIndex(this.#gridx, this.#gridy), idx) + 1 if (x === this.#gridx && y === this.#gridy) { return @@ -669,7 +680,7 @@ class Editor extends Component { this.#gridx = x this.#gridy = y - for (let i = 0; i < grids.length; i++) { + for (let i = 0; i < max; i++) { let _x = getX(i) let _y = getY(i) grids[i].classList.toggle('active', _x <= x && _y <= y)