Skip to content

Commit

Permalink
Add support for line spacing.
Browse files Browse the repository at this point in the history
  • Loading branch information
gbr committed Mar 17, 2023
1 parent 07781e2 commit 4b666a2
Show file tree
Hide file tree
Showing 8 changed files with 69 additions and 43 deletions.
18 changes: 9 additions & 9 deletions net.certiv.tools.indentguide.feature/feature.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<feature
id="net.certiv.tools.indentguide.feature"
label="IndentGuide"
version="2.1.0.qualifier"
version="2.2.0.qualifier"
provider-name="Certiv Analytis">

<description>
Expand Down Expand Up @@ -43,14 +43,14 @@ SOFTWARE.
</url>

<requires>
<import plugin="org.eclipse.ui" version="3.201.200" match="compatible"/>
<import plugin="org.eclipse.core.runtime" version="3.26.100" match="compatible"/>
<import plugin="org.eclipse.jface.text" version="3.22.0" match="compatible"/>
<import plugin="org.eclipse.ui.workbench.texteditor" version="3.16.600" match="compatible"/>
<import plugin="org.eclipse.e4.core.services" version="2.3.400" match="compatible"/>
<import plugin="org.eclipse.e4.ui.css.swt.theme" version="0.13.200" match="compatible"/>
<import plugin="org.eclipse.osgi.services" version="3.11.100" match="compatible"/>
<import plugin="org.eclipse.ui.forms" version="3.11.500" match="compatible"/>
<import plugin="org.eclipse.core.runtime" version="3.24.100" match="compatible"/>
<import plugin="org.eclipse.e4.core.services" version="2.3.100" match="compatible"/>
<import plugin="org.eclipse.e4.ui.css.swt.theme" version="0.13.0" match="compatible"/>
<import plugin="org.eclipse.jface.text" version="3.20.0" match="compatible"/>
<import plugin="org.eclipse.osgi.services" version="3.10.200" match="compatible"/>
<import plugin="org.eclipse.ui" version="3.201.0" match="compatible"/>
<import plugin="org.eclipse.ui.forms" version="3.11.300" match="compatible"/>
<import plugin="org.eclipse.ui.workbench.texteditor" version="3.16.400" match="compatible"/>
</requires>

<plugin
Expand Down
2 changes: 1 addition & 1 deletion net.certiv.tools.indentguide.feature/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
<parent>
<groupId>net.certiv</groupId>
<artifactId>net.certiv.tools.indentguide.parent</artifactId>
<version>2.1.0-SNAPSHOT</version>
<version>2.2.0-SNAPSHOT</version>
</parent>

<artifactId>net.certiv.tools.indentguide.feature</artifactId>
Expand Down
2 changes: 1 addition & 1 deletion net.certiv.tools.indentguide.plugin.test/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
<parent>
<groupId>net.certiv</groupId>
<artifactId>net.certiv.tools.indentguide.parent</artifactId>
<version>2.1.0-SNAPSHOT</version>
<version>2.2.0-SNAPSHOT</version>
</parent>

<artifactId>net.certiv.tools.indentguide.plugin.test</artifactId>
Expand Down
18 changes: 9 additions & 9 deletions net.certiv.tools.indentguide.plugin/META-INF/MANIFEST.MF
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,17 @@ Manifest-Version: 1.0
Bundle-ManifestVersion: 2
Bundle-Name: IndentGuide
Bundle-SymbolicName: net.certiv.tools.indentguide;singleton:=true
Bundle-Version: 2.1.0.qualifier
Bundle-Version: 2.2.0.qualifier
Bundle-Activator: net.certiv.tools.indentguide.Activator
Bundle-Vendor: Certiv Analytics
Require-Bundle: org.eclipse.core.runtime;bundle-version="[3.26.100,4.0.0)",
org.eclipse.e4.core.services;bundle-version="[2.3.400,3.0.0)",
org.eclipse.e4.ui.css.swt.theme;bundle-version="[0.13.200,1.0.0)",
org.eclipse.jface.text;bundle-version="[3.22.0,4.0.0)",
org.eclipse.osgi.services;bundle-version="[3.11.100,4.0.0)",
org.eclipse.ui;bundle-version="[3.201.200,4.0.0)",
org.eclipse.ui.forms;bundle-version="[3.11.500,4.0.0)",
org.eclipse.ui.workbench.texteditor;bundle-version="[3.16.600,4.0.0)"
Require-Bundle: org.eclipse.core.runtime;bundle-version="[3.24.100,4.0.0)",
org.eclipse.e4.core.services;bundle-version="[2.3.100,3.0.0)",
org.eclipse.e4.ui.css.swt.theme;bundle-version="[0.13.0,1.0.0)",
org.eclipse.jface.text;bundle-version="[3.20.0,4.0.0)",
org.eclipse.osgi.services;bundle-version="[3.10.200,4.0.0)",
org.eclipse.ui;bundle-version="[3.201.0,4.0.0)",
org.eclipse.ui.forms;bundle-version="[3.11.300,4.0.0)",
org.eclipse.ui.workbench.texteditor;bundle-version="[3.16.400,4.0.0)"
Bundle-RequiredExecutionEnvironment: JavaSE-11
Automatic-Module-Name: net.certiv.tools.indentguide.singleton.true
Bundle-ActivationPolicy: lazy
2 changes: 1 addition & 1 deletion net.certiv.tools.indentguide.plugin/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
<parent>
<groupId>net.certiv</groupId>
<artifactId>net.certiv.tools.indentguide.parent</artifactId>
<version>2.1.0-SNAPSHOT</version>
<version>2.2.0-SNAPSHOT</version>
</parent>

<artifactId>net.certiv.tools.indentguide</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,8 @@ private void drawLineRange(GC gc, int begLine, int endLine, int x, int w) {
StyledTextContent content = widget.getContent();

Line prevNb = null; // last non-blank line
Line prevLn = null; // immediately prior line
Line currLn = null; // current line
Line nextNb = null; // next non-blank line

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

if (!Utils.isFolded(viewer, docLine)) {
String text = widget.getLine(line);
Line ln = new Line(docLine, text, tabWidth);
prevLn = prevLine(docLine, tabWidth, currLn);
currLn = new Line(docLine, text, tabWidth);

if (drawBlankLn) {
if (ln.blank) {
if (currLn.blank) {
prevNb = prevNonblankLine(prevNb, docLine, tabWidth);
nextNb = nextNonblankLine(nextNb, docLine, tabWidth);
// log(ln.dir, prevNb, ln, nextNb);

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

ln.stops.clear();
ln.stops.addAll(nextNb.stops); // default: same as next non-blank line
if (ln.delta > 0 && ln.tabs() > 1) ln.stops.removeLast(); // shift in
currLn.stops.clear();
currLn.stops.addAll(nextNb.stops); // default: same as next non-blank line
if (currLn.delta > 0 && currLn.tabs() > 1) {
currLn.stops.removeLast(); // shift in
}

} else {
prevNb = ln;
prevNb = currLn;
}
}

boolean nest = ln.tabs() > 1;
boolean only = ln.tabs(1);
boolean zero = ln.delta == 0;
boolean nest = currLn.tabs() > 1;
boolean only = currLn.tabs(1);
boolean zero = currLn.delta == 0;

for (Pos stop : ln.stops) {
boolean first = stop == ln.stops.peekFirst();
boolean last = stop == ln.stops.peekLast();
for (Pos stop : currLn.stops) {
boolean first = stop == currLn.stops.peekFirst();
boolean last = stop == currLn.stops.peekLast();

if (ln.comment) {
if (currLn.comment) {
// skip first visible character
if (stop.col == ln.beg) continue;
if (stop.col == currLn.beg) continue;

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

} else if (ln.blank) {
} else if (currLn.blank) {
// skip first where only and zero
if (first && only && zero) continue;

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

} else {
// skip first visible character
if (stop.col == ln.beg) continue;
if (stop.col == currLn.beg) continue;

// skip first unless drawLeadEdge
if (first && !drawLeadEdge) continue;
}

draw(gc, offset, stop.col, spcWidth);
boolean ascender = stop.col >= prevLn.endStop();

draw(gc, offset, stop.col, spcWidth, ascender);
}
}
}

}

private Line prevLine(int line, int tabWidth, Line currLn) {
if (currLn != null) return currLn;

int prev = line - 1;
if (prev >= 0) {
String text = widget.getLine(prev);
return new Line(prev, text, tabWidth);
}
return new Line(-1, Utils.EMPTY + Utils.NL_MARK, tabWidth);
}

// get previous non-blank line
private Line prevNonblankLine(Line prevNb, int line, int tabWidth) {
if (prevNb != null && prevNb.num > -1 && prevNb.num < line) return prevNb;
Expand Down Expand Up @@ -255,10 +273,18 @@ private Line nextNonblankLine(Line nextNb, int line, int tabWidth) {
return new Line(end, Utils.EMPTY + Utils.NL_MARK, tabWidth);
}

private void draw(GC gc, int offset, int col, int spcWidth) {
private void draw(GC gc, int offset, int col, int spcWidth, boolean ascender) {
Point pos = widget.getLocationAtOffset(offset);
pos.x += col * spcWidth + lineShift;
gc.drawLine(pos.x, pos.y, pos.x, pos.y + widget.getLineHeight(offset));

int sp = widget.getLineSpacing();
int ht = widget.getLineHeight(offset);

if (ascender) {
gc.drawLine(pos.x, pos.y - sp, pos.x, pos.y + ht + sp);
} else {
gc.drawLine(pos.x, pos.y, pos.x, pos.y + ht + sp);
}
}

public void loadPrefs() {
Expand Down
2 changes: 1 addition & 1 deletion net.certiv.tools.indentguide.site/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
<parent>
<groupId>net.certiv</groupId>
<artifactId>net.certiv.tools.indentguide.parent</artifactId>
<version>2.1.0-SNAPSHOT</version>
<version>2.2.0-SNAPSHOT</version>
</parent>

<artifactId>net.certiv.tools.indentguide.site</artifactId>
Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

<groupId>net.certiv</groupId>
<artifactId>net.certiv.tools.indentguide.parent</artifactId>
<version>2.1.0-SNAPSHOT</version>
<version>2.2.0-SNAPSHOT</version>

<name>IndentGuide</name>
<description>IndentGuide</description>
Expand Down

0 comments on commit 4b666a2

Please sign in to comment.