( cursor: Cursor, target: Cursor, motion: string, op: Operator, count: number, )
| 427 | } |
| 428 | |
| 429 | function getOperatorRange( |
| 430 | cursor: Cursor, |
| 431 | target: Cursor, |
| 432 | motion: string, |
| 433 | op: Operator, |
| 434 | count: number, |
| 435 | ): { from: number; to: number; linewise: boolean } { |
| 436 | let from = Math.min(cursor.offset, target.offset) |
| 437 | let to = Math.max(cursor.offset, target.offset) |
| 438 | let linewise = false |
| 439 | |
| 440 | // Special case: cw/cW changes to end of word, not start of next word |
| 441 | if (op === 'change' && (motion === 'w' || motion === 'W')) { |
| 442 | // For cw with count, move forward (count-1) words, then find end of that word |
| 443 | let wordCursor = cursor |
| 444 | for (let i = 0; i < count - 1; i++) { |
| 445 | wordCursor = |
| 446 | motion === 'w' ? wordCursor.nextVimWord() : wordCursor.nextWORD() |
| 447 | } |
| 448 | const wordEnd = |
| 449 | motion === 'w' ? wordCursor.endOfVimWord() : wordCursor.endOfWORD() |
| 450 | to = cursor.measuredText.nextOffset(wordEnd.offset) |
| 451 | } else if (isLinewiseMotion(motion)) { |
| 452 | // Linewise motions extend to include entire lines |
| 453 | linewise = true |
| 454 | const text = cursor.text |
| 455 | const nextNewline = text.indexOf('\n', to) |
| 456 | if (nextNewline === -1) { |
| 457 | // Deleting to end of file - include the preceding newline if exists |
| 458 | to = text.length |
| 459 | if (from > 0 && text[from - 1] === '\n') { |
| 460 | from -= 1 |
| 461 | } |
| 462 | } else { |
| 463 | to = nextNewline + 1 |
| 464 | } |
| 465 | } else if (isInclusiveMotion(motion) && cursor.offset <= target.offset) { |
| 466 | to = cursor.measuredText.nextOffset(to) |
| 467 | } |
| 468 | |
| 469 | // Word motions can land inside an [Image #N] chip; extend the range to |
| 470 | // cover the whole chip so dw/cw/yw never leave a partial placeholder. |
| 471 | from = cursor.snapOutOfImageRef(from, 'start') |
| 472 | to = cursor.snapOutOfImageRef(to, 'end') |
| 473 | |
| 474 | return { from, to, linewise } |
| 475 | } |
| 476 | |
| 477 | /** |
| 478 | * Get the range for a find-based operator. |
no test coverage detected