@@ -151,6 +151,8 @@ private void drawLineRange(GC gc, int begLine, int endLine, int x, int w) {
151
151
StyledTextContent content = widget .getContent ();
152
152
153
153
Line prevNb = null ; // last non-blank line
154
+ Line prevLn = null ; // immediately prior line
155
+ Line currLn = null ; // current line
154
156
Line nextNb = null ; // next non-blank line
155
157
156
158
for (int line = begLine ; line <= endLine ; line ++) {
@@ -159,37 +161,40 @@ private void drawLineRange(GC gc, int begLine, int endLine, int x, int w) {
159
161
160
162
if (!Utils .isFolded (viewer , docLine )) {
161
163
String text = widget .getLine (line );
162
- Line ln = new Line (docLine , text , tabWidth );
164
+ prevLn = prevLine (docLine , tabWidth , currLn );
165
+ currLn = new Line (docLine , text , tabWidth );
163
166
164
167
if (drawBlankLn ) {
165
- if (ln .blank ) {
168
+ if (currLn .blank ) {
166
169
prevNb = prevNonblankLine (prevNb , docLine , tabWidth );
167
170
nextNb = nextNonblankLine (nextNb , docLine , tabWidth );
168
171
// log(ln.dir, prevNb, ln, nextNb);
169
172
170
173
// change in dents: - <-> +
171
- ln .delta = nextNb .tabs () - prevNb .tabs ();
174
+ currLn .delta = nextNb .tabs () - prevNb .tabs ();
172
175
173
- ln .stops .clear ();
174
- ln .stops .addAll (nextNb .stops ); // default: same as next non-blank line
175
- if (ln .delta > 0 && ln .tabs () > 1 ) ln .stops .removeLast (); // shift in
176
+ currLn .stops .clear ();
177
+ currLn .stops .addAll (nextNb .stops ); // default: same as next non-blank line
178
+ if (currLn .delta > 0 && currLn .tabs () > 1 ) {
179
+ currLn .stops .removeLast (); // shift in
180
+ }
176
181
177
182
} else {
178
- prevNb = ln ;
183
+ prevNb = currLn ;
179
184
}
180
185
}
181
186
182
- boolean nest = ln .tabs () > 1 ;
183
- boolean only = ln .tabs (1 );
184
- boolean zero = ln .delta == 0 ;
187
+ boolean nest = currLn .tabs () > 1 ;
188
+ boolean only = currLn .tabs (1 );
189
+ boolean zero = currLn .delta == 0 ;
185
190
186
- for (Pos stop : ln .stops ) {
187
- boolean first = stop == ln .stops .peekFirst ();
188
- boolean last = stop == ln .stops .peekLast ();
191
+ for (Pos stop : currLn .stops ) {
192
+ boolean first = stop == currLn .stops .peekFirst ();
193
+ boolean last = stop == currLn .stops .peekLast ();
189
194
190
- if (ln .comment ) {
195
+ if (currLn .comment ) {
191
196
// skip first visible character
192
- if (stop .col == ln .beg ) continue ;
197
+ if (stop .col == currLn .beg ) continue ;
193
198
194
199
// skip first where only unless drawComment or drawLeadEdge
195
200
if (only && !(drawComment || drawLeadEdge )) continue ;
@@ -200,7 +205,7 @@ private void drawLineRange(GC gc, int begLine, int endLine, int x, int w) {
200
205
// skip last where !only unless drawComment
201
206
if (last && !only && !drawComment ) continue ;
202
207
203
- } else if (ln .blank ) {
208
+ } else if (currLn .blank ) {
204
209
// skip first where only and zero
205
210
if (first && only && zero ) continue ;
206
211
@@ -215,19 +220,32 @@ private void drawLineRange(GC gc, int begLine, int endLine, int x, int w) {
215
220
216
221
} else {
217
222
// skip first visible character
218
- if (stop .col == ln .beg ) continue ;
223
+ if (stop .col == currLn .beg ) continue ;
219
224
220
225
// skip first unless drawLeadEdge
221
226
if (first && !drawLeadEdge ) continue ;
222
227
}
223
228
224
- draw (gc , offset , stop .col , spcWidth );
229
+ boolean ascender = stop .col >= prevLn .endStop ();
230
+
231
+ draw (gc , offset , stop .col , spcWidth , ascender );
225
232
}
226
233
}
227
234
}
228
235
229
236
}
230
237
238
+ private Line prevLine (int line , int tabWidth , Line currLn ) {
239
+ if (currLn != null ) return currLn ;
240
+
241
+ int prev = line - 1 ;
242
+ if (prev >= 0 ) {
243
+ String text = widget .getLine (prev );
244
+ return new Line (prev , text , tabWidth );
245
+ }
246
+ return new Line (-1 , Utils .EMPTY + Utils .NL_MARK , tabWidth );
247
+ }
248
+
231
249
// get previous non-blank line
232
250
private Line prevNonblankLine (Line prevNb , int line , int tabWidth ) {
233
251
if (prevNb != null && prevNb .num > -1 && prevNb .num < line ) return prevNb ;
@@ -255,10 +273,18 @@ private Line nextNonblankLine(Line nextNb, int line, int tabWidth) {
255
273
return new Line (end , Utils .EMPTY + Utils .NL_MARK , tabWidth );
256
274
}
257
275
258
- private void draw (GC gc , int offset , int col , int spcWidth ) {
276
+ private void draw (GC gc , int offset , int col , int spcWidth , boolean ascender ) {
259
277
Point pos = widget .getLocationAtOffset (offset );
260
278
pos .x += col * spcWidth + lineShift ;
261
- gc .drawLine (pos .x , pos .y , pos .x , pos .y + widget .getLineHeight (offset ));
279
+
280
+ int sp = widget .getLineSpacing ();
281
+ int ht = widget .getLineHeight (offset );
282
+
283
+ if (ascender ) {
284
+ gc .drawLine (pos .x , pos .y - sp , pos .x , pos .y + ht + sp );
285
+ } else {
286
+ gc .drawLine (pos .x , pos .y , pos .x , pos .y + ht + sp );
287
+ }
262
288
}
263
289
264
290
public void loadPrefs () {
0 commit comments