优化表格划选性能

master
yutent 2023-09-19 10:06:05 +08:00
parent d5e8ddb613
commit 0b2ac330c8
1 changed files with 12 additions and 1 deletions

View File

@ -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)