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

Commit 80a7f28

Browse files
Merge pull request #2016 from BerndN/patch-6
[Bug 21721] Keep Selection when formatting handler
2 parents 9bc5257 + 8ad18f4 commit 80a7f28

2 files changed

Lines changed: 16 additions & 5 deletions

File tree

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

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3084,7 +3084,7 @@ command scriptFormat pScope, pDontGroup
30843084
if tStart > tEnd then
30853085
put tOldFirstIndent into tOldLastIndent
30863086
else
3087-
put textFormatGetLineIndent(line (tLine + tSelectionLineCount) of tScript) into tOldLastIndent
3087+
put textFormatGetLineIndent(line (tLine + tSelectionLineCount - 1) of tScript) into tOldLastIndent
30883088
end if
30893089

30903090
local tCode
@@ -3111,17 +3111,27 @@ command scriptFormat pScope, pDontGroup
31113111
# The selection offsets are composed of two parts, the difference in the indent of the line that the selection started / ended on
31123112
# and the difference in the number of chars before that line.
31133113
local tFirstSelectionOffset
3114-
put (the number of chars of tNewFirstIndent - the number of chars of tOldFirstIndent) + (the number of chars of line 1 to (tLine - 1) of tNewScript - the number of chars of line 1 to (tLine - 1) of tScript) into tFirstSelectionOffset
3114+
put (the number of chars of line 1 to tLine of tNewScript - the number of chars of line 1 to tLine of tScript) into tFirstSelectionOffset
3115+
3116+
put (the number of chars of line 1 to tLine - 1 of tNewScript) + 2 into tFirstLineChar
3117+
if tLine is 1 then subtract 1 from tFirstLineChar
31153118

31163119
local tLastSelectionOffset
31173120
if tStart > tEnd then
31183121
put tFirstSelectionOffset into tLastSelectionOffset
31193122
else
3120-
put (the number of chars of tNewLastIndent - the number of chars of tOldLastIndent) + (the number of chars of line 1 to (tLine + tSelectionLineCount) of tNewScript - the number of chars of line 1 to (tLine + tSelectionLineCount) of tScript) into tLastSelectionOffset
3121-
end if
3123+
put(the number of chars of line 1 to (tLine + (tSelectionLineCount - 1)) of tNewScript - the number of chars of line 1 to (tLine + (tSelectionLineCount - 1)) of tScript) into tLastSelectionOffset end if
31223124

31233125
if tStart is not empty then
3124-
select char (tStart + tFirstSelectionOffset) to (tEnd + tLastSelectionOffset) of field "Script" of me
3126+
if tStart > tEnd then
3127+
select char (tStart + tFirstSelectionOffset ) to (tEnd + tFirstSelectionOffset ) of field "Script" of me
3128+
else
3129+
put tStart + tFirstSelectionOffset into tStart
3130+
if tStart < tFirstLineChar + (the number of chars of tNewFirstIndent) then
3131+
put tFirstLineChar + (the number of chars of tNewFirstIndent) into tStart
3132+
end if
3133+
select char (tStart) to (tEnd + tLastSelectionOffset) of field "Script" of me
3134+
end if
31253135
end if
31263136
end if
31273137

notes/bugfix-21721.md

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

0 commit comments

Comments
 (0)