md-editor-v3 5.2.1 → 5.2.3
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.
- package/lib/cjs/MdEditor.cjs +270 -263
- package/lib/es/MdEditor.mjs +270 -263
- package/lib/preview.css +1 -1
- package/lib/style.css +1 -1
- package/lib/types/MdEditor/layouts/Content/codemirror/index.d.ts +1 -6
- package/lib/types/MdEditor/utils/content-help.d.ts +22 -1
- package/lib/umd/index.js +94 -121
- package/package.json +2 -2
package/lib/cjs/MdEditor.cjs
CHANGED
|
@@ -1412,268 +1412,260 @@ const useAutoScroll = (props2, html, codeMirrorUt) => {
|
|
|
1412
1412
|
vue.onMounted(rebindEvent);
|
|
1413
1413
|
};
|
|
1414
1414
|
const directive2flag = async (direct, codeMirrorUt, params) => {
|
|
1415
|
-
|
|
1416
|
-
|
|
1417
|
-
let deviationStart = 0;
|
|
1418
|
-
let deviationEnd = 0;
|
|
1419
|
-
let select = true;
|
|
1420
|
-
let replaceAll = false;
|
|
1421
|
-
const selectedText = codeMirrorUt.getSelectedText();
|
|
1422
|
-
const mermaidTemplate = config.configOption.editorConfig.mermaidTemplate;
|
|
1423
|
-
if (/^h[1-6]{1}$/.test(direct)) {
|
|
1424
|
-
const pix = direct.replace(/^h(\d)/, (_, num) => {
|
|
1425
|
-
return new Array(Number(num)).fill("#", 0, num).join("");
|
|
1426
|
-
});
|
|
1427
|
-
targetValue = `${pix} ${selectedText}`;
|
|
1428
|
-
deviationStart = pix.length + 1;
|
|
1415
|
+
if (/^h[1-6]$/.test(direct)) {
|
|
1416
|
+
return handleHeading(direct, codeMirrorUt);
|
|
1429
1417
|
} else if (direct === "prettier") {
|
|
1430
|
-
|
|
1431
|
-
|
|
1432
|
-
|
|
1433
|
-
|
|
1434
|
-
|
|
1435
|
-
|
|
1436
|
-
|
|
1437
|
-
|
|
1438
|
-
|
|
1439
|
-
|
|
1440
|
-
|
|
1441
|
-
|
|
1442
|
-
|
|
1443
|
-
|
|
1444
|
-
|
|
1418
|
+
return await handlePrettier(codeMirrorUt, params);
|
|
1419
|
+
}
|
|
1420
|
+
switch (direct) {
|
|
1421
|
+
case "bold":
|
|
1422
|
+
case "underline":
|
|
1423
|
+
case "italic":
|
|
1424
|
+
case "strikeThrough":
|
|
1425
|
+
case "sub":
|
|
1426
|
+
case "sup":
|
|
1427
|
+
case "codeRow":
|
|
1428
|
+
case "katexInline":
|
|
1429
|
+
case "katexBlock": {
|
|
1430
|
+
return wrapText(direct, codeMirrorUt);
|
|
1431
|
+
}
|
|
1432
|
+
case "quote":
|
|
1433
|
+
case "orderedList":
|
|
1434
|
+
case "unorderedList":
|
|
1435
|
+
case "task": {
|
|
1436
|
+
return handleMultiLine(direct, codeMirrorUt);
|
|
1437
|
+
}
|
|
1438
|
+
case "code": {
|
|
1439
|
+
return handleCodeBlock(params, codeMirrorUt);
|
|
1440
|
+
}
|
|
1441
|
+
case "table": {
|
|
1442
|
+
return handleTable(params);
|
|
1443
|
+
}
|
|
1444
|
+
case "link": {
|
|
1445
|
+
return { text: `[${params.desc}](${params.url})`, options: { select: false } };
|
|
1446
|
+
}
|
|
1447
|
+
case "image": {
|
|
1448
|
+
return handleImage(params);
|
|
1449
|
+
}
|
|
1450
|
+
case "flow":
|
|
1451
|
+
case "sequence":
|
|
1452
|
+
case "gantt":
|
|
1453
|
+
case "class":
|
|
1454
|
+
case "state":
|
|
1455
|
+
case "pie":
|
|
1456
|
+
case "relationship":
|
|
1457
|
+
case "journey": {
|
|
1458
|
+
return handleMermaid(direct);
|
|
1459
|
+
}
|
|
1460
|
+
case "universal": {
|
|
1461
|
+
return handleUniversal(codeMirrorUt.getSelectedText(), params);
|
|
1462
|
+
}
|
|
1463
|
+
default: {
|
|
1464
|
+
return { text: "", options: {} };
|
|
1445
1465
|
}
|
|
1446
|
-
|
|
1447
|
-
|
|
1448
|
-
|
|
1449
|
-
|
|
1450
|
-
|
|
1451
|
-
|
|
1452
|
-
|
|
1453
|
-
|
|
1454
|
-
|
|
1455
|
-
|
|
1456
|
-
|
|
1457
|
-
|
|
1458
|
-
|
|
1459
|
-
|
|
1460
|
-
|
|
1461
|
-
|
|
1462
|
-
|
|
1463
|
-
|
|
1464
|
-
|
|
1465
|
-
|
|
1466
|
-
|
|
1467
|
-
|
|
1468
|
-
|
|
1469
|
-
|
|
1470
|
-
|
|
1471
|
-
|
|
1472
|
-
|
|
1473
|
-
|
|
1474
|
-
|
|
1475
|
-
|
|
1476
|
-
|
|
1477
|
-
|
|
1478
|
-
|
|
1479
|
-
|
|
1480
|
-
|
|
1481
|
-
|
|
1482
|
-
|
|
1483
|
-
|
|
1484
|
-
|
|
1485
|
-
|
|
1486
|
-
|
|
1487
|
-
|
|
1488
|
-
|
|
1489
|
-
|
|
1490
|
-
|
|
1491
|
-
|
|
1492
|
-
|
|
1493
|
-
|
|
1494
|
-
|
|
1495
|
-
|
|
1496
|
-
|
|
1497
|
-
|
|
1498
|
-
|
|
1499
|
-
|
|
1500
|
-
|
|
1501
|
-
|
|
1502
|
-
|
|
1503
|
-
|
|
1504
|
-
|
|
1505
|
-
|
|
1506
|
-
|
|
1507
|
-
|
|
1508
|
-
|
|
1509
|
-
|
|
1510
|
-
|
|
1511
|
-
|
|
1512
|
-
|
|
1513
|
-
|
|
1514
|
-
|
|
1515
|
-
|
|
1516
|
-
|
|
1517
|
-
|
|
1518
|
-
|
|
1519
|
-
|
|
1520
|
-
|
|
1521
|
-
|
|
1522
|
-
|
|
1523
|
-
|
|
1524
|
-
|
|
1525
|
-
|
|
1526
|
-
|
|
1527
|
-
|
|
1528
|
-
|
|
1529
|
-
|
|
1530
|
-
|
|
1531
|
-
|
|
1532
|
-
|
|
1533
|
-
|
|
1534
|
-
|
|
1535
|
-
|
|
1536
|
-
for (let col = 0; col <= y; col++) {
|
|
1537
|
-
targetValue += " content |";
|
|
1538
|
-
}
|
|
1539
|
-
}
|
|
1540
|
-
deviationStart = 2;
|
|
1541
|
-
deviationEnd = 5 - targetValue.length;
|
|
1542
|
-
break;
|
|
1543
|
-
}
|
|
1544
|
-
case "link": {
|
|
1545
|
-
const { desc, url } = params;
|
|
1546
|
-
targetValue = `[${desc}](${url})`;
|
|
1547
|
-
select = false;
|
|
1548
|
-
break;
|
|
1549
|
-
}
|
|
1550
|
-
case "image": {
|
|
1551
|
-
const { desc, url, urls } = params;
|
|
1552
|
-
if (urls instanceof Array) {
|
|
1553
|
-
targetValue = urls.reduce((pVal, _url) => {
|
|
1554
|
-
const {
|
|
1555
|
-
url: url2 = "",
|
|
1556
|
-
alt = "",
|
|
1557
|
-
title = ""
|
|
1558
|
-
} = typeof _url === "object" ? _url : { url: _url };
|
|
1559
|
-
return pVal + `
|
|
1560
|
-
`;
|
|
1561
|
-
}, "");
|
|
1562
|
-
} else {
|
|
1563
|
-
targetValue = `
|
|
1564
|
-
`;
|
|
1565
|
-
}
|
|
1566
|
-
select = false;
|
|
1567
|
-
break;
|
|
1568
|
-
}
|
|
1569
|
-
case "flow": {
|
|
1570
|
-
targetValue = `\`\`\`mermaid
|
|
1571
|
-
${(mermaidTemplate == null ? void 0 : mermaidTemplate.flow) || "flowchart TD \n Start --> Stop"}
|
|
1572
|
-
\`\`\`
|
|
1573
|
-
`;
|
|
1574
|
-
deviationStart = 11;
|
|
1575
|
-
deviationEnd = -5;
|
|
1576
|
-
break;
|
|
1577
|
-
}
|
|
1578
|
-
case "sequence": {
|
|
1579
|
-
targetValue = `\`\`\`mermaid
|
|
1580
|
-
${(mermaidTemplate == null ? void 0 : mermaidTemplate.sequence) || "sequenceDiagram\n A->>B: hello!\n B-->>A: hi!\n A-)B: bye!"}
|
|
1581
|
-
\`\`\`
|
|
1582
|
-
`;
|
|
1583
|
-
deviationStart = 11;
|
|
1584
|
-
deviationEnd = -5;
|
|
1585
|
-
break;
|
|
1586
|
-
}
|
|
1587
|
-
case "gantt": {
|
|
1588
|
-
targetValue = `\`\`\`mermaid
|
|
1589
|
-
${(mermaidTemplate == null ? void 0 : mermaidTemplate.gantt) || "gantt\ntitle A Gantt Diagram\ndateFormat YYYY-MM-DD\nsection Section\nA task :a1, 2014-01-01, 30d\nAnother task :after a1, 20d"}
|
|
1590
|
-
\`\`\`
|
|
1591
|
-
`;
|
|
1592
|
-
deviationStart = 11;
|
|
1593
|
-
deviationEnd = -5;
|
|
1594
|
-
break;
|
|
1595
|
-
}
|
|
1596
|
-
case "class": {
|
|
1597
|
-
targetValue = `\`\`\`mermaid
|
|
1598
|
-
${(mermaidTemplate == null ? void 0 : mermaidTemplate.class) || "classDiagram\n class Animal\n Vehicle <|-- Car"}
|
|
1599
|
-
\`\`\`
|
|
1600
|
-
`;
|
|
1601
|
-
deviationStart = 11;
|
|
1602
|
-
deviationEnd = -5;
|
|
1603
|
-
break;
|
|
1604
|
-
}
|
|
1605
|
-
case "state": {
|
|
1606
|
-
targetValue = `\`\`\`mermaid
|
|
1607
|
-
${(mermaidTemplate == null ? void 0 : mermaidTemplate.state) || "stateDiagram-v2\n s1 --> s2"}
|
|
1608
|
-
\`\`\`
|
|
1609
|
-
`;
|
|
1610
|
-
deviationStart = 11;
|
|
1611
|
-
deviationEnd = -5;
|
|
1612
|
-
break;
|
|
1613
|
-
}
|
|
1614
|
-
case "pie": {
|
|
1615
|
-
targetValue = `\`\`\`mermaid
|
|
1616
|
-
${(mermaidTemplate == null ? void 0 : mermaidTemplate.pie) || 'pie title Pets adopted by volunteers\n "Dogs" : 386\n "Cats" : 85\n "Rats" : 15'}
|
|
1466
|
+
}
|
|
1467
|
+
};
|
|
1468
|
+
const handleHeading = (direct, codeMirrorUt) => {
|
|
1469
|
+
const level = direct.slice(1);
|
|
1470
|
+
const prefix = "#".repeat(Number(level));
|
|
1471
|
+
const [text, replaceStart, replaceEnd] = getSelectedInfo(codeMirrorUt, {
|
|
1472
|
+
wholeLine: true
|
|
1473
|
+
});
|
|
1474
|
+
return {
|
|
1475
|
+
text: `${prefix} ${text}`,
|
|
1476
|
+
options: { deviationStart: prefix.length + 1, replaceStart, replaceEnd }
|
|
1477
|
+
};
|
|
1478
|
+
};
|
|
1479
|
+
const handlePrettier = async (codeMirrorUt, params) => {
|
|
1480
|
+
var _a, _b, _c;
|
|
1481
|
+
const prettier = window.prettier || ((_a = config.configOption.editorExtensions.prettier) == null ? void 0 : _a.prettierInstance);
|
|
1482
|
+
const prettierPlugins = [
|
|
1483
|
+
((_b = window.prettierPlugins) == null ? void 0 : _b.markdown) || ((_c = config.configOption.editorExtensions.prettier) == null ? void 0 : _c.parserMarkdownInstance)
|
|
1484
|
+
];
|
|
1485
|
+
if (!prettier || !prettierPlugins[0]) {
|
|
1486
|
+
eventName.bus.emit(params.editorId, eventName.ERROR_CATCHER, {
|
|
1487
|
+
name: "prettier",
|
|
1488
|
+
message: "prettier is undefined"
|
|
1489
|
+
});
|
|
1490
|
+
return {
|
|
1491
|
+
text: codeMirrorUt.getValue(),
|
|
1492
|
+
options: { select: false, replaceAll: true }
|
|
1493
|
+
};
|
|
1494
|
+
}
|
|
1495
|
+
return {
|
|
1496
|
+
text: await prettier.format(codeMirrorUt.getValue(), {
|
|
1497
|
+
parser: "markdown",
|
|
1498
|
+
plugins: prettierPlugins
|
|
1499
|
+
}),
|
|
1500
|
+
options: { select: false, replaceAll: true }
|
|
1501
|
+
};
|
|
1502
|
+
};
|
|
1503
|
+
const wrappers = {
|
|
1504
|
+
bold: ["**", "**", 2, -2],
|
|
1505
|
+
underline: ["<u>", "</u>", 3, -4],
|
|
1506
|
+
italic: ["*", "*", 1, -1],
|
|
1507
|
+
strikeThrough: ["~~", "~~", 2, -2],
|
|
1508
|
+
sub: ["~", "~", 1, -1],
|
|
1509
|
+
sup: ["^", "^", 1, -1],
|
|
1510
|
+
codeRow: ["`", "`", 1, -1],
|
|
1511
|
+
katexInline: ["$", "$", 1, -1],
|
|
1512
|
+
katexBlock: ["\n$$\n", "\n$$\n", 4, -4]
|
|
1513
|
+
};
|
|
1514
|
+
const wrapText = (type, codeMirrorUt) => {
|
|
1515
|
+
const text = codeMirrorUt.getSelectedText();
|
|
1516
|
+
const [prefix, subfix, deviationStart, deviationEnd] = wrappers[type];
|
|
1517
|
+
return {
|
|
1518
|
+
text: `${prefix}${text}${subfix}`,
|
|
1519
|
+
options: {
|
|
1520
|
+
deviationStart,
|
|
1521
|
+
deviationEnd
|
|
1522
|
+
// replaceStart, replaceEnd
|
|
1523
|
+
}
|
|
1524
|
+
};
|
|
1525
|
+
};
|
|
1526
|
+
const keys = {
|
|
1527
|
+
quote: "> ",
|
|
1528
|
+
unorderedList: "- ",
|
|
1529
|
+
orderedList: 1,
|
|
1530
|
+
task: "- [ ] "
|
|
1531
|
+
};
|
|
1532
|
+
const handleMultiLine = (type, codeMirrorUt) => {
|
|
1533
|
+
const [text, replaceStart, replaceEnd] = getSelectedInfo(codeMirrorUt, {
|
|
1534
|
+
wholeLine: true
|
|
1535
|
+
});
|
|
1536
|
+
const lines = text.split("\n");
|
|
1537
|
+
const key = keys[type];
|
|
1538
|
+
const formattedLines = type === "orderedList" ? lines.map((line, i) => `${key + i}. ${line}`) : lines.map((line) => `${key}${line}`);
|
|
1539
|
+
const firstLinePrefix = type === "orderedList" ? "1. " : key.toString();
|
|
1540
|
+
const deviationStart = lines.length === 1 ? firstLinePrefix.length : 0;
|
|
1541
|
+
return {
|
|
1542
|
+
text: formattedLines.join("\n"),
|
|
1543
|
+
options: {
|
|
1544
|
+
deviationStart,
|
|
1545
|
+
replaceStart,
|
|
1546
|
+
replaceEnd
|
|
1547
|
+
}
|
|
1548
|
+
};
|
|
1549
|
+
};
|
|
1550
|
+
const handleCodeBlock = (params, codeMirrorUt) => {
|
|
1551
|
+
const [text, replaceStart, replaceEnd] = getSelectedInfo(codeMirrorUt);
|
|
1552
|
+
const mode = params.mode || "language";
|
|
1553
|
+
const _text = `
|
|
1554
|
+
\`\`\`${mode}
|
|
1555
|
+
${params.text || text || ""}
|
|
1617
1556
|
\`\`\`
|
|
1618
1557
|
`;
|
|
1619
|
-
|
|
1620
|
-
|
|
1621
|
-
|
|
1622
|
-
|
|
1623
|
-
|
|
1624
|
-
|
|
1625
|
-
|
|
1558
|
+
return {
|
|
1559
|
+
text: _text,
|
|
1560
|
+
options: {
|
|
1561
|
+
deviationStart: 4,
|
|
1562
|
+
deviationEnd: 4 + mode.length - _text.length,
|
|
1563
|
+
replaceStart,
|
|
1564
|
+
replaceEnd
|
|
1565
|
+
}
|
|
1566
|
+
};
|
|
1567
|
+
};
|
|
1568
|
+
const handleMermaid = (type) => {
|
|
1569
|
+
const mermaidTemplates = {
|
|
1570
|
+
flow: "flowchart TD \n Start --> Stop",
|
|
1571
|
+
sequence: "sequenceDiagram\n A->>B: hello!\n B-->>A: hi!",
|
|
1572
|
+
gantt: "gantt\ntitle Gantt Chart\ndateFormat YYYY-MM-DD",
|
|
1573
|
+
class: "classDiagram\n class Animal",
|
|
1574
|
+
state: "stateDiagram-v2\n s1 --> s2",
|
|
1575
|
+
pie: 'pie\n "Dogs" : 386\n "Cats" : 85\n "Rats" : 15',
|
|
1576
|
+
relationship: "erDiagram\n CAR ||--o{ NAMED-DRIVER : allows",
|
|
1577
|
+
journey: "journey\n title My Journey",
|
|
1578
|
+
...config.configOption.editorConfig.mermaidTemplate
|
|
1579
|
+
};
|
|
1580
|
+
return {
|
|
1581
|
+
text: `
|
|
1582
|
+
\`\`\`mermaid
|
|
1583
|
+
${mermaidTemplates[type]}
|
|
1626
1584
|
\`\`\`
|
|
1585
|
+
`,
|
|
1586
|
+
options: { deviationStart: 12, deviationEnd: -5 }
|
|
1587
|
+
};
|
|
1588
|
+
};
|
|
1589
|
+
const handleImage = (params) => {
|
|
1590
|
+
const { desc, url, urls } = params;
|
|
1591
|
+
let text = "";
|
|
1592
|
+
if (urls instanceof Array) {
|
|
1593
|
+
text = urls.reduce((pVal, _url) => {
|
|
1594
|
+
const {
|
|
1595
|
+
url: url2 = "",
|
|
1596
|
+
alt = "",
|
|
1597
|
+
title = ""
|
|
1598
|
+
} = typeof _url === "object" ? _url : { url: _url };
|
|
1599
|
+
return pVal + `
|
|
1627
1600
|
`;
|
|
1628
|
-
|
|
1629
|
-
|
|
1630
|
-
|
|
1631
|
-
}
|
|
1632
|
-
case "journey": {
|
|
1633
|
-
targetValue = `\`\`\`mermaid
|
|
1634
|
-
${(mermaidTemplate == null ? void 0 : mermaidTemplate.journey) || "journey\n title My working day\n section Go to work\n Make tea: 5: Me\n Go upstairs: 3: Me\n Do work: 1: Me, Cat\n section Go home\n Go downstairs: 5: Me\n Sit down: 5: Me"}
|
|
1635
|
-
\`\`\`
|
|
1601
|
+
}, "");
|
|
1602
|
+
} else {
|
|
1603
|
+
text = `
|
|
1636
1604
|
`;
|
|
1637
|
-
|
|
1638
|
-
|
|
1639
|
-
|
|
1640
|
-
|
|
1641
|
-
|
|
1642
|
-
|
|
1643
|
-
|
|
1644
|
-
|
|
1645
|
-
|
|
1646
|
-
|
|
1647
|
-
|
|
1648
|
-
|
|
1649
|
-
|
|
1650
|
-
|
|
1651
|
-
|
|
1652
|
-
|
|
1653
|
-
|
|
1654
|
-
|
|
1655
|
-
const insertOptions = generate(selectedText);
|
|
1656
|
-
targetValue = insertOptions.targetValue;
|
|
1657
|
-
select = insertOptions.select ?? true;
|
|
1658
|
-
deviationStart = insertOptions.deviationStart || 0;
|
|
1659
|
-
deviationEnd = insertOptions.deviationEnd || 0;
|
|
1660
|
-
}
|
|
1605
|
+
}
|
|
1606
|
+
return { text, options: { select: false } };
|
|
1607
|
+
};
|
|
1608
|
+
const handleTable = (params) => {
|
|
1609
|
+
const { selectedShape = { x: 1, y: 1 } } = params;
|
|
1610
|
+
const { x, y } = selectedShape;
|
|
1611
|
+
let text = "\n| Column";
|
|
1612
|
+
for (let i = 0; i <= y; i++) {
|
|
1613
|
+
text += ` |`;
|
|
1614
|
+
}
|
|
1615
|
+
text += "\n|";
|
|
1616
|
+
for (let i = 0; i <= y; i++) {
|
|
1617
|
+
text += " - |";
|
|
1618
|
+
}
|
|
1619
|
+
for (let row = 0; row <= x; row++) {
|
|
1620
|
+
text += "\n|";
|
|
1621
|
+
for (let col = 0; col <= y; col++) {
|
|
1622
|
+
text += " |";
|
|
1661
1623
|
}
|
|
1662
1624
|
}
|
|
1625
|
+
text += "\n";
|
|
1663
1626
|
return {
|
|
1664
|
-
text
|
|
1627
|
+
text,
|
|
1665
1628
|
options: {
|
|
1666
|
-
|
|
1667
|
-
|
|
1668
|
-
|
|
1669
|
-
|
|
1670
|
-
|
|
1671
|
-
|
|
1672
|
-
|
|
1673
|
-
|
|
1629
|
+
deviationStart: 3,
|
|
1630
|
+
deviationEnd: 10 - text.length
|
|
1631
|
+
}
|
|
1632
|
+
};
|
|
1633
|
+
};
|
|
1634
|
+
const handleUniversal = (selectedText, params) => {
|
|
1635
|
+
const { generate } = params;
|
|
1636
|
+
const insertOptions = generate(selectedText);
|
|
1637
|
+
return {
|
|
1638
|
+
text: insertOptions.targetValue,
|
|
1639
|
+
options: {
|
|
1640
|
+
select: insertOptions.select ?? true,
|
|
1641
|
+
deviationStart: insertOptions.deviationStart || 0,
|
|
1642
|
+
deviationEnd: insertOptions.deviationEnd || 0
|
|
1674
1643
|
}
|
|
1675
1644
|
};
|
|
1676
1645
|
};
|
|
1646
|
+
const getSelectedInfo = (codeMirrorUt, options = {
|
|
1647
|
+
wholeLine: false
|
|
1648
|
+
}) => {
|
|
1649
|
+
const state2 = codeMirrorUt.view.state;
|
|
1650
|
+
const selection2 = state2.selection.main;
|
|
1651
|
+
if (selection2.empty) {
|
|
1652
|
+
const startLine = state2.doc.lineAt(selection2.from);
|
|
1653
|
+
return [state2.doc.lineAt(selection2.from).text, startLine.from, startLine.to];
|
|
1654
|
+
} else if (options.wholeLine) {
|
|
1655
|
+
const startLine = state2.doc.lineAt(selection2.from);
|
|
1656
|
+
const endLine = state2.doc.lineAt(selection2.to);
|
|
1657
|
+
return [
|
|
1658
|
+
state2.doc.sliceString(startLine.from, endLine.to),
|
|
1659
|
+
startLine.from,
|
|
1660
|
+
endLine.to
|
|
1661
|
+
];
|
|
1662
|
+
}
|
|
1663
|
+
return [
|
|
1664
|
+
state2.doc.sliceString(selection2.from, selection2.to),
|
|
1665
|
+
selection2.from,
|
|
1666
|
+
selection2.to
|
|
1667
|
+
];
|
|
1668
|
+
};
|
|
1677
1669
|
const chalky$1 = "#e5c07b", coral$1 = "var(--md-color)", cyan$1 = "#56b6c2", invalid$1 = "#ffffff", ivory$1 = "var(--md-color)", stone$1 = "#e5c07b", malibu$1 = "#e5c07b", sage$1 = "var(--md-color)", whiskey$1 = "#d19a66", violet$1 = "#c678dd", darkBackground$1 = "#21252b", highlightBackground$1 = "#2c313a", background$1 = "var(--md-bk-color)", tooltipBackground$1 = "var(--md-bk-color)", selection$1 = "#ceedfa33", cursor$1 = "#528bff";
|
|
1678
1670
|
const oneDarkTheme = view.EditorView.theme(
|
|
1679
1671
|
{
|
|
@@ -1780,7 +1772,7 @@ const oneDark = [
|
|
|
1780
1772
|
oneDarkTheme,
|
|
1781
1773
|
language.syntaxHighlighting(oneDarkHighlightStyle)
|
|
1782
1774
|
];
|
|
1783
|
-
const chalky = "#e5c07b", coral = "
|
|
1775
|
+
const chalky = "#e5c07b", coral = "var(--md-color)", cyan = "#56b6c2", invalid = "#fff", ivory = "#3f4a54", stone = "#2d8cf0", malibu = "#2d8cf0", sage = "#3f4a54", whiskey = "#d19a66", violet = "#c678dd", darkBackground = "#f6f6f6", highlightBackground = "#ceedfa33", background = "var(--md-bk-color)", tooltipBackground = "var(--md-bk-color)", selection = "#bad5fa", cursor = "#3f4a54";
|
|
1784
1776
|
const oneLightTheme = view.EditorView.theme(
|
|
1785
1777
|
{
|
|
1786
1778
|
"&": {
|
|
@@ -2081,16 +2073,22 @@ class CodeMirrorUt {
|
|
|
2081
2073
|
* @param text 待替换内容
|
|
2082
2074
|
* @param options 替换后是否选中
|
|
2083
2075
|
*/
|
|
2084
|
-
replaceSelectedText(text,
|
|
2085
|
-
|
|
2086
|
-
|
|
2087
|
-
|
|
2088
|
-
|
|
2089
|
-
|
|
2090
|
-
|
|
2091
|
-
|
|
2092
|
-
|
|
2093
|
-
|
|
2076
|
+
replaceSelectedText(text, _options, editorId) {
|
|
2077
|
+
const options = {
|
|
2078
|
+
// 是否选中
|
|
2079
|
+
select: true,
|
|
2080
|
+
// 选中时,开始位置的偏移量
|
|
2081
|
+
deviationStart: 0,
|
|
2082
|
+
// 结束的偏移量
|
|
2083
|
+
deviationEnd: 0,
|
|
2084
|
+
// 直接替换所有文本
|
|
2085
|
+
replaceAll: false,
|
|
2086
|
+
// 替换旧文本的开始位置
|
|
2087
|
+
replaceStart: -1,
|
|
2088
|
+
// 替换旧文本的结束位置
|
|
2089
|
+
replaceEnd: -1,
|
|
2090
|
+
..._options
|
|
2091
|
+
};
|
|
2094
2092
|
try {
|
|
2095
2093
|
if (options.replaceAll) {
|
|
2096
2094
|
this.setValue(text);
|
|
@@ -2103,13 +2101,22 @@ class CodeMirrorUt {
|
|
|
2103
2101
|
throw new Error("The input text is too long");
|
|
2104
2102
|
}
|
|
2105
2103
|
const { from } = this.view.state.selection.main;
|
|
2106
|
-
|
|
2104
|
+
if (options.replaceStart !== -1) {
|
|
2105
|
+
this.view.dispatch({
|
|
2106
|
+
changes: {
|
|
2107
|
+
from: options.replaceStart,
|
|
2108
|
+
to: options.replaceEnd,
|
|
2109
|
+
insert: text
|
|
2110
|
+
}
|
|
2111
|
+
});
|
|
2112
|
+
} else {
|
|
2113
|
+
this.view.dispatch(this.view.state.replaceSelection(text));
|
|
2114
|
+
}
|
|
2107
2115
|
if (options.select) {
|
|
2108
|
-
const to = from + text.length + options.deviationEnd;
|
|
2109
2116
|
this.view.dispatch({
|
|
2110
2117
|
selection: {
|
|
2111
|
-
anchor: from + options.deviationStart,
|
|
2112
|
-
head:
|
|
2118
|
+
anchor: options.replaceStart === -1 ? from + options.deviationStart : options.replaceStart + options.deviationStart,
|
|
2119
|
+
head: options.replaceStart === -1 ? from + text.length + options.deviationEnd : options.replaceStart + text.length + options.deviationEnd
|
|
2113
2120
|
}
|
|
2114
2121
|
});
|
|
2115
2122
|
}
|