Skip to content
This repository was archived by the owner on Aug 31, 2021. It is now read-only.

Commit 146c12b

Browse files
Merge pull request #1940 from BerndN/patch-2
[Bug 21086] Keep correct selection when formatting script
2 parents 8f2dee9 + afd8db2 commit 146c12b

File tree

2 files changed

+31
-0
lines changed

2 files changed

+31
-0
lines changed

Toolset/palettes/script editor/behaviors/revsecommoneditorbehavior.livecodescript

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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

notes/bugfix-21086.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
# Keep correct selection when formatting whole script

0 commit comments

Comments
 (0)