Home
Options

Feature request: Results double-clickable

The title says it all.

Just like in the query/code section I would like double click VS behaviour (or even triple click VS behaviour)

1 double click to select the /w
2 triple click to select between the last /n and the next /n

Is there another forum to post feature requests? github? can we contribute to the code base? or write an extension?

Comments

  • Options

    This is a bug in the WebBrowser control that Microsoft refuse to fix. I've spent hours exploring various workarounds, but none of them are reliable.

  • Options

    The JS suggestion on that thread seems to work. If you'd like to test it more, add the following code to your My Extensions query in LINQPad 6:

    public class Fix
    {
        public static void Doubleclick()
        {
            Util.HtmlHead.AddScript (@"// function to get mouse position relative to the container
    var getMousePosition = function (container, mouseEvent) {
        var currentObject = container;
        var currentLeft = 0;
        var currentTop = 0;
        while (currentObject != document.body) {
            currentLeft += currentObject.offsetLeft;
            currentTop += currentObject.offsetTop;
            currentObject = currentObject.offsetParent;
        }
        return {
            x: mouseEvent.pageX - currentLeft,
            y: mouseEvent.pageY - currentTop
        }
    }
    
    var clickCounter;
    var clickPosition;
    var resetClick = function () {
        clickCounter = 0;
        clickPosition = {
            x: null,
            y: null
        };
    };
    resetClick();
    var clickTimer;
    
    // function to wait for the next click, and reset click details if time elapses
    var conserveClick = function (mousePosition) {
        clickPosition = mousePosition;
        clearTimeout(clickTimer);
        clickTimer = setTimeout(resetClick, 250); // NOTE: that this does mean that the double click speed is defined by the javascript, NOT the system settings...
        clickCounter++;
    };
    
    var findClickedText = function (parentElement, x, y, paragraph) {
        var range = document.createRange();
        for (var child = 0; child < parentElement.childNodes.length; child++) {
            var textElement = parentElement.childNodes[child];
    
            var texts = paragraph ? [textElement.textContent] : textElement.textContent.split(/\W/);
            var start = 0;
            for (var index in texts) {
                var check = texts[index];
                var end = start + check.length;
                range.setStart(textElement, start);
                range.setEnd(textElement, end);
                var rects = range.getClientRects(); // don't use getBoundingClientRect as text could wrap
                var clickedRect = isClickInRects(rects);
                if (clickedRect) {
                    return [check, start, clickedRect, range, textElement];
                }
                start = end + 1;
            }
        }
    
        function isClickInRects (rects) {
            for (var index in rects) {
                var rect = rects[index];
                if (rect.left < x && rect.right > x && rect.top < y && rect.bottom > y) {            
                    return rect;
                }
            }
            return false;
        }
        return null;
    };
    
    var selectTextAtPosition = function (all, position) {
        var element = document.elementFromPoint(position.x, position.y);
        var result = findClickedText(element, position.x, position.y, all);
        if (result != null) {
            var selection = window.getSelection();
            selection.removeAllRanges();
            selection.addRange(result[3]);
        }
    };
    
    document.body.addEventListener('click', function (event) {
    
        // get the current mouse position
        var mousePosition = getMousePosition(document.body, event);
    
        // if first click or position has not changed
        if (clickCounter == 0 || (clickPosition.x == mousePosition.x && clickPosition.y == mousePosition.y)) {
            conserveClick(mousePosition);
    
            if (clickCounter > 1 && clickCounter < 4)
                selectTextAtPosition(clickCounter == 3, clickPosition);
        }
    });");
        }
    }
    

    To activate in a query, add this to the start:

    Fix.Doubleclick();

    Let me know if you run into any problems. I can look into make this the default if I know it won't cause issues.

Sign In or Register to comment.