1- import { PlainTarget } from "../processTargets/targets" ;
1+ import { Range } from "@cursorless/common" ;
2+ import {
3+ FlashDescriptor ,
4+ FlashStyle ,
5+ } from "../libs/common/ide/types/FlashDescriptor" ;
6+ import {
7+ toCharacterRange ,
8+ toLineRange ,
9+ } from "../libs/common/types/GeneralizedRange" ;
10+ import ide from "../libs/cursorless-engine/singletons/ide.singleton" ;
211import { Target } from "../typings/target.types" ;
312import { Graph } from "../typings/Types" ;
4- import { getOutsideOverflow } from "../util/targetUtils" ;
513import { Action , ActionReturnValue } from "./actions.types" ;
614
715export class CutToClipboard implements Action {
@@ -10,32 +18,42 @@ export class CutToClipboard implements Action {
1018 }
1119
1220 async run ( [ targets ] : [ Target [ ] ] ) : Promise < ActionReturnValue > {
13- const overflowTargets = targets . flatMap ( ( target ) => {
14- const range = target . getRemovalHighlightRange ( ) ;
15- if ( range == null ) {
16- return [ ] ;
17- }
18- return getOutsideOverflow ( target . editor , target . contentRange , range ) . map (
19- ( overflow ) : Target =>
20- // TODO Instead of creating a new target display decorations by range
21- new PlainTarget ( {
22- editor : target . editor ,
23- contentRange : overflow ,
24- isReversed : target . isReversed ,
25- } ) ,
26- ) ;
27- } ) ;
28-
29- await Promise . all ( [
30- this . graph . editStyles . displayPendingEditDecorations (
31- targets ,
32- this . graph . editStyles . referenced ,
33- ) ,
34- this . graph . editStyles . displayPendingEditDecorations (
35- overflowTargets ,
36- this . graph . editStyles . pendingDelete ,
37- ) ,
38- ] ) ;
21+ await ide ( ) . flashRanges (
22+ targets . flatMap ( ( target ) => {
23+ const { editor, contentRange } = target ;
24+ const removalHighlightRange = target . getRemovalHighlightRange ( ) ;
25+
26+ if ( target . isLine ) {
27+ return [
28+ {
29+ editor,
30+ range : toCharacterRange ( contentRange ) ,
31+ style : FlashStyle . referenced ,
32+ } ,
33+ {
34+ editor,
35+ range : toLineRange ( removalHighlightRange ) ,
36+ style : FlashStyle . pendingDelete ,
37+ } ,
38+ ] ;
39+ }
40+
41+ return [
42+ {
43+ editor,
44+ range : toCharacterRange ( contentRange ) ,
45+ style : FlashStyle . referenced ,
46+ } ,
47+ ...getOutsideOverflow ( contentRange , removalHighlightRange ) . map (
48+ ( overflow ) : FlashDescriptor => ( {
49+ editor,
50+ range : toCharacterRange ( overflow ) ,
51+ style : FlashStyle . pendingDelete ,
52+ } ) ,
53+ ) ,
54+ ] ;
55+ } ) ,
56+ ) ;
3957
4058 const options = { showDecorations : false } ;
4159
@@ -49,3 +67,17 @@ export class CutToClipboard implements Action {
4967 return { thatSelections : thatMark } ;
5068 }
5169}
70+
71+ /** Get the possible leading and trailing overflow ranges of the outside range compared to the inside range */
72+ function getOutsideOverflow ( insideRange : Range , outsideRange : Range ) : Range [ ] {
73+ const { start : insideStart , end : insideEnd } = insideRange ;
74+ const { start : outsideStart , end : outsideEnd } = outsideRange ;
75+ const result = [ ] ;
76+ if ( outsideStart . isBefore ( insideStart ) ) {
77+ result . push ( new Range ( outsideStart , insideStart ) ) ;
78+ }
79+ if ( outsideEnd . isAfter ( insideEnd ) ) {
80+ result . push ( new Range ( insideEnd , outsideEnd ) ) ;
81+ }
82+ return result ;
83+ }
0 commit comments