MCPcopy Create free account
hub / github.com/AnukarOP/claude-code-leaked / getOperatorRange

Function getOperatorRange

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

Source from the content-addressed store, hash-verified

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