-
-
Notifications
You must be signed in to change notification settings - Fork 85
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
305 additions
and
115 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
56 changes: 56 additions & 0 deletions
56
packages/cursorless-vscode/src/ide/vscode/getDecorationRanges/borderStyles.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
import { Borders } from "./getDecorationRanges.types"; | ||
|
||
export const NONE: Borders = { | ||
top: false, | ||
right: false, | ||
bottom: false, | ||
left: false, | ||
}; | ||
export const TOP: Borders = { | ||
top: true, | ||
left: false, | ||
right: false, | ||
bottom: false, | ||
}; | ||
export const BOTTOM: Borders = { | ||
bottom: true, | ||
top: false, | ||
left: false, | ||
right: false, | ||
}; | ||
export const TOP_LEFT: Borders = { | ||
top: true, | ||
left: true, | ||
right: false, | ||
bottom: false, | ||
}; | ||
export const TOP_BOTTOM: Borders = { | ||
top: true, | ||
bottom: true, | ||
left: false, | ||
right: false, | ||
}; | ||
export const BOTTOM_RIGHT: Borders = { | ||
bottom: true, | ||
right: true, | ||
top: false, | ||
left: false, | ||
}; | ||
export const TOP_BOTTOM_LEFT: Borders = { | ||
top: true, | ||
bottom: true, | ||
left: true, | ||
right: false, | ||
}; | ||
export const TOP_BOTTOM_RIGHT: Borders = { | ||
top: true, | ||
bottom: true, | ||
right: true, | ||
left: false, | ||
}; | ||
export const FULL: Borders = { | ||
top: true, | ||
right: true, | ||
bottom: true, | ||
left: true, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
63 changes: 63 additions & 0 deletions
63
packages/cursorless-vscode/src/ide/vscode/getDecorationRanges/handleManyLines.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
import { Range } from "@cursorless/common"; | ||
import { DecoratedRange } from "./getDecorationRanges.types"; | ||
import { BOTTOM, BOTTOM_RIGHT, NONE, TOP, TOP_LEFT } from "./borderStyles"; | ||
import { singleLineRange } from "./singleLineRange"; | ||
|
||
export function* handleManyLines( | ||
lineRanges: Range[], | ||
): Iterable<DecoratedRange> { | ||
const [firstLine, secondLine, ...lastLines] = lineRanges; | ||
const secondLastLine = lastLines[lastLines.length - 2]; | ||
const lastLine = lastLines[lastLines.length - 1]; | ||
const { | ||
start: { character: firstLineStart }, | ||
} = firstLine; | ||
const { | ||
start: { line: secondLineNumber }, | ||
} = secondLine; | ||
const { | ||
start: { line: secondLastLineNumber }, | ||
end: { character: secondLastLineEnd }, | ||
} = secondLastLine; | ||
const { | ||
end: { character: lastLineEnd }, | ||
} = lastLine; | ||
|
||
yield { | ||
range: firstLine, | ||
style: TOP_LEFT, | ||
}; | ||
|
||
if (firstLineStart > 0) { | ||
yield { | ||
range: singleLineRange(secondLineNumber, 0, firstLineStart), | ||
style: TOP, | ||
}; | ||
} | ||
|
||
yield { | ||
range: new Range( | ||
secondLineNumber, | ||
firstLineStart, | ||
secondLastLineNumber, | ||
Math.min(secondLastLineEnd, lastLineEnd), | ||
), | ||
style: NONE, | ||
}; | ||
|
||
if (secondLastLineEnd > lastLineEnd) { | ||
yield { | ||
range: singleLineRange( | ||
secondLastLineNumber, | ||
lastLineEnd, | ||
secondLastLineEnd, | ||
), | ||
style: BOTTOM, | ||
}; | ||
} | ||
|
||
yield { | ||
range: lastLine, | ||
style: BOTTOM_RIGHT, | ||
}; | ||
} |
97 changes: 97 additions & 0 deletions
97
packages/cursorless-vscode/src/ide/vscode/getDecorationRanges/handleThreeLines.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,97 @@ | ||
import { Range } from "@cursorless/common"; | ||
import { Borders, DecoratedRange } from "./getDecorationRanges.types"; | ||
import { TOP_LEFT, BOTTOM_RIGHT, TOP } from "./borderStyles"; | ||
import { singleLineRange } from "./singleLineRange"; | ||
|
||
export function* handleThreeLines( | ||
lineRanges: Range[], | ||
): Iterable<DecoratedRange> { | ||
const [firstLine, secondLine, thirdLine] = lineRanges; | ||
const { | ||
start: { character: firstLineStart }, | ||
} = firstLine; | ||
const { | ||
start: { line: secondLineNumber }, | ||
end: { character: secondLineEnd }, | ||
} = secondLine; | ||
const { | ||
end: { character: thirdLineEnd }, | ||
} = thirdLine; | ||
|
||
yield { | ||
range: firstLine, | ||
style: TOP_LEFT, | ||
}; | ||
|
||
yield* handleSecondLine( | ||
secondLineNumber, | ||
firstLineStart, | ||
secondLineEnd, | ||
thirdLineEnd, | ||
); | ||
|
||
yield { | ||
range: thirdLine, | ||
style: BOTTOM_RIGHT, | ||
}; | ||
} | ||
|
||
function* handleSecondLine( | ||
secondLineNumber: number, | ||
firstLineStart: number, | ||
secondLineEnd: number, | ||
thirdLineEnd: number, | ||
): Iterable<DecoratedRange> { | ||
let currentDecoration: Borders = TOP; | ||
let currentOffset = 0; | ||
|
||
const events: Event[] = [ | ||
{ | ||
offset: firstLineStart, | ||
type: EventType.firstLineStart, | ||
}, | ||
{ | ||
offset: secondLineEnd, | ||
type: EventType.secondLineEnd, | ||
}, | ||
{ | ||
offset: thirdLineEnd, | ||
type: EventType.thirdLineEnd, | ||
}, | ||
]; | ||
|
||
events.sort((a, b) => a.offset - b.offset); | ||
|
||
for (const { offset, type } of events) { | ||
if (offset > currentOffset) { | ||
yield { | ||
range: singleLineRange(secondLineNumber, currentOffset, offset), | ||
style: currentDecoration, | ||
}; | ||
} | ||
|
||
switch (type) { | ||
case EventType.firstLineStart: | ||
currentDecoration = { ...currentDecoration, top: false }; | ||
break; | ||
case EventType.secondLineEnd: | ||
return; | ||
case EventType.thirdLineEnd: | ||
currentDecoration = { ...currentDecoration, bottom: true }; | ||
break; | ||
} | ||
|
||
currentOffset = offset; | ||
} | ||
} | ||
|
||
interface Event { | ||
offset: number; | ||
type: EventType; | ||
} | ||
|
||
enum EventType { | ||
firstLineStart, | ||
secondLineEnd, | ||
thirdLineEnd, | ||
} |
Oops, something went wrong.