Skip to content

Commit 42ef53d

Browse files
committed
Scroll preview to the beginning of an include (#1624)
1 parent aa37cca commit 42ef53d

File tree

2 files changed

+21
-8
lines changed

2 files changed

+21
-8
lines changed

CHANGELOG.adoc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ This document provides a high-level view of the changes introduced by release.
1313
- Prevent AlreadyDisposedException during startup when re-opening editors (#1617)
1414
- Upgrade to AsciidoctorJ v2.5.13 and asciidoctor 2.0.23
1515
- Detect dark editor theme in light IDE to apply correct background color for monospaced contents in the editor (#1620)
16+
- Scroll preview to the beginning of an include (#1624)
1617

1718
=== 0.41.14
1819

src/main/resources/org/asciidoc/intellij/editor/javafx/scrollToElement.js

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,12 @@ window.__IntelliJTools.scrollToLine = (function () {
1414

1515
for (var i = 0; i < classes.length; i++) {
1616
var className = classes[i]
17-
if (className.match(/^data-line-stdin-/)) {
18-
return Number(className.substr("data-line-stdin-".length));
19-
}
17+
}
18+
if (className.match(/^data-line-stdin-/)) {
19+
return Number(className.substr("data-line-stdin-".length));
20+
} else if (className.match(/^data-line-/)) {
21+
// This is an include of another file
22+
return -1;
2023
}
2124

2225
return null
@@ -39,19 +42,28 @@ window.__IntelliJTools.scrollToLine = (function () {
3942
var startLine = 0;
4043
var endY;
4144
var endLine = lineCount;
45+
var includeFound = false;
4246

4347
for (var i = 0; i < blocks.length; i++) {
4448
var block = blocks[i]
4549
var lineOfBlock = getLine(block);
46-
if (lineOfBlock <= newLineToScroll) {
50+
if (lineOfBlock === -1) {
51+
includeFound = true;
52+
} else if (lineOfBlock <= newLineToScroll) {
4753
startY = calculateOffset(block)
4854
startLine = lineOfBlock
4955
// there might be no further block, therefore assume that the end is at the end of this block
5056
endY = startY + block.offsetHeight
51-
}
52-
else if (lineOfBlock > newLineToScroll) {
53-
endY = calculateOffset(block)
54-
endLine = lineOfBlock -1;
57+
includeFound = false;
58+
} else if (lineOfBlock > newLineToScroll) {
59+
if (includeFound) {
60+
// if there is an include, place the view where we expect the beginning of the include
61+
endY = startY
62+
endLine = startLine;
63+
} else {
64+
endY = calculateOffset(block)
65+
endLine = lineOfBlock - 1;
66+
}
5567
break
5668
}
5769
}

0 commit comments

Comments
 (0)