md-editor-v3 4.16.5 → 4.16.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1311,6 +1311,26 @@ const scrollAuto = (pEle, cEle, codeMirrorUt) => {
1311
1311
  });
1312
1312
  }
1313
1313
  };
1314
+ const getLineNumber = (pMaxScrollLength, cMaxScrollLength) => {
1315
+ let lineNumer = 0;
1316
+ for (let i = elesHasLineNumber.length - 1; i - 1 >= 0; i--) {
1317
+ const curr = elesHasLineNumber[i];
1318
+ const sibling = elesHasLineNumber[i - 1];
1319
+ if (curr.offsetTop + curr.offsetHeight > cMaxScrollLength && sibling.offsetTop < cMaxScrollLength) {
1320
+ lineNumer = Number(sibling.dataset.line);
1321
+ break;
1322
+ }
1323
+ }
1324
+ for (let i = blockMap.length - 1; i >= 0; i--) {
1325
+ const itemBottom = getBottomByLine(blockMap[i].end);
1326
+ const itemTop = getTopByLine(blockMap[i].start);
1327
+ if (itemBottom > pMaxScrollLength && itemTop <= pMaxScrollLength) {
1328
+ lineNumer = lineNumer < blockMap[i].start ? lineNumer : blockMap[i].start;
1329
+ break;
1330
+ }
1331
+ }
1332
+ return lineNumer;
1333
+ };
1314
1334
  let pLock = 0;
1315
1335
  let cLock = 0;
1316
1336
  const pEleHandler = () => {
@@ -1348,23 +1368,7 @@ const scrollAuto = (pEle, cEle, codeMirrorUt) => {
1348
1368
  }
1349
1369
  scale = (scrollDOM.scrollTop - startTop + getComputedStyleNum(view2.contentDOM, "padding-bottom")) / (endBottom - startTop);
1350
1370
  if (startTop > 0 && (endBottom >= pMaxScrollLength || endEle.offsetTop + endEle.clientHeight > cMaxScrollLength)) {
1351
- let lineNumer = 0;
1352
- for (let i = elesHasLineNumber.length - 1; i >= 0; i--) {
1353
- const curr = elesHasLineNumber[i];
1354
- const sibling = elesHasLineNumber[i].previousElementSibling;
1355
- if (curr.offsetTop + curr.offsetHeight > cMaxScrollLength && sibling.offsetTop < cMaxScrollLength) {
1356
- lineNumer = Number(sibling.dataset.line);
1357
- break;
1358
- }
1359
- }
1360
- for (let i = blockMap.length - 1; i >= 0; i--) {
1361
- const itemBottom = getBottomByLine(blockMap[i].end);
1362
- const itemTop = getTopByLine(blockMap[i].start);
1363
- if (itemBottom > pMaxScrollLength && itemTop <= pMaxScrollLength) {
1364
- lineNumer = lineNumer < blockMap[i].start ? lineNumer : blockMap[i].start;
1365
- break;
1366
- }
1367
- }
1371
+ const lineNumer = getLineNumber(pMaxScrollLength, cMaxScrollLength);
1368
1372
  startTop = getTopByLine(lineNumer);
1369
1373
  scale = (scrollDOM.scrollTop - startTop) / (pMaxScrollLength - startTop);
1370
1374
  startEleOffetTop = (_c = document.querySelector(`[data-line="${lineNumer}"]`)) == null ? void 0 : _c.offsetTop;
@@ -1376,7 +1380,7 @@ const scrollAuto = (pEle, cEle, codeMirrorUt) => {
1376
1380
  });
1377
1381
  };
1378
1382
  const cEleHandler = () => {
1379
- var _a, _b, _c, _d, _e, _f;
1383
+ var _a, _b, _c, _d, _e, _f, _g;
1380
1384
  if (pLock !== 0) {
1381
1385
  return;
1382
1386
  }
@@ -1384,6 +1388,8 @@ const scrollAuto = (pEle, cEle, codeMirrorUt) => {
1384
1388
  const { scrollDOM } = view2;
1385
1389
  const cScrollTop = cEle.scrollTop;
1386
1390
  const cScrollHeight = cEle.scrollHeight;
1391
+ const pMaxScrollLength = scrollDOM.scrollHeight - scrollDOM.clientHeight;
1392
+ const cMaxScrollLength = cEle.scrollHeight - cEle.clientHeight;
1387
1393
  let realEleStart = (_a = cEle.firstElementChild) == null ? void 0 : _a.firstElementChild;
1388
1394
  let realEleEnd = (_b = cEle.firstElementChild) == null ? void 0 : _b.lastElementChild;
1389
1395
  if (startLines.length > 0) {
@@ -1430,19 +1436,24 @@ const scrollAuto = (pEle, cEle, codeMirrorUt) => {
1430
1436
  }
1431
1437
  }
1432
1438
  }
1433
- const eleStartOffsetTop = realEleStart === ((_e = cEle.firstElementChild) == null ? void 0 : _e.firstElementChild) ? 0 : realEleStart.offsetTop;
1439
+ let eleStartOffsetTop = realEleStart === ((_e = cEle.firstElementChild) == null ? void 0 : _e.firstElementChild) ? 0 : realEleStart.offsetTop;
1434
1440
  let eleEndOffsetTop = realEleEnd.offsetTop;
1435
1441
  let scale = 0;
1436
1442
  const { start, end } = blockMap[Number(realEleStart.dataset.line || 0)];
1437
- const firstLineScrollTop = getTopByLine(start);
1443
+ let firstLineScrollTop = getTopByLine(start);
1438
1444
  const endLineScrollTop = getTopByLine(
1439
1445
  end + 1 === view2.state.doc.lines ? end : end + 1
1440
1446
  );
1441
1447
  let blockHeight = 0;
1442
- if (endLineScrollTop > scrollDOM.scrollHeight - scrollDOM.clientHeight || realEleEnd.offsetTop + realEleEnd.offsetHeight > cEle.scrollHeight - cEle.clientHeight) {
1443
- scale = (cScrollTop - eleStartOffsetTop) / (cEle.scrollHeight - eleStartOffsetTop - cEle.clientHeight);
1444
- blockHeight = scrollDOM.scrollHeight - firstLineScrollTop - scrollDOM.clientHeight;
1445
- } else if (realEleStart === ((_f = cEle.firstElementChild) == null ? void 0 : _f.firstElementChild)) {
1448
+ if (endLineScrollTop > pMaxScrollLength || realEleEnd.offsetTop + realEleEnd.offsetHeight > cMaxScrollLength) {
1449
+ const lineNumer = getLineNumber(pMaxScrollLength, cMaxScrollLength);
1450
+ eleStartOffsetTop = (_f = document.querySelector(
1451
+ `[data-line="${lineNumer}"]`
1452
+ )) == null ? void 0 : _f.offsetTop;
1453
+ firstLineScrollTop = getTopByLine(lineNumer);
1454
+ scale = (cScrollTop - eleStartOffsetTop) / (cMaxScrollLength - eleStartOffsetTop);
1455
+ blockHeight = pMaxScrollLength - firstLineScrollTop;
1456
+ } else if (realEleStart === ((_g = cEle.firstElementChild) == null ? void 0 : _g.firstElementChild)) {
1446
1457
  if (realEleStart === realEleEnd) {
1447
1458
  eleEndOffsetTop = realEleEnd.offsetTop + realEleEnd.offsetHeight + +getComputedStyle(realEleEnd).marginBottom.replace("px", "");
1448
1459
  blockHeight = endLineScrollTop;
@@ -1310,6 +1310,26 @@ const scrollAuto = (pEle, cEle, codeMirrorUt) => {
1310
1310
  });
1311
1311
  }
1312
1312
  };
1313
+ const getLineNumber = (pMaxScrollLength, cMaxScrollLength) => {
1314
+ let lineNumer = 0;
1315
+ for (let i = elesHasLineNumber.length - 1; i - 1 >= 0; i--) {
1316
+ const curr = elesHasLineNumber[i];
1317
+ const sibling = elesHasLineNumber[i - 1];
1318
+ if (curr.offsetTop + curr.offsetHeight > cMaxScrollLength && sibling.offsetTop < cMaxScrollLength) {
1319
+ lineNumer = Number(sibling.dataset.line);
1320
+ break;
1321
+ }
1322
+ }
1323
+ for (let i = blockMap.length - 1; i >= 0; i--) {
1324
+ const itemBottom = getBottomByLine(blockMap[i].end);
1325
+ const itemTop = getTopByLine(blockMap[i].start);
1326
+ if (itemBottom > pMaxScrollLength && itemTop <= pMaxScrollLength) {
1327
+ lineNumer = lineNumer < blockMap[i].start ? lineNumer : blockMap[i].start;
1328
+ break;
1329
+ }
1330
+ }
1331
+ return lineNumer;
1332
+ };
1313
1333
  let pLock = 0;
1314
1334
  let cLock = 0;
1315
1335
  const pEleHandler = () => {
@@ -1347,23 +1367,7 @@ const scrollAuto = (pEle, cEle, codeMirrorUt) => {
1347
1367
  }
1348
1368
  scale = (scrollDOM.scrollTop - startTop + getComputedStyleNum(view.contentDOM, "padding-bottom")) / (endBottom - startTop);
1349
1369
  if (startTop > 0 && (endBottom >= pMaxScrollLength || endEle.offsetTop + endEle.clientHeight > cMaxScrollLength)) {
1350
- let lineNumer = 0;
1351
- for (let i = elesHasLineNumber.length - 1; i >= 0; i--) {
1352
- const curr = elesHasLineNumber[i];
1353
- const sibling = elesHasLineNumber[i].previousElementSibling;
1354
- if (curr.offsetTop + curr.offsetHeight > cMaxScrollLength && sibling.offsetTop < cMaxScrollLength) {
1355
- lineNumer = Number(sibling.dataset.line);
1356
- break;
1357
- }
1358
- }
1359
- for (let i = blockMap.length - 1; i >= 0; i--) {
1360
- const itemBottom = getBottomByLine(blockMap[i].end);
1361
- const itemTop = getTopByLine(blockMap[i].start);
1362
- if (itemBottom > pMaxScrollLength && itemTop <= pMaxScrollLength) {
1363
- lineNumer = lineNumer < blockMap[i].start ? lineNumer : blockMap[i].start;
1364
- break;
1365
- }
1366
- }
1370
+ const lineNumer = getLineNumber(pMaxScrollLength, cMaxScrollLength);
1367
1371
  startTop = getTopByLine(lineNumer);
1368
1372
  scale = (scrollDOM.scrollTop - startTop) / (pMaxScrollLength - startTop);
1369
1373
  startEleOffetTop = (_c = document.querySelector(`[data-line="${lineNumer}"]`)) == null ? void 0 : _c.offsetTop;
@@ -1375,7 +1379,7 @@ const scrollAuto = (pEle, cEle, codeMirrorUt) => {
1375
1379
  });
1376
1380
  };
1377
1381
  const cEleHandler = () => {
1378
- var _a, _b, _c, _d, _e, _f;
1382
+ var _a, _b, _c, _d, _e, _f, _g;
1379
1383
  if (pLock !== 0) {
1380
1384
  return;
1381
1385
  }
@@ -1383,6 +1387,8 @@ const scrollAuto = (pEle, cEle, codeMirrorUt) => {
1383
1387
  const { scrollDOM } = view;
1384
1388
  const cScrollTop = cEle.scrollTop;
1385
1389
  const cScrollHeight = cEle.scrollHeight;
1390
+ const pMaxScrollLength = scrollDOM.scrollHeight - scrollDOM.clientHeight;
1391
+ const cMaxScrollLength = cEle.scrollHeight - cEle.clientHeight;
1386
1392
  let realEleStart = (_a = cEle.firstElementChild) == null ? void 0 : _a.firstElementChild;
1387
1393
  let realEleEnd = (_b = cEle.firstElementChild) == null ? void 0 : _b.lastElementChild;
1388
1394
  if (startLines.length > 0) {
@@ -1429,19 +1435,24 @@ const scrollAuto = (pEle, cEle, codeMirrorUt) => {
1429
1435
  }
1430
1436
  }
1431
1437
  }
1432
- const eleStartOffsetTop = realEleStart === ((_e = cEle.firstElementChild) == null ? void 0 : _e.firstElementChild) ? 0 : realEleStart.offsetTop;
1438
+ let eleStartOffsetTop = realEleStart === ((_e = cEle.firstElementChild) == null ? void 0 : _e.firstElementChild) ? 0 : realEleStart.offsetTop;
1433
1439
  let eleEndOffsetTop = realEleEnd.offsetTop;
1434
1440
  let scale = 0;
1435
1441
  const { start, end } = blockMap[Number(realEleStart.dataset.line || 0)];
1436
- const firstLineScrollTop = getTopByLine(start);
1442
+ let firstLineScrollTop = getTopByLine(start);
1437
1443
  const endLineScrollTop = getTopByLine(
1438
1444
  end + 1 === view.state.doc.lines ? end : end + 1
1439
1445
  );
1440
1446
  let blockHeight = 0;
1441
- if (endLineScrollTop > scrollDOM.scrollHeight - scrollDOM.clientHeight || realEleEnd.offsetTop + realEleEnd.offsetHeight > cEle.scrollHeight - cEle.clientHeight) {
1442
- scale = (cScrollTop - eleStartOffsetTop) / (cEle.scrollHeight - eleStartOffsetTop - cEle.clientHeight);
1443
- blockHeight = scrollDOM.scrollHeight - firstLineScrollTop - scrollDOM.clientHeight;
1444
- } else if (realEleStart === ((_f = cEle.firstElementChild) == null ? void 0 : _f.firstElementChild)) {
1447
+ if (endLineScrollTop > pMaxScrollLength || realEleEnd.offsetTop + realEleEnd.offsetHeight > cMaxScrollLength) {
1448
+ const lineNumer = getLineNumber(pMaxScrollLength, cMaxScrollLength);
1449
+ eleStartOffsetTop = (_f = document.querySelector(
1450
+ `[data-line="${lineNumer}"]`
1451
+ )) == null ? void 0 : _f.offsetTop;
1452
+ firstLineScrollTop = getTopByLine(lineNumer);
1453
+ scale = (cScrollTop - eleStartOffsetTop) / (cMaxScrollLength - eleStartOffsetTop);
1454
+ blockHeight = pMaxScrollLength - firstLineScrollTop;
1455
+ } else if (realEleStart === ((_g = cEle.firstElementChild) == null ? void 0 : _g.firstElementChild)) {
1445
1456
  if (realEleStart === realEleEnd) {
1446
1457
  eleEndOffsetTop = realEleEnd.offsetTop + realEleEnd.offsetHeight + +getComputedStyle(realEleEnd).marginBottom.replace("px", "");
1447
1458
  blockHeight = endLineScrollTop;