This is a bit scary. It will _probably_ work, but the timing may work out badly. The issue is asynchronous JavaScript. Effectively the `session.getSelectionText` and `session.getSelectionRange` calls will be executed simultaneously. In practice, the first will most likely return first, in case everything works fine. But if the second would, for some reason, return first things would break.

The fix is to nest the `session.getSelectionRange` inside of the callback function of `session.getSelectionText`, to the two happen in sequence:

```
session.getSelectionText(options.path, function(ignored, text) {
            if (text.slice(text.length - 1) == "\n") {
                chopped = true;
                text = text.substring(0, text.length - 1);
            }
            selected_lines = text.split("\n").sort();
            session.getSelectionRange(options.path, function(ignored, range) { ... });
        });
```