MCPcopy Index your code
hub / github.com/codeaashu/claude-code / getOperatorRange

Function getOperatorRange

src/vim/operators.ts:429–475  ·  view source on GitHub ↗
(
  cursor: Cursor,
  target: Cursor,
  motion: string,
  op: Operator,
  count: number,
)

Source from the content-addressed store, hash-verified

427}
428
429function 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.

Callers 3

executeOperatorMotionFunction · 0.85
executeOperatorGFunction · 0.85
executeOperatorGgFunction · 0.85

Calls 9

isLinewiseMotionFunction · 0.85
isInclusiveMotionFunction · 0.85
maxMethod · 0.80
nextVimWordMethod · 0.80
nextWORDMethod · 0.80
endOfVimWordMethod · 0.80
endOfWORDMethod · 0.80
nextOffsetMethod · 0.80
snapOutOfImageRefMethod · 0.80

Tested by

no test coverage detected