Skip to content

Commit

Permalink
Scroll preview to the beginning of an include (#1624)
Browse files Browse the repository at this point in the history
  • Loading branch information
ahus1 committed May 26, 2024
1 parent aa37cca commit 42ef53d
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 8 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ This document provides a high-level view of the changes introduced by release.
- Prevent AlreadyDisposedException during startup when re-opening editors (#1617)
- Upgrade to AsciidoctorJ v2.5.13 and asciidoctor 2.0.23
- Detect dark editor theme in light IDE to apply correct background color for monospaced contents in the editor (#1620)
- Scroll preview to the beginning of an include (#1624)

=== 0.41.14

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,12 @@ window.__IntelliJTools.scrollToLine = (function () {

for (var i = 0; i < classes.length; i++) {
var className = classes[i]
if (className.match(/^data-line-stdin-/)) {
return Number(className.substr("data-line-stdin-".length));
}
}
if (className.match(/^data-line-stdin-/)) {
return Number(className.substr("data-line-stdin-".length));
} else if (className.match(/^data-line-/)) {
// This is an include of another file
return -1;
}

return null
Expand All @@ -39,19 +42,28 @@ window.__IntelliJTools.scrollToLine = (function () {
var startLine = 0;
var endY;
var endLine = lineCount;
var includeFound = false;

for (var i = 0; i < blocks.length; i++) {
var block = blocks[i]
var lineOfBlock = getLine(block);
if (lineOfBlock <= newLineToScroll) {
if (lineOfBlock === -1) {
includeFound = true;
} else if (lineOfBlock <= newLineToScroll) {
startY = calculateOffset(block)
startLine = lineOfBlock
// there might be no further block, therefore assume that the end is at the end of this block
endY = startY + block.offsetHeight
}
else if (lineOfBlock > newLineToScroll) {
endY = calculateOffset(block)
endLine = lineOfBlock -1;
includeFound = false;
} else if (lineOfBlock > newLineToScroll) {
if (includeFound) {
// if there is an include, place the view where we expect the beginning of the include
endY = startY
endLine = startLine;
} else {
endY = calculateOffset(block)
endLine = lineOfBlock - 1;
}
break
}
}
Expand Down

0 comments on commit 42ef53d

Please sign in to comment.