@@ -2992,11 +2992,41 @@ command scriptFormat pScope, pDontGroup
29922992 local tOldText
29932993 put the text of field "Script" of me into tOldText
29942994
2995+ local tFirstLine , tLastLine , tCharsAboveFirstLineOld , tCharsAboveLastLineOld
2996+ get the selectedLine
2997+ put word 2 of it into tFirstLine
2998+ if word 4 of it is a number then put word 4 of it into tLastLine else put tFirstLine into tLastLine
2999+
3000+ put the number of chars of line 1 to tFirstLine of tOldText into tCharsAboveFirstLineOld
3001+ if tFirstLine is tLastLine then
3002+ put tCharsAboveFirstLineOld into tCharsAboveLastLineOld
3003+ else
3004+ put the number of chars of line 1 to tLastLine of tOldText into tCharsAboveLastLineOld
3005+ end if
3006+
29953007 local tNewText
29963008 put textFormatSelection(tOldText ) into tNewText
3009+
3010+ local tCharsAboveFirstLineNew , tCharsAboveLastLineNew , tDiffFirstLine , tDiffLastLine
3011+ put the number of chars of line 1 to tFirstLine of tNewText into tCharsAboveFirstLineNew
3012+ if tFirstLine is tLastLine then
3013+ put tCharsAboveFirstLineNew into tCharsAboveLastLineNew
3014+ else
3015+ put the number of chars of line 1 to tLastLine of tNewText into tCharsAboveLastLineNew
3016+ end if
3017+
3018+ put tCharsAboveFirstLineOld - tCharsAboveFirstLineNew into tDiffFirstLine
3019+ put tCharsAboveLastLineOld - tCharsAboveLastLineNew into tDiffLastLine
3020+
3021+ local tFirstLineChar
3022+ put (the number of chars of line 1 to tFirstLine - 1 of tNewText ) + 1 into tFirstLineChar
3023+
29973024 textReplace tStartChar , tOldText , tNewText , empty , pDontGroup
29983025
29993026 if tStart is not empty then
3027+ subtract tDiffFirstLine from tStart
3028+ put max (tStart , tFirstLineChar ) into tStart # dont let selection go into previous line
3029+ subtract tDiffLastLine from tEnd
30003030 select char tStart to tEnd of field "Script" of me
30013031 end if
30023032
0 commit comments