diff --git a/library/tedit/TEDIT-FIND b/library/tedit/TEDIT-FIND
index aa4d5ab1..12414eb6 100644
--- a/library/tedit/TEDIT-FIND
+++ b/library/tedit/TEDIT-FIND
@@ -1,12 +1,12 @@
 (DEFINE-FILE-INFO PACKAGE "INTERLISP" READTABLE "INTERLISP" BASE 10)
 
-(FILECREATED "17-Feb-2025 12:25:36" {WMEDLEY}<library>tedit>TEDIT-FIND.;136 36884  
+(FILECREATED " 6-Mar-2025 20:18:04" {WMEDLEY}<library>TEDIT>TEDIT-FIND.;138 38227  
 
       :EDIT-BY rmk
 
-      :CHANGES-TO (FNS \TEDIT.BASICFIND)
+      :CHANGES-TO (FNS TEDIT.SUBSTITUTE)
 
-      :PREVIOUS-DATE "15-Feb-2025 18:08:55" {WMEDLEY}<library>tedit>TEDIT-FIND.;135)
+      :PREVIOUS-DATE "17-Feb-2025 12:25:36" {WMEDLEY}<library>TEDIT>TEDIT-FIND.;136)
 
 
 (PRETTYCOMPRINT TEDIT-FINDCOMS)
@@ -94,7 +94,8 @@
                          (CAR (\TEDIT.BASICFIND.BACKWARD TSTREAM TARGET START END))))])])
 
 (TEDIT.SUBSTITUTE
-  [LAMBDA (TSTREAM PATTERN REPLACEMENT CONFIRM?)             (* ; "Edited  8-Dec-2024 15:47 by rmk")
+  [LAMBDA (TSTREAM PATTERN REPLACEMENT CONFIRM?)             (* ; "Edited  6-Mar-2025 20:17 by rmk")
+                                                             (* ; "Edited  8-Dec-2024 15:47 by rmk")
                                                              (* ; "Edited 26-Nov-2024 23:49 by rmk")
                                                              (* ; "Edited 15-Aug-2024 09:20 by rmk")
                                                              (* ; "Edited 14-Jul-2024 00:24 by rmk")
@@ -123,11 +124,10 @@
 
              (* ;; "Don't call \TEDIT.GET.TARGET.STRING because it might pick the search-domain (current selection) as the search string.  If the search pattern is empty, bail out.")
 
-                  [CL:UNLESS (SETQ SEARCHSTRING (OR PATTERN (TEDIT.GETINPUT TEXTOBJ "Search string:"
-                                                                   (GETTEXTPROP TEXTOBJ 
-                                                                          '
-                                                                         TEDIT.LAST.SUBSTITUTE.STRING
-                                                                          ]
+                  (CL:UNLESS SEARCHSTRING
+                      [SETQ SEARCHSTRING (OR PATTERN (TEDIT.GETINPUT TEXTOBJ "Search string:"
+                                                            (GETTEXTPROP TEXTOBJ 
+                                                                   'TEDIT.LAST.SUBSTITUTE.STRING])
                   (CL:UNLESS [OR REPLACEMENT (SETQ REPLACEMENT (TEDIT.GETINPUT TEXTOBJ 
                                                                       "Replace string:"
                                                                       (GETTEXTPROP TEXTOBJ
@@ -137,16 +137,17 @@
                                                                              ]
                       (TEDIT.PROMPTPRINT TEXTOBJ "[Aborted]")
                       (RETURN))
-                  [RESETSAVE (\TEDIT.MARKACTIVE TEXTOBJ)
+                  [RESETSAVE (\TEDIT.MARKACTIVE TEXTOBJ "Substitute")
                          '(PROGN (\TEDIT.MARKINACTIVE OLDVALUE]
                   (if (type? SELPIECES REPLACEMENT)
                     elseif (OR (STRINGP REPLACEMENT)
                                (LITATOM REPLACEMENT))
-                      then (SETQ REPLACEMENT (\TEDIT.SELPIECES.FROM.STRING REPLACEMENT TEXTOBJ)))
+                      then (SETQ REPLACEMENT (\TEDIT.SELPIECES.FROM.STRING REPLACEMENT TEXTOBJ))
+                    else (RETURN NIL))
 
              (* ;; "Could be NIL or empty string, meaning just delete all occurrences.")
 
-                  (SETQ REPLACE-LEN (fetch (SELPIECES SPLEN) of REPLACEMENT))
+                  (SETQ REPLACE-LEN (GETSPC REPLACEMENT SPLEN))
                   (SETQ ACTIONSTRING (CL:IF (ZEROP REPLACE-LEN)
                                          "delet"
                                          "substitut"))
@@ -163,7 +164,7 @@
                   (TEDIT.PROMPTPRINT TEXTOBJ (CONCAT (L-CASE ACTIONSTRING T)
                                                     "ing...")
                          T)
-                  (SETQ SEL (fetch (TEXTOBJ SEL) of TEXTOBJ))
+                  (SETQ SEL (FGETTOBJ TEXTOBJ SEL))
                   (\TEDIT.SHOWSEL SEL NIL TEXTOBJ)
                   (\TEDIT.RESET.EXTEND.PENDING.DELETE TEXTOBJ)
                                                              (* ; "Turn off any blue pending delete")
@@ -174,31 +175,39 @@
                   [SETQ ENDCHAR# (CL:IF (ZEROP (GETSEL SEL DCH))
                                      (GETTOBJ TEXTOBJ TEXTLEN)
                                      (IPLUS STARTCHAR# (SUB1 (GETSEL SEL DCH))))]
+
+             (* ;; 
+             "NOTE:  SEARCHSTRING may contain wild cards, so the hits may be of different lengths.")
+
                   [if CONFIRMFLG
                       then 
                            (* ;; "In this case the selection moves along, ending up at the last hit.")
 
-                           [bind PENDING.SEL CHOICE while (SETQ RANGE (TEDIT.FIND TEXTOBJ 
-                                                                             SEARCHSTRING STARTCHAR#
-                                                                             ENDCHAR# T))
+                           (bind (LASTSEL _ (\TEDIT.COPYSEL SEL))
+                              while (SETQ RANGE (TEDIT.FIND TEXTOBJ SEARCHSTRING STARTCHAR# ENDCHAR#
+                                                       T))
                               do                             (* ; 
                                                  "Show each substitution site and ask for permission")
-                                 (SETQ PENDING.SEL (TEDIT.SETSEL TEXTOBJ (CAR RANGE)
-                                                          (ADD1 (IDIFFERENCE (CADR RANGE)
-                                                                       (CAR RANGE)))
-                                                          'RIGHT T))
-                                 (\TEDIT.SHOWSEL PENDING.SEL T TEXTOBJ)
-                                 (TEDIT.NORMALIZECARET TEXTOBJ PENDING.SEL)
-                                 (SELECTQ (U-CASE (NTHCHAR (TEDIT.GETINPUT TEXTOBJ 
+                                 (\TEDIT.UPDATE.SEL SEL (CAR RANGE)
+                                        NIL
+                                        'RIGHT
+                                        'PENDINGDEL
+                                        (ADD1 (CADR RANGE)))
+                                 (\TEDIT.FIXSEL SEL TEXTOBJ)
+                                 (\TEDIT.SHOWSEL SEL T TEXTOBJ)
+                                 (TEDIT.NORMALIZECARET TEXTOBJ SEL)
+                                 [SELECTQ (U-CASE (NTHCHAR (TEDIT.GETINPUT TEXTOBJ 
                                                                   "OK to replace? ['q' quits]" "Yes")
                                                          1))
-                                     (Q (RETURN))
+                                     (Q (GO $$OUT))
                                      (Y                      (* ; "Do this one")
                                         (\TEDIT.REPLACE.SELPIECES (\TEDIT.SELPIECES.COPY REPLACEMENT
                                                                          'COPY TEXTOBJ)
-                                               TEXTOBJ PENDING.SEL)
+                                               TEXTOBJ SEL)
+                                        (\TEDIT.COPYSEL SEL LASTSEL)
+                                                             (* ; "This may be where we end up")
                                         (add NREPLACEMENTS 1)
-                                        (SETQ STARTCHAR# (GETSEL PENDING.SEL CHLIM))
+                                        (SETQ STARTCHAR# (GETSEL SEL CHLIM))
                                                              (* ; "Next start, compensate for end")
                                         [add ENDCHAR# (IDIFFERENCE REPLACE-LEN
                                                              (ADD1 (IDIFFERENCE (CADR RANGE)
@@ -207,13 +216,13 @@
                                             (* ;; 
     "Turn off rejected selection, search for next starting one charcter later. ENDCHAR# is still OK.")
 
-                                            (\TEDIT.SHOWSEL PENDING.SEL NIL TEXTOBJ)
+                                            (\TEDIT.SHOWSEL SEL NIL TEXTOBJ)
                                             (SETQ STARTCHAR# (ADD1 (CAR RANGE]
+                              finally (\TEDIT.COPYSEL LASTSEL SEL))
                     else 
                          (* ;; "No confirmation required.  Do the substitutions without showing intermediate work, collect all of the replacement events")
 
                          (bind FIRSTHIT HITLAST HITLEN HITDIFF (TOTALDIFF _ 0)
-                               (SAVESEL _ (\TEDIT.COPYSEL SEL))
                                EVENTS while (SETQ RANGE (TEDIT.FIND TEXTOBJ SEARCHSTRING STARTCHAR# 
                                                                ENDCHAR# T))
                             do (CL:UNLESS FIRSTHIT           (* ; "For final line updating.")
@@ -238,12 +247,21 @@
                                (add TOTALDIFF HITDIFF)
                             finally (CL:UNLESS (EQ NREPLACEMENTS 0)
 
-                                        (* ;; 
-                                      "At least one replacement, update the lines that have changed.")
+                                 (* ;; "At least one replacement, update the lines that have changed.  We have to calculate how many of the original characters have %"changed%" by adding the TOTALDIFF to the final position of the last character of the last hit.  Might be better if UPDATELINES took a lastchangechar.")
 
-                                        (\TEDIT.UPDATE.LINES TEXTOBJ 'INSERTION FIRSTHIT
-                                               (IDIFFERENCE (GETSEL SEL CHLIM)
-                                                      FIRSTHIT))
+                                        (if (IGREATERP TOTALDIFF 0)
+                                            then (\TEDIT.UPDATE.LINES TEXTOBJ 'INSERTION FIRSTHIT
+                                                        (IDIFFERENCE (IPLUS (FGETSEL SEL CHLIM)
+                                                                            TOTALDIFF)
+                                                               FIRSTHIT))
+                                          elseif (ILESSP TOTALDIFF 0)
+                                            then (\TEDIT.UPDATE.LINES TEXTOBJ 'DELETION FIRSTHIT
+                                                        (IDIFFERENCE (IDIFFERENCE (FGETSEL SEL CHLIM)
+                                                                            TOTALDIFF)
+                                                               FIRSTHIT))
+                                          else (\TEDIT.UPDATE.LINES TEXTOBJ 'CHANGED FIRSTHIT
+                                                      (IDIFFERENCE (FGETSEL SEL CHLIM)
+                                                             FIRSTHIT)))
 
                                  (* ;; "Not clear what the final selection should be, if there are multiple changes.  The original selection? A selection that goes from the beginning of the first subsitution to the end of the last (as here)?  Or just the selection of the last substitution?")
 
@@ -251,6 +269,7 @@
                                         (\TEDIT.UPDATE.SEL SEL FIRSTHIT (IDIFFERENCE HITLAST FIRSTHIT
                                                                                )
                                                'RIGHT)
+                                        (\TEDIT.FIXSEL SEL TEXTOBJ)
                                         (\TEDIT.HISTORYADD.COMPOSITE TEXTOBJ EVENTS))]
 
              (* ;; "Save the search & replacement strings to offer for next time:")
@@ -563,8 +582,8 @@
                                                     (DREVERSE $$VAL))])
 )
 (DECLARE%: DONTCOPY
-  (FILEMAP (NIL (784 22132 (TEDIT.FIND 794 . 2793) (TEDIT.FIND.BACKWARD 2795 . 5117) (TEDIT.SUBSTITUTE 
-5119 . 17479) (TEDIT.NEXT 17481 . 22130)) (22165 36861 (\TEDIT.WCFIND 22175 . 25694) (\TEDIT.BASICFIND
- 25696 . 28055) (\TEDIT.WCFIND.BACKWARD 28057 . 31521) (\TEDIT.BASICFIND.BACKWARD 31523 . 33780) (
-\TEDIT.PARSE.SEARCHSTRING 33782 . 36859)))))
+  (FILEMAP (NIL (784 23475 (TEDIT.FIND 794 . 2793) (TEDIT.FIND.BACKWARD 2795 . 5117) (TEDIT.SUBSTITUTE 
+5119 . 18822) (TEDIT.NEXT 18824 . 23473)) (23508 38204 (\TEDIT.WCFIND 23518 . 27037) (\TEDIT.BASICFIND
+ 27039 . 29398) (\TEDIT.WCFIND.BACKWARD 29400 . 32864) (\TEDIT.BASICFIND.BACKWARD 32866 . 35123) (
+\TEDIT.PARSE.SEARCHSTRING 35125 . 38202)))))
 STOP
diff --git a/library/tedit/TEDIT-FIND.LCOM b/library/tedit/TEDIT-FIND.LCOM
index 782de847..9bf6dd80 100644
Binary files a/library/tedit/TEDIT-FIND.LCOM and b/library/tedit/TEDIT-FIND.LCOM differ
