(...delimiters: string[])
| 112 | } |
| 113 | |
| 114 | export function selectWithLeadingDelimiter(...delimiters: string[]) { |
| 115 | return function (editor: TextEditor, node: SyntaxNode): SelectionWithContext { |
| 116 | const firstSibling = node.previousSibling; |
| 117 | const secondSibling = firstSibling?.previousSibling; |
| 118 | let leadingDelimiterRange; |
| 119 | if (firstSibling) { |
| 120 | if (delimiters.includes(firstSibling.type)) { |
| 121 | // Second sibling exists. Terminate before it. |
| 122 | if (secondSibling) { |
| 123 | leadingDelimiterRange = makeRangeFromPositions( |
| 124 | secondSibling.endPosition, |
| 125 | node.startPosition |
| 126 | ); |
| 127 | } |
| 128 | // First delimiter sibling exists. Terminate after it. |
| 129 | else { |
| 130 | leadingDelimiterRange = makeRangeFromPositions( |
| 131 | firstSibling.startPosition, |
| 132 | node.startPosition |
| 133 | ); |
| 134 | } |
| 135 | } |
| 136 | // First sibling exists but is not the delimiter we are looking for. Terminate before it. |
| 137 | else { |
| 138 | leadingDelimiterRange = makeRangeFromPositions( |
| 139 | firstSibling.endPosition, |
| 140 | node.startPosition |
| 141 | ); |
| 142 | } |
| 143 | } |
| 144 | return { |
| 145 | ...simpleSelectionExtractor(editor, node), |
| 146 | context: { |
| 147 | leadingDelimiterRange, |
| 148 | }, |
| 149 | }; |
| 150 | }; |
| 151 | } |
| 152 | |
| 153 | export function selectWithTrailingDelimiter(...delimiters: string[]) { |
| 154 | return function (editor: TextEditor, node: SyntaxNode): SelectionWithContext { |
no test coverage detected