sc ide: fix and improve region detection

* Previously, the closing bracket's position was checked twice instead of
  checking the opening bracket.

* Relax opening bracket condition: it should be the first token on line,
  but may be followed by other tokens.

* Relax closing bracket condition: it should be either the last token on
  line or followed by ';'.