| 22 | }; |
| 23 | |
| 24 | export async function takeSnapshot( |
| 25 | thatMark: ThatMark, |
| 26 | sourceMark: ThatMark, |
| 27 | excludeFields: string[] = [], |
| 28 | marks?: SerializedMarks |
| 29 | ) { |
| 30 | const activeEditor = vscode.window.activeTextEditor!; |
| 31 | |
| 32 | const snapshot: TestCaseSnapshot = { |
| 33 | documentContents: activeEditor.document.getText(), |
| 34 | selections: activeEditor.selections.map(selectionToPlainObject), |
| 35 | }; |
| 36 | |
| 37 | if (marks != null) { |
| 38 | snapshot.marks = marks; |
| 39 | } |
| 40 | |
| 41 | if (!excludeFields.includes("clipboard")) { |
| 42 | snapshot.clipboard = await Clipboard.readText(); |
| 43 | } |
| 44 | |
| 45 | if (!excludeFields.includes("visibleRanges")) { |
| 46 | snapshot.visibleRanges = activeEditor.visibleRanges.map(rangeToPlainObject); |
| 47 | } |
| 48 | |
| 49 | if (thatMark.exists() && !excludeFields.includes("thatMark")) { |
| 50 | snapshot.thatMark = thatMark |
| 51 | .get() |
| 52 | .map((mark) => selectionToPlainObject(mark.selection)); |
| 53 | } |
| 54 | |
| 55 | if (sourceMark.exists() && !excludeFields.includes("sourceMark")) { |
| 56 | snapshot.sourceMark = sourceMark |
| 57 | .get() |
| 58 | .map((mark) => selectionToPlainObject(mark.selection)); |
| 59 | } |
| 60 | |
| 61 | return snapshot; |
| 62 | } |