MCPcopy Create free account
hub / github.com/cursorless-dev/cursorless / getTokenComparator

Function getTokenComparator

src/util/getTokenComparator.ts:9–35  ·  view source on GitHub ↗
(
  selectionDisplayLine: number,
  selectionCharacterIndex: number
)

Source from the content-addressed store, hash-verified

7 * @param selectionCharacterIndex The character index of current cursor within line
8 */
9export function getTokenComparator(
10 selectionDisplayLine: number,
11 selectionCharacterIndex: number
12): (a: Token, b: Token) => number {
13 return (token1, token2) => {
14 const token1LineDiff = Math.abs(token1.displayLine - selectionDisplayLine);
15 const token2LineDiff = Math.abs(token2.displayLine - selectionDisplayLine);
16
17 if (token1LineDiff < token2LineDiff) {
18 return -1;
19 }
20
21 if (token1LineDiff > token2LineDiff) {
22 return 1;
23 }
24
25 const token1CharacterDiff = Math.abs(
26 token1.range.start.character - selectionCharacterIndex
27 );
28
29 const token2CharacterDiff = Math.abs(
30 token2.range.start.character - selectionCharacterIndex
31 );
32
33 return token1CharacterDiff - token2CharacterDiff;
34 };
35}

Callers 1

addDecorationsToEditorsFunction · 0.90

Calls

no outgoing calls

Tested by

no test coverage detected