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)