|
@@ -1,3 +1,4 @@
|
|
|
|
|
+import { foldEffect } from '@codemirror/language';
|
|
|
import { EditorView } from '@codemirror/view';
|
|
import { EditorView } from '@codemirror/view';
|
|
|
|
|
|
|
|
const lineBeginPartOfDrawioRE = /^```(\s.*)drawio$/;
|
|
const lineBeginPartOfDrawioRE = /^```(\s.*)drawio$/;
|
|
@@ -115,6 +116,36 @@ export const getMarkdownDrawioMxfile = (editor: EditorView): string | null => {
|
|
|
return editor.state.sliceDoc(bodLine, eodLine);
|
|
return editor.state.sliceDoc(bodLine, eodLine);
|
|
|
};
|
|
};
|
|
|
|
|
|
|
|
|
|
+// /**
|
|
|
|
|
+// * return an array of the starting line numbers of the drawio sections found in markdown
|
|
|
|
|
+// */
|
|
|
|
|
+// const findAllDrawioSection = (editor: EditorView): number[] => {
|
|
|
|
|
+// const lineNumbers: number[] = [];
|
|
|
|
|
+// for (let i = firstLineNum, e = lastLineNum(editor); i <= e; i++) {
|
|
|
|
|
+// const lineTxt = getLine(editor, i).text;
|
|
|
|
|
+// const match = lineBeginPartOfDrawioRE.exec(lineTxt);
|
|
|
|
|
+// if (match) {
|
|
|
|
|
+// lineNumbers.push(i);
|
|
|
|
|
+// }
|
|
|
|
|
+// }
|
|
|
|
|
+// return lineNumbers;
|
|
|
|
|
+// };
|
|
|
|
|
+
|
|
|
|
|
+// // fold draw.io section (``` drawio ~ ```)
|
|
|
|
|
+// export const foldDrawioSection = (editor: EditorView): void => {
|
|
|
|
|
+// const lineNumbers = findAllDrawioSection(editor);
|
|
|
|
|
+// console.log(lineNumbers);
|
|
|
|
|
+// lineNumbers.forEach((lineNumber) => {
|
|
|
|
|
+// const from = getLine(editor, lineNumber).to;
|
|
|
|
|
+// const to = getLine(editor, lineNumber + 2).to;
|
|
|
|
|
+// editor.dispatch({
|
|
|
|
|
+// effects: foldEffect.of({
|
|
|
|
|
+// from, to,
|
|
|
|
|
+// }),
|
|
|
|
|
+// });
|
|
|
|
|
+// });
|
|
|
|
|
+// };
|
|
|
|
|
+
|
|
|
export const replaceFocusedDrawioWithEditor = (editor: EditorView, drawioData: string): void => {
|
|
export const replaceFocusedDrawioWithEditor = (editor: EditorView, drawioData: string): void => {
|
|
|
const drawioBlock = ['``` drawio', drawioData.toString(), '```'].join('\n');
|
|
const drawioBlock = ['``` drawio', drawioData.toString(), '```'].join('\n');
|
|
|
let bod = getBod(editor);
|
|
let bod = getBod(editor);
|
|
@@ -131,21 +162,5 @@ export const replaceFocusedDrawioWithEditor = (editor: EditorView, drawioData: s
|
|
|
insert: drawioBlock,
|
|
insert: drawioBlock,
|
|
|
},
|
|
},
|
|
|
});
|
|
});
|
|
|
|
|
+ // foldDrawioSection(editor);
|
|
|
};
|
|
};
|
|
|
-
|
|
|
|
|
-/**
|
|
|
|
|
- * return an array of the starting line numbers of the drawio sections found in markdown
|
|
|
|
|
- */
|
|
|
|
|
-// TODO: https://redmine.weseek.co.jp/issues/136473
|
|
|
|
|
-// export const findAllDrawioSection = (editor: EditorView): number[] => {
|
|
|
|
|
-// const lineNumbers: number[] = [];
|
|
|
|
|
-// // refs: https://github.com/codemirror/CodeMirror/blob/5.64.0/addon/fold/foldcode.js#L106-L111
|
|
|
|
|
-// for (let i = firstLineNum, e = lastLineNum(editor); i <= e; i++) {
|
|
|
|
|
-// const lineTxt = getLine(editor, i).text;
|
|
|
|
|
-// const match = lineBeginPartOfDrawioRE.exec(lineTxt);
|
|
|
|
|
-// if (match) {
|
|
|
|
|
-// lineNumbers.push(i);
|
|
|
|
|
-// }
|
|
|
|
|
-// }
|
|
|
|
|
-// return lineNumbers;
|
|
|
|
|
-// };
|
|
|