(type: Type, direction: Direction, edge: Edge, position: Position)
| 144 | * With this information one can determine all of the required motions |
| 145 | */ |
| 146 | find(type: Type, direction: Direction, edge: Edge, position: Position): Position | undefined { |
| 147 | // Choose the ordering method name based on direction |
| 148 | const isDirection = direction === 'next' ? 'isAfter' : 'isBefore'; |
| 149 | |
| 150 | // Filter function for all elements whose "edge" is in the correct "direction" |
| 151 | // relative to the cursor's position, excluding the current function for prev direction |
| 152 | const dir = (element: StructureElement) => { |
| 153 | const pos = element[edge]; |
| 154 | return direction === 'next' ? pos.isAfter(position) : pos.line < position.line; // For prev, we want strictly before |
| 155 | }; |
| 156 | |
| 157 | // Filter out elements from structure based on type and direction |
| 158 | const elements = this.structure.filter((elem) => elem.type === type).filter(dir); |
| 159 | |
| 160 | if (edge === 'end') { |
| 161 | // When moving to an 'end' the elements should be started by the end position |
| 162 | elements.sort((a, b) => a.end.line - b.end.line); |
| 163 | } |
| 164 | |
| 165 | // Return the first match if any exist |
| 166 | if (elements.length) { |
| 167 | // If direction === 'next' return the first element |
| 168 | // otherwise return the last element |
| 169 | const index = direction === 'next' ? 0 : elements.length - 1; |
| 170 | const element = elements[index]; |
| 171 | const pos = element[edge]; |
| 172 | |
| 173 | // execAction MUST return a fully realized Position object created using new |
| 174 | return pos; |
| 175 | } |
| 176 | |
| 177 | return undefined; |
| 178 | } |
| 179 | |
| 180 | // Use PythonDocument instance to move to specified class boundary |
| 181 | static moveClassBoundary( |
no outgoing calls