Skip to content

Commit 4b666a2

Browse files
author
gbr
committed
Add support for line spacing.
1 parent 07781e2 commit 4b666a2

File tree

8 files changed

+69
-43
lines changed

8 files changed

+69
-43
lines changed

net.certiv.tools.indentguide.feature/feature.xml

+9-9
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
<feature
33
id="net.certiv.tools.indentguide.feature"
44
label="IndentGuide"
5-
version="2.1.0.qualifier"
5+
version="2.2.0.qualifier"
66
provider-name="Certiv Analytis">
77

88
<description>
@@ -43,14 +43,14 @@ SOFTWARE.
4343
</url>
4444

4545
<requires>
46-
<import plugin="org.eclipse.ui" version="3.201.200" match="compatible"/>
47-
<import plugin="org.eclipse.core.runtime" version="3.26.100" match="compatible"/>
48-
<import plugin="org.eclipse.jface.text" version="3.22.0" match="compatible"/>
49-
<import plugin="org.eclipse.ui.workbench.texteditor" version="3.16.600" match="compatible"/>
50-
<import plugin="org.eclipse.e4.core.services" version="2.3.400" match="compatible"/>
51-
<import plugin="org.eclipse.e4.ui.css.swt.theme" version="0.13.200" match="compatible"/>
52-
<import plugin="org.eclipse.osgi.services" version="3.11.100" match="compatible"/>
53-
<import plugin="org.eclipse.ui.forms" version="3.11.500" match="compatible"/>
46+
<import plugin="org.eclipse.core.runtime" version="3.24.100" match="compatible"/>
47+
<import plugin="org.eclipse.e4.core.services" version="2.3.100" match="compatible"/>
48+
<import plugin="org.eclipse.e4.ui.css.swt.theme" version="0.13.0" match="compatible"/>
49+
<import plugin="org.eclipse.jface.text" version="3.20.0" match="compatible"/>
50+
<import plugin="org.eclipse.osgi.services" version="3.10.200" match="compatible"/>
51+
<import plugin="org.eclipse.ui" version="3.201.0" match="compatible"/>
52+
<import plugin="org.eclipse.ui.forms" version="3.11.300" match="compatible"/>
53+
<import plugin="org.eclipse.ui.workbench.texteditor" version="3.16.400" match="compatible"/>
5454
</requires>
5555

5656
<plugin

net.certiv.tools.indentguide.feature/pom.xml

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
<parent>
1010
<groupId>net.certiv</groupId>
1111
<artifactId>net.certiv.tools.indentguide.parent</artifactId>
12-
<version>2.1.0-SNAPSHOT</version>
12+
<version>2.2.0-SNAPSHOT</version>
1313
</parent>
1414

1515
<artifactId>net.certiv.tools.indentguide.feature</artifactId>

net.certiv.tools.indentguide.plugin.test/pom.xml

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
<parent>
99
<groupId>net.certiv</groupId>
1010
<artifactId>net.certiv.tools.indentguide.parent</artifactId>
11-
<version>2.1.0-SNAPSHOT</version>
11+
<version>2.2.0-SNAPSHOT</version>
1212
</parent>
1313

1414
<artifactId>net.certiv.tools.indentguide.plugin.test</artifactId>

net.certiv.tools.indentguide.plugin/META-INF/MANIFEST.MF

+9-9
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,17 @@ Manifest-Version: 1.0
22
Bundle-ManifestVersion: 2
33
Bundle-Name: IndentGuide
44
Bundle-SymbolicName: net.certiv.tools.indentguide;singleton:=true
5-
Bundle-Version: 2.1.0.qualifier
5+
Bundle-Version: 2.2.0.qualifier
66
Bundle-Activator: net.certiv.tools.indentguide.Activator
77
Bundle-Vendor: Certiv Analytics
8-
Require-Bundle: org.eclipse.core.runtime;bundle-version="[3.26.100,4.0.0)",
9-
org.eclipse.e4.core.services;bundle-version="[2.3.400,3.0.0)",
10-
org.eclipse.e4.ui.css.swt.theme;bundle-version="[0.13.200,1.0.0)",
11-
org.eclipse.jface.text;bundle-version="[3.22.0,4.0.0)",
12-
org.eclipse.osgi.services;bundle-version="[3.11.100,4.0.0)",
13-
org.eclipse.ui;bundle-version="[3.201.200,4.0.0)",
14-
org.eclipse.ui.forms;bundle-version="[3.11.500,4.0.0)",
15-
org.eclipse.ui.workbench.texteditor;bundle-version="[3.16.600,4.0.0)"
8+
Require-Bundle: org.eclipse.core.runtime;bundle-version="[3.24.100,4.0.0)",
9+
org.eclipse.e4.core.services;bundle-version="[2.3.100,3.0.0)",
10+
org.eclipse.e4.ui.css.swt.theme;bundle-version="[0.13.0,1.0.0)",
11+
org.eclipse.jface.text;bundle-version="[3.20.0,4.0.0)",
12+
org.eclipse.osgi.services;bundle-version="[3.10.200,4.0.0)",
13+
org.eclipse.ui;bundle-version="[3.201.0,4.0.0)",
14+
org.eclipse.ui.forms;bundle-version="[3.11.300,4.0.0)",
15+
org.eclipse.ui.workbench.texteditor;bundle-version="[3.16.400,4.0.0)"
1616
Bundle-RequiredExecutionEnvironment: JavaSE-11
1717
Automatic-Module-Name: net.certiv.tools.indentguide.singleton.true
1818
Bundle-ActivationPolicy: lazy

net.certiv.tools.indentguide.plugin/pom.xml

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
<parent>
1010
<groupId>net.certiv</groupId>
1111
<artifactId>net.certiv.tools.indentguide.parent</artifactId>
12-
<version>2.1.0-SNAPSHOT</version>
12+
<version>2.2.0-SNAPSHOT</version>
1313
</parent>
1414

1515
<artifactId>net.certiv.tools.indentguide</artifactId>

net.certiv.tools.indentguide.plugin/src/main/java/net/certiv/tools/indentguide/painter/GuidePainter.java

+46-20
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,8 @@ private void drawLineRange(GC gc, int begLine, int endLine, int x, int w) {
151151
StyledTextContent content = widget.getContent();
152152

153153
Line prevNb = null; // last non-blank line
154+
Line prevLn = null; // immediately prior line
155+
Line currLn = null; // current line
154156
Line nextNb = null; // next non-blank line
155157

156158
for (int line = begLine; line <= endLine; line++) {
@@ -159,37 +161,40 @@ private void drawLineRange(GC gc, int begLine, int endLine, int x, int w) {
159161

160162
if (!Utils.isFolded(viewer, docLine)) {
161163
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);
163166

164167
if (drawBlankLn) {
165-
if (ln.blank) {
168+
if (currLn.blank) {
166169
prevNb = prevNonblankLine(prevNb, docLine, tabWidth);
167170
nextNb = nextNonblankLine(nextNb, docLine, tabWidth);
168171
// log(ln.dir, prevNb, ln, nextNb);
169172

170173
// change in dents: - <-> +
171-
ln.delta = nextNb.tabs() - prevNb.tabs();
174+
currLn.delta = nextNb.tabs() - prevNb.tabs();
172175

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+
}
176181

177182
} else {
178-
prevNb = ln;
183+
prevNb = currLn;
179184
}
180185
}
181186

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;
185190

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();
189194

190-
if (ln.comment) {
195+
if (currLn.comment) {
191196
// skip first visible character
192-
if (stop.col == ln.beg) continue;
197+
if (stop.col == currLn.beg) continue;
193198

194199
// skip first where only unless drawComment or drawLeadEdge
195200
if (only && !(drawComment || drawLeadEdge)) continue;
@@ -200,7 +205,7 @@ private void drawLineRange(GC gc, int begLine, int endLine, int x, int w) {
200205
// skip last where !only unless drawComment
201206
if (last && !only && !drawComment) continue;
202207

203-
} else if (ln.blank) {
208+
} else if (currLn.blank) {
204209
// skip first where only and zero
205210
if (first && only && zero) continue;
206211

@@ -215,19 +220,32 @@ private void drawLineRange(GC gc, int begLine, int endLine, int x, int w) {
215220

216221
} else {
217222
// skip first visible character
218-
if (stop.col == ln.beg) continue;
223+
if (stop.col == currLn.beg) continue;
219224

220225
// skip first unless drawLeadEdge
221226
if (first && !drawLeadEdge) continue;
222227
}
223228

224-
draw(gc, offset, stop.col, spcWidth);
229+
boolean ascender = stop.col >= prevLn.endStop();
230+
231+
draw(gc, offset, stop.col, spcWidth, ascender);
225232
}
226233
}
227234
}
228235

229236
}
230237

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+
231249
// get previous non-blank line
232250
private Line prevNonblankLine(Line prevNb, int line, int tabWidth) {
233251
if (prevNb != null && prevNb.num > -1 && prevNb.num < line) return prevNb;
@@ -255,10 +273,18 @@ private Line nextNonblankLine(Line nextNb, int line, int tabWidth) {
255273
return new Line(end, Utils.EMPTY + Utils.NL_MARK, tabWidth);
256274
}
257275

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) {
259277
Point pos = widget.getLocationAtOffset(offset);
260278
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+
}
262288
}
263289

264290
public void loadPrefs() {

net.certiv.tools.indentguide.site/pom.xml

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
<parent>
1010
<groupId>net.certiv</groupId>
1111
<artifactId>net.certiv.tools.indentguide.parent</artifactId>
12-
<version>2.1.0-SNAPSHOT</version>
12+
<version>2.2.0-SNAPSHOT</version>
1313
</parent>
1414

1515
<artifactId>net.certiv.tools.indentguide.site</artifactId>

pom.xml

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
<groupId>net.certiv</groupId>
1010
<artifactId>net.certiv.tools.indentguide.parent</artifactId>
11-
<version>2.1.0-SNAPSHOT</version>
11+
<version>2.2.0-SNAPSHOT</version>
1212

1313
<name>IndentGuide</name>
1414
<description>IndentGuide</description>

0 commit comments

Comments
 (0)