From 80a8379818bb0e058f223a279aa86f716938fca5 Mon Sep 17 00:00:00 2001
From: mkslanc <mkslanc@gmail.com>
Date: Tue, 6 Aug 2024 17:16:05 +0400
Subject: [PATCH 1/3] fix: highlight indent guides with wrapped lines

---
 src/layer/text.js            | 28 ++++++++++++++--------------
 src/virtual_renderer_test.js |  1 +
 2 files changed, 15 insertions(+), 14 deletions(-)

diff --git a/src/layer/text.js b/src/layer/text.js
index 20cc1194316..771e67bf675 100644
--- a/src/layer/text.js
+++ b/src/layer/text.js
@@ -511,25 +511,25 @@ class Text {
     }
 
     $clearActiveIndentGuide() {
-        var cells = this.$lines.cells;
-        for (var i = 0; i < cells.length; i++) {
-            var cell = cells[i];
-            var childNodes = cell.element.childNodes;
-            if (childNodes.length > 0) {
-                for (var j = 0; j < childNodes.length; j++) {
-                    if (childNodes[j].classList && childNodes[j].classList.contains("ace_indent-guide-active")) {
-                        childNodes[j].classList.remove("ace_indent-guide-active");
-                        break;
-                    }
-                }
-            }
-        }
+        var activeIndentGuides = this.element.querySelectorAll(".ace_indent-guide-active");
+        activeIndentGuides.forEach(el => {
+            el.classList.remove("ace_indent-guide-active");
+        });
     }
 
     $setIndentGuideActive(cell, indentLevel) {
         var line = this.session.doc.getLine(cell.row);
         if (line !== "") {
-            var childNodes = cell.element.childNodes;
+            let element = cell.element;
+            if (cell.element.classList && cell.element.classList.contains("ace_line_group")) {
+                if (cell.element.childNodes.length > 0) {
+                    element = cell.element.childNodes[0];
+                }
+                else {
+                    return;
+                }
+            }
+            var childNodes = element.childNodes;
             if (childNodes) {
                 let node = childNodes[indentLevel - 1];
                 if (node && node.classList && node.classList.contains("ace_indent-guide")) node.classList.add(
diff --git a/src/virtual_renderer_test.js b/src/virtual_renderer_test.js
index 912a91e4b48..90ebf40063a 100644
--- a/src/virtual_renderer_test.js
+++ b/src/virtual_renderer_test.js
@@ -243,6 +243,7 @@ module.exports = {
         editor.session.setValue(
             "function Test() {\n" + "    function Inner() {\n" + "        \n" + "        \n" + "    }\n" + "}");
         editor.setOption("highlightIndentGuides", false);
+        editor.setOption("wrap", 10); // to make sure higlight works with wrapped lines
         editor.session.selection.$setSelection(1, 22, 1, 22);
         editor.resize(true);
 

From 6a4cdac60b5f9be60d46c6307ef8b6a2423be358 Mon Sep 17 00:00:00 2001
From: mkslanc <mkslanc@gmail.com>
Date: Tue, 24 Sep 2024 13:43:28 +0400
Subject: [PATCH 2/3] fix: rare cases when indent guide final line was not
 included to bracketed block

---
 src/layer/text.js | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/src/layer/text.js b/src/layer/text.js
index 771e67bf675..a2e60e4f04c 100644
--- a/src/layer/text.js
+++ b/src/layer/text.js
@@ -481,7 +481,7 @@ class Text {
             var ranges = this.session.$bracketHighlight.ranges;
             for (var i = 0; i < ranges.length; i++) {
                 if (cursor.row !== ranges[i].start.row) {
-                    this.$highlightIndentGuideMarker.end = ranges[i].start.row;
+                    this.$highlightIndentGuideMarker.end = ranges[i].start.row + 1;
                     if (cursor.row > ranges[i].start.row) {
                         this.$highlightIndentGuideMarker.dir = -1;
                     }
@@ -558,7 +558,7 @@ class Text {
                 for (var i = cells.length - 1; i >= 0; i--) {
                     var cell = cells[i];
                     if (this.$highlightIndentGuideMarker.end && cell.row < this.$highlightIndentGuideMarker.start) {
-                        if (cell.row <= this.$highlightIndentGuideMarker.end) break;
+                        if (cell.row < this.$highlightIndentGuideMarker.end) break;
                         this.$setIndentGuideActive(cell, indentLevel);
                     }
                 }

From b738f6a54eb411dc18aad343dfcbae99dd41fa5e Mon Sep 17 00:00:00 2001
From: mkslanc <mkslanc@gmail.com>
Date: Mon, 21 Oct 2024 16:23:41 +0400
Subject: [PATCH 3/3] imrove test for highlight indent guide

---
 src/virtual_renderer_test.js | 10 +++++++++-
 1 file changed, 9 insertions(+), 1 deletion(-)

diff --git a/src/virtual_renderer_test.js b/src/virtual_renderer_test.js
index 90ebf40063a..b8b1fda370d 100644
--- a/src/virtual_renderer_test.js
+++ b/src/virtual_renderer_test.js
@@ -239,7 +239,7 @@ module.exports = {
         editor._signal("input", {});
         assert.equal(editor.renderer.content.textContent, "only visible for empty value");
     },
-    "test: highlight indent guide": function () {
+    "test: highlight indent guide": function (done) {
         editor.session.setValue(
             "function Test() {\n" + "    function Inner() {\n" + "        \n" + "        \n" + "    }\n" + "}");
         editor.setOption("highlightIndentGuides", false);
@@ -261,6 +261,14 @@ module.exports = {
         editor.session.selection.$setSelection(1, 15, 1, 15);
         editor.resize(true);
         assertIndentGuides( 0);
+
+        editor.session.selection.clearSelection();
+        editor.session.selection.$setSelection(4, 5, 4, 5);
+
+        setTimeout(() => {
+            assertIndentGuides( 2);
+            done();
+        }, 100);
     },
     "test annotation marks": function() {
         function findPointFillStyle(imageData, x, y) {