( document: TextDocument, selection: Selection, rangeBehavior: DecorationRangeBehavior )
| 25 | * @returns An object that can be used for selection tracking |
| 26 | */ |
| 27 | export function getSelectionInfo( |
| 28 | document: TextDocument, |
| 29 | selection: Selection, |
| 30 | rangeBehavior: DecorationRangeBehavior |
| 31 | ): FullSelectionInfo { |
| 32 | return { |
| 33 | range: new Range(selection.start, selection.end), |
| 34 | isForward: isForward(selection), |
| 35 | expansionBehavior: { |
| 36 | start: { |
| 37 | type: |
| 38 | rangeBehavior === DecorationRangeBehavior.ClosedClosed || |
| 39 | rangeBehavior === DecorationRangeBehavior.ClosedOpen |
| 40 | ? "closed" |
| 41 | : "open", |
| 42 | }, |
| 43 | end: { |
| 44 | type: |
| 45 | rangeBehavior === DecorationRangeBehavior.ClosedClosed || |
| 46 | rangeBehavior === DecorationRangeBehavior.OpenClosed |
| 47 | ? "closed" |
| 48 | : "open", |
| 49 | }, |
| 50 | }, |
| 51 | offsets: { |
| 52 | start: document.offsetAt(selection.start), |
| 53 | end: document.offsetAt(selection.end), |
| 54 | }, |
| 55 | text: document.getText(selection), |
| 56 | }; |
| 57 | } |
| 58 | |
| 59 | /** |
| 60 | * Creates SelectionInfo objects for all selections in a list of lists. |
no test coverage detected