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

Commit 4fa1b43

Browse files
Merge pull request #1892 from montegoulding/bugfix-20851
[[ Bug 20851 ]] Fix case/break completion
2 parents e7467d9 + 5149261 commit 4fa1b43

2 files changed

Lines changed: 19 additions & 0 deletions

File tree

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

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1807,6 +1807,11 @@ private function autoCompleteSearchContext @pScript, pLineNumber, pStructureType
18071807
return 1
18081808
end if
18091809

1810+
-- case can't be nested except within another switch so return 0
1811+
if pStructureType is "case" then
1812+
return 1
1813+
end if
1814+
18101815
local tDepth
18111816
put 0 into tDepth
18121817
repeat with x = pLineNumber down to 1
@@ -1854,6 +1859,19 @@ function autoCompleteCompletionRequired pLineNumber, pStructureType, pStructureN
18541859
# The structure is already completed
18551860
return false
18561861
end if
1862+
else if pStructureType is "case" then
1863+
# special case `case` so it behaves sensibly
1864+
if (token 1 of tLine is "end" and token 2 of tLine is "switch") or \
1865+
token 1 of tLine is "case" or \
1866+
token 1 of tLine is "default" then
1867+
# if the switch structure ends then we need a break
1868+
return true
1869+
else if token 1 of tLine is not empty then
1870+
# if there's existing code within the case then we
1871+
# can reasonably assume that they don't want to put a break
1872+
# above it
1873+
return false
1874+
end if
18571875
else if token 1 of tLine is "end" and token 2 of tLine is not among the items of autoCompleteUnnamedStructures() and token 2 of tLine is not "if" then
18581876
# If a named structure is ending, but it doesn't match the structure we are looking for
18591877
# then if the structure we're looking for is un-named, we return true

notes/bugfix-20851.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
# Fix adding `break` after `case` in switch control structure when one exists

0 commit comments

Comments
 (0)