to handle folded lines use
```js
var sel = editor.selection
var range = sel.getRange()
var newRange = sel.getLineRange(range.start.row)
if (range.isMultiLine())
    newRange.end = sel.getLineRange(range.end.row).end
sel.setRange(newRange)
```