( targets: TypedSelection[], editStyle: EditStyle )
| 46 | } |
| 47 | |
| 48 | export default async function displayPendingEditDecorations( |
| 49 | targets: TypedSelection[], |
| 50 | editStyle: EditStyle |
| 51 | ) { |
| 52 | await runOnTargetsForEachEditor(targets, async (editor, selections) => { |
| 53 | editor.setDecorations( |
| 54 | editStyle.token, |
| 55 | selections |
| 56 | .filter((selection) => !useLineDecorations(selection)) |
| 57 | .map((selection) => selection.selection.selection) |
| 58 | ); |
| 59 | |
| 60 | editor.setDecorations( |
| 61 | editStyle.line, |
| 62 | selections |
| 63 | .filter((selection) => useLineDecorations(selection)) |
| 64 | .map((selection) => { |
| 65 | const { document } = selection.selection.editor; |
| 66 | const { start, end } = selection.selection.selection; |
| 67 | const startLine = document.lineAt(start); |
| 68 | const hasLeadingLine = |
| 69 | start.character === startLine.range.end.character; |
| 70 | if ( |
| 71 | end.character === 0 && |
| 72 | (!hasLeadingLine || start.character === 0) |
| 73 | ) { |
| 74 | // NB: We move end up one line because it is at beginning of |
| 75 | // next line |
| 76 | return selection.selection.selection.with({ |
| 77 | end: end.translate(-1), |
| 78 | }); |
| 79 | } |
| 80 | if (hasLeadingLine) { |
| 81 | // NB: We move start down one line because it is at end of |
| 82 | // previous line |
| 83 | return selection.selection.selection.with({ |
| 84 | start: start.translate(1), |
| 85 | }); |
| 86 | } |
| 87 | return selection.selection.selection; |
| 88 | }) |
| 89 | ); |
| 90 | }); |
| 91 | |
| 92 | await decorationSleep(); |
| 93 | |
| 94 | await runOnTargetsForEachEditor(targets, async (editor) => { |
| 95 | editor.setDecorations(editStyle.token, []); |
| 96 | editor.setDecorations(editStyle.line, []); |
| 97 | }); |
| 98 | } |
| 99 | |
| 100 | function useLineDecorations(selection: TypedSelection) { |
| 101 | return ( |
no test coverage detected