Bug: If text is highlighted in the editor, the query won't run

Server Version 7.4.4
If you have a current selection in your query and you click Run, the query won't run. For example, if I have "PREFIX" highlighted, I get the error message, "Failed to run query: QEQNF2: Stored query not found: PREFIX (Not Found)"

What you're encountering here is actually intended behavior; if you explicitly highlight text in a Studio editor and click the Run button, Studio will run just the text you highlighted. This feature is there to let the user tell Studio exactly what they want to have run, and it can be useful in cases where you want to see what a specific part of your query is doing without having to write it as a separate query. For example, you can run the sub-select (for getting the latest date) in the following query by itself by highlighting it:

PREFIX wd: <http://www.wikidata.org/entity/>
PREFIX wdt: <http://www.wikidata.org/prop/direct/>

SELECT ?countyName ?cases ?population ?percentCases 
    # get the latest date
    { SELECT (max(?d) as ?date) { ?r :date ?d } }

    # get all the reports for the latest date
        :cases ?cases  ;
        :date ?date ;                
        :county [
            rdfs:label ?countyName ;
            :fips ?fips

    # look up the population of the county from Wikidata using the FIPS code
    SERVICE <https://query.wikidata.org/sparql> 
            wdt:P1082 ?population ;
            wdt:P882 ?fips

    # compute percentages
    BIND(roundHalfToEven((?cases / ?population) * 100, 2) AS ?percentCases)
ORDER BY desc(?percentCases)

If you have additional feedback about this feature, we're happy to hear it! Arguably, there are at least ways that we can make the behavior more apparent.


Hmm, that's a tough one. The first thing that stands out to me is that the Command-Return keyboard shortcut is different than the Run button, so if you don't know about this feature (which I didn't until today) then it's hard to figure out what's going wrong and the first natural assumption is that it's a syntax error.

My first thought would be to change the label on the Run button when something is highlighted, but it would end up flashing during normal copy/paste operations. Alternatively, there could be a tooltip on the button that says "Run selected" like the contextual menu.

My other question would be to know if you've done any user research on how often that feature is intended to be used. If it truly is an advanced neat feature but not very many people use it then maybe the contextual menu is good enough. The balance is helping those who want an advanced but hidden feature versus users getting an error message and not understanding why.