private Location buildNewSourceLocationFromHighlight(final SourceLocation sourceLocation,
                                                         final DataRange highlight,
                                                         final SourceConfig sourceConfig) {
        final Location newSourceStart;
        final Location highlightStart = highlight.getLocationFrom();

        // If we are stepping backwards then this highlight will be before the last one we
        // requested. If we don't have previous data then treat it like stepping forward.
        final boolean isHighlightMovingBackwards = isHighlightMovingBackwards(
                sourceLocation,
                requestedSourceLocation);

        final Optional<Integer> optCurrLineCount = Optional.ofNullable(receivedSourceLocation)
                .flatMap(SourceLocation::getOptDataRange)
                .flatMap(DataRange::getLineCount);

        if (optCurrLineCount
                .filter(i -> i == 1)
                .isPresent()
                && highlight.getAsTextRange().filter(TextRange::isOnOneLine).isPresent()
                && highlightStart.getColNo() > HIGHLIGHT_CONTEXT_CHARS_BEFORE) {

            // single line data and highlight
            final int newColNo;
            if (isHighlightMovingBackwards
                    && receivedSourceLocation.getDataRange() != null
                    && receivedSourceLocation.getDataRange().getOptLength().isPresent()) {
                // try and show just under a fetch's worth of data before
                final int highlightLen = highlight.getLocationTo().getColNo()
                        - highlight.getLocationFrom().getColNo()
                        + 1;
                newColNo = (int) (highlightStart.getColNo()
                        - sourceConfig.getMaxCharactersPerFetch()
                        + highlightLen
//                        - receivedSourceLocation.getDataRange().getLength()
                        + HIGHLIGHT_CONTEXT_CHARS_BEFORE);
            } else {
                // we need to change the visible range
                // to be some chars before the highlight to provide the user some context
                newColNo = highlightStart.getColNo() - HIGHLIGHT_CONTEXT_CHARS_BEFORE;
            }
            newSourceStart = DefaultLocation.of(1, Math.max(1, newColNo));
        } else if (highlightStart.getLineNo() > HIGHLIGHT_CONTEXT_LINES_BEFORE) {
            final int newLineNo;
            if (isHighlightMovingBackwards && optCurrLineCount.isPresent()) {
                // try and show just under a fetch's worth of data before
                newLineNo = highlightStart.getLineNo()
                        - optCurrLineCount.get()
                        + HIGHLIGHT_CONTEXT_LINES_BEFORE;
            } else {
                // Adjust the visible data range to be a few lines before the highlight
                // so the user has some context
                newLineNo = highlightStart.getLineNo() - HIGHLIGHT_CONTEXT_LINES_BEFORE;
            }
            newSourceStart = DefaultLocation.of(Math.max(1, newLineNo), 1);
        } else {
            // Shouldn't really come in here but just display from the start just in case
            newSourceStart = DefaultLocation.of(1, 1);
        }

//        GWT.log("Highlight: " + highlight.toString()
//                + " new start: " + newSourceStart.toString());
        return newSourceStart;
    }
Will attempt to set the source range using the passed highlight, i.e. if the highlight
is towards the end of the data then it will set the range to enclose the highlight.
stroom-core-client/src/main/java/stroom/data/client/presenter/SourcePresenter.java