File tree Expand file tree Collapse file tree 3 files changed +61
-1
lines changed Expand file tree Collapse file tree 3 files changed +61
-1
lines changed Original file line number Diff line number Diff line change @@ -98,6 +98,15 @@ export interface SubpieceModifier {
98
98
export interface MatchingPairSymbolModifier {
99
99
type : "matchingPairSymbol" ;
100
100
}
101
+ export interface LineNumberModifierPosition {
102
+ lineNumber : number ;
103
+ isRelative : boolean ;
104
+ }
105
+ export interface LineNumberModifier {
106
+ type : "lineNumber" ;
107
+ anchor : LineNumberModifierPosition ;
108
+ active : LineNumberModifierPosition ;
109
+ }
101
110
export interface IdentityModifier {
102
111
type : "identity" ;
103
112
}
@@ -109,11 +118,12 @@ export interface TailModifier {
109
118
}
110
119
111
120
export type Modifier =
121
+ | IdentityModifier
112
122
| SurroundingPairModifier
113
123
| ContainingScopeModifier
114
124
| SubpieceModifier
115
125
| MatchingPairSymbolModifier
116
- | IdentityModifier
126
+ | LineNumberModifier
117
127
| HeadModifier
118
128
| TailModifier ;
119
129
Original file line number Diff line number Diff line change @@ -215,10 +215,38 @@ export async function activate(context: vscode.ExtensionContext) {
215
215
216
216
addDecorationsDebounced ( ) ;
217
217
218
+ function checkForEditsOutsideViewport ( event : vscode . TextDocumentChangeEvent ) {
219
+ const editor = vscode . window . activeTextEditor ;
220
+ if ( editor == null || editor . document !== event . document ) {
221
+ return ;
222
+ }
223
+ const { start, end } = editor . visibleRanges [ 0 ] ;
224
+ const ranges = [ ] ;
225
+ for ( const edit of event . contentChanges ) {
226
+ if (
227
+ edit . range . end . isBeforeOrEqual ( start ) ||
228
+ edit . range . start . isAfterOrEqual ( end )
229
+ ) {
230
+ ranges . push ( edit . range ) ;
231
+ }
232
+ }
233
+ if ( ranges . length > 0 ) {
234
+ ranges . sort ( ( a , b ) => a . start . line - b . start . line ) ;
235
+ const linesText = ranges
236
+ . map ( ( range ) => `${ range . start . line + 1 } -${ range . end . line + 1 } ` )
237
+ . join ( ", " ) ;
238
+ vscode . window . showWarningMessage (
239
+ `Modification outside of viewport at lines: ${ linesText } `
240
+ ) ;
241
+ }
242
+ }
243
+
218
244
function handleEdit ( edit : vscode . TextDocumentChangeEvent ) {
219
245
graph . navigationMap . updateTokenRanges ( edit ) ;
220
246
221
247
addDecorationsDebounced ( ) ;
248
+
249
+ checkForEditsOutsideViewport ( edit ) ;
222
250
}
223
251
224
252
const recomputeDecorationStyles = async ( ) => {
Original file line number Diff line number Diff line change @@ -14,6 +14,7 @@ import {
14
14
Target ,
15
15
TypedSelection ,
16
16
Modifier ,
17
+ LineNumberModifierPosition ,
17
18
} from "./Types" ;
18
19
import { performInsideOutsideAdjustment } from "./performInsideOutsideAdjustment" ;
19
20
import { SUBWORD_MATCHER } from "./constants" ;
@@ -370,6 +371,27 @@ function transformSelection(
370
371
] ;
371
372
}
372
373
374
+ case "lineNumber" : {
375
+ const getLine = ( linePosition : LineNumberModifierPosition ) =>
376
+ linePosition . isRelative
377
+ ? selection . editor . selection . active . line + linePosition . lineNumber
378
+ : linePosition . lineNumber ;
379
+ return [
380
+ {
381
+ selection : update ( selection , {
382
+ selection : ( ) =>
383
+ new Selection (
384
+ getLine ( modifier . anchor ) ,
385
+ 0 ,
386
+ getLine ( modifier . active ) ,
387
+ 0
388
+ ) ,
389
+ } ) ,
390
+ context : { } ,
391
+ } ,
392
+ ] ;
393
+ }
394
+
373
395
case "matchingPairSymbol" :
374
396
case "surroundingPair" :
375
397
throw new Error ( "Not implemented" ) ;
You can’t perform that action at this time.
0 commit comments