fortrangoingonforty/fortsh / 76b7757

Browse files

fix prefix getting carried into tab completions

Authored by mfwolffe <wolffemf@dukes.jmu.edu>
SHA
76b7757b4a759620f775e6d3b76d210063d166a4
Parents
9893bac
Tree
35398c0

2 changed files

StatusFile+-
A .tool-versions 1 0
M src/io/readline.f90 36 14
.tool-versionsadded
@@ -0,0 +1,1 @@
1
+nodejs 24.9.0
src/io/readline.f90modified
@@ -843,11 +843,9 @@ contains
843843
     else
844844
       ! Complete files and directories
845845
       call complete_files_enhanced(last_word, completions, num_completions)
846
-      
847
-      ! Add prefix back to completions
848
-      do i = 1, num_completions
849
-        completions(i) = trim(prefix_part) // trim(completions(i))
850
-      end do
846
+
847
+      ! Don't add prefix to completions - they are for display only
848
+      ! The prefix will be added when constructing the completed line
851849
     end if
852850
   end subroutine
853851
 
@@ -1206,27 +1204,51 @@ contains
12061204
     integer, intent(out) :: num_completions
12071205
     character(len=*), intent(out) :: completed_line
12081206
     logical, intent(out) :: completed
1209
-    
1210
-    character(len=MAX_LINE_LEN) :: common_prefix
1211
-    
1207
+
1208
+    character(len=MAX_LINE_LEN) :: common_prefix, prefix_part
1209
+    integer :: last_space_pos, i
1210
+
12121211
     completed = .false.
12131212
     completed_line = partial_input
1214
-    
1213
+
1214
+    ! Find the prefix (command and any earlier arguments)
1215
+    last_space_pos = 0
1216
+    do i = len_trim(partial_input), 1, -1
1217
+      if (partial_input(i:i) == ' ') then
1218
+        last_space_pos = i
1219
+        exit
1220
+      end if
1221
+    end do
1222
+
1223
+    if (last_space_pos > 0) then
1224
+      prefix_part = partial_input(:last_space_pos)
1225
+    else
1226
+      prefix_part = ''
1227
+    end if
1228
+
12151229
     call enhanced_tab_complete(partial_input, completions, num_completions)
1216
-    
1230
+
12171231
     if (num_completions == 0) then
12181232
       ! No completions found
12191233
       return
12201234
     else if (num_completions == 1) then
1221
-      ! Single completion - use it
1222
-      completed_line = trim(completions(1))
1235
+      ! Single completion - add prefix back (preserve spacing)
1236
+      if (last_space_pos > 0) then
1237
+        completed_line = prefix_part(:last_space_pos) // trim(completions(1))
1238
+      else
1239
+        completed_line = trim(completions(1))
1240
+      end if
12231241
       completed = .true.
12241242
     else
12251243
       ! Multiple completions - try common prefix
12261244
       common_prefix = get_common_prefix(completions, num_completions)
1227
-      
1245
+
12281246
       if (len_trim(common_prefix) > 0) then
1229
-        completed_line = trim(common_prefix)
1247
+        if (last_space_pos > 0) then
1248
+          completed_line = prefix_part(:last_space_pos) // trim(common_prefix)
1249
+        else
1250
+          completed_line = trim(common_prefix)
1251
+        end if
12301252
         completed = .true.
12311253
       end if
12321254
     end if