@@ -38,7 +38,7 @@ export class InteractiveConcatTextDocument implements IConcatTextDocument {
38
38
}
39
39
40
40
get lineCount ( ) : number {
41
- return this . _lineCounts [ 0 ] + 1 + this . _lineCounts [ 1 ] ;
41
+ return this . _lineCounts [ 0 ] + this . _lineCounts [ 1 ] ;
42
42
}
43
43
44
44
get languageId ( ) : string {
@@ -65,9 +65,6 @@ export class InteractiveConcatTextDocument implements IConcatTextDocument {
65
65
}
66
66
} ) ;
67
67
68
- this . _updateConcat ( ) ;
69
- this . _updateInput ( ) ;
70
-
71
68
const counter = / I n t e r a c t i v e - ( \d + ) \. i n t e r a c t i v e / . exec ( this . _notebook . uri . path ) ;
72
69
if ( counter ) {
73
70
this . _input = workspace . textDocuments . find (
@@ -90,6 +87,9 @@ export class InteractiveConcatTextDocument implements IConcatTextDocument {
90
87
}
91
88
} ) ;
92
89
}
90
+
91
+ this . _updateConcat ( ) ;
92
+ this . _updateInput ( ) ;
93
93
}
94
94
95
95
private _updateConcat ( ) {
@@ -98,15 +98,12 @@ export class InteractiveConcatTextDocument implements IConcatTextDocument {
98
98
for ( let i = 0 ; i < this . _notebook . cellCount ; i += 1 ) {
99
99
const cell = this . _notebook . cellAt ( i ) ;
100
100
if ( score ( cell . document , this . _selector ) ) {
101
- concatLineCnt += cell . document . lineCount + 1 ;
101
+ concatLineCnt += cell . document . lineCount ;
102
102
concatTextLen += this . _getDocumentTextLen ( cell . document ) + 1 ;
103
103
}
104
104
}
105
105
106
- this . _lineCounts = [
107
- concatLineCnt > 0 ? concatLineCnt - 1 : 0 , // NotebookConcatTextDocument.lineCount
108
- this . _lineCounts [ 1 ] ,
109
- ] ;
106
+ this . _lineCounts = [ concatLineCnt , this . _lineCounts [ 1 ] ] ;
110
107
111
108
this . _textLen = [ concatTextLen > 0 ? concatTextLen - 1 : 0 , this . _textLen [ 1 ] ] ;
112
109
}
@@ -126,9 +123,12 @@ export class InteractiveConcatTextDocument implements IConcatTextDocument {
126
123
127
124
getText ( range ?: Range ) : string {
128
125
if ( ! range ) {
129
- let result = '' ;
130
- result += `${ this . _concatTextDocument . getText ( ) } \n${ this . _input ?. getText ( ) ?? '' } ` ;
131
- return result ;
126
+ if ( this . _lineCounts [ 0 ] === 0 ) {
127
+ // empty
128
+ return this . _input ?. getText ( ) ?? '' ;
129
+ }
130
+
131
+ return `${ this . _concatTextDocument . getText ( ) } \n${ this . _input ?. getText ( ) ?? '' } ` ;
132
132
}
133
133
134
134
if ( range . isEmpty ) {
@@ -198,9 +198,9 @@ export class InteractiveConcatTextDocument implements IConcatTextDocument {
198
198
const start = positionOrRange . start . line ;
199
199
if ( start >= this . _lineCounts [ 0 ] ) {
200
200
// this is the inputbox
201
- const offset = Math . max ( 0 , start - this . _lineCounts [ 0 ] - 1 ) ;
201
+ const offset = start - this . _lineCounts [ 0 ] ;
202
202
const startPosition = new Position ( offset , positionOrRange . start . character ) ;
203
- const endOffset = Math . max ( 0 , positionOrRange . end . line - this . _lineCounts [ 0 ] - 1 ) ;
203
+ const endOffset = positionOrRange . end . line - this . _lineCounts [ 0 ] ;
204
204
const endPosition = new Position ( endOffset , positionOrRange . end . character ) ;
205
205
206
206
// TODO@rebornix !
@@ -230,15 +230,15 @@ export class InteractiveConcatTextDocument implements IConcatTextDocument {
230
230
lineAt ( posOrNumber : Position | number ) : TextLine {
231
231
const position = typeof posOrNumber === 'number' ? new Position ( posOrNumber , 0 ) : posOrNumber ;
232
232
233
+ if ( position . line >= this . _lineCounts [ 0 ] && this . _input ) {
234
+ // this is the input box
235
+ return this . _input ?. lineAt ( position . line - this . _lineCounts [ 0 ] ) ;
236
+ }
237
+
233
238
// convert this position into a cell location
234
239
// (we need the translated location, that's why we can't use getCellAtPosition)
235
240
const location = this . _concatTextDocument . locationAt ( position ) ;
236
241
237
- // Get the cell at this location
238
- if ( location . uri . toString ( ) === this . _input ?. uri . toString ( ) ) {
239
- return this . _input . lineAt ( location . range . start ) ;
240
- }
241
-
242
242
const cell = this . _notebook . getCells ( ) . find ( ( c ) => c . document . uri . toString ( ) === location . uri . toString ( ) ) ;
243
243
return cell ! . document . lineAt ( location . range . start ) ;
244
244
}
0 commit comments