From b901b636065a22fcfbb65ae5dd16783ebb1c6032 Mon Sep 17 00:00:00 2001
From: Steve Hancock <perltidy@users.sourceforge.net>
Date: Sun, 23 Oct 2022 17:23:20 -0700
Subject: [PATCH] move call to undo_ci downstream

---
 lib/Perl/Tidy/Formatter.pm | 20 ++++++++++++--------
 1 file changed, 12 insertions(+), 8 deletions(-)

diff --git a/lib/Perl/Tidy/Formatter.pm b/lib/Perl/Tidy/Formatter.pm
index 66722a55..daa6b714 100644
--- a/lib/Perl/Tidy/Formatter.pm
+++ b/lib/Perl/Tidy/Formatter.pm
@@ -554,6 +554,7 @@ BEGIN {
         _do_not_pad_                 => $i++,
         _peak_batch_size_            => $i++,
         _batch_count_                => $i++,
+        _rix_seqno_controlling_ci_   => $i++,
         _batch_CODE_type_            => $i++,
         _ri_starting_one_line_block_ => $i++,
         _runmatched_opening_indexes_ => $i++,
@@ -15632,8 +15633,9 @@ EOM
         #--------------------------------------------------
         elsif ( !$max_index_to_go && $types_to_go[0] eq '#' ) {
             my $ibeg = 0;
-            $this_batch->[_ri_first_] = [$ibeg];
-            $this_batch->[_ri_last_]  = [$ibeg];
+            $this_batch->[_ri_first_]                 = [$ibeg];
+            $this_batch->[_ri_last_]                  = [$ibeg];
+            $this_batch->[_rix_seqno_controlling_ci_] = [];
 
             $self->convey_batch_to_vertical_aligner();
 
@@ -16103,15 +16105,12 @@ EOM
             $this_batch->[_do_not_pad_] = $do_not_pad;
         }
 
-        if ( @{$ri_first} > 1 || $rOpts_extended_continuation_indentation ) {
-            $self->undo_ci( $ri_first, $ri_last, \@ix_seqno_controlling_ci );
-        }
-
         #--------------------
         # ship this batch out
         #--------------------
-        $this_batch->[_ri_first_] = $ri_first;
-        $this_batch->[_ri_last_]  = $ri_last;
+        $this_batch->[_ri_first_]                 = $ri_first;
+        $this_batch->[_ri_last_]                  = $ri_last;
+        $this_batch->[_rix_seqno_controlling_ci_] = \@ix_seqno_controlling_ci;
 
         $self->convey_batch_to_vertical_aligner();
 
@@ -23851,6 +23850,11 @@ sub convey_batch_to_vertical_aligner {
           $self->add_closing_side_comment( $ri_first, $ri_last );
     }
 
+    if ( $n_last_line > 0 || $rOpts_extended_continuation_indentation ) {
+        $self->undo_ci( $ri_first, $ri_last,
+            $this_batch->[_rix_seqno_controlling_ci_] );
+    }
+
     # for multi-line batches ...
     if ( $n_last_line > 0 ) {
 
-- 
2.39.5