Document selection "lost" in filemanager when a filter is applied #3253

Closed
robertogerola opened this Issue Aug 18, 2015 · 6 comments

Projects

None yet

3 participants

@robertogerola

Scenario :
WYSIWYG text area, click the image button, click in the input filter
At this point the original document selection is gone and the filemanager doesn't know where to insert the image.

Solution :
Add this code in admin/view/common.js file

var document_selection;

function saveSelection() {
    if (window.getSelection) {
        sel = window.getSelection();
        if (sel.getRangeAt && sel.rangeCount) {
            return sel.getRangeAt(0);
        }
    } else if (document.selection && document.selection.createRange) {
        return document.selection.createRange();
    }
    return null;
}

function restoreSelection(range) {
    if (range) {
        if (window.getSelection) {
            sel = window.getSelection();
            sel.removeAllRanges();
            sel.addRange(range);
        } else if (document.selection && range.select) {
            range.select();
        }
    }
}

In the same file at the beginning of the function

$(document).delegate('button[data-toggle=\'image\']', 'click', function() {

add

document_selection = saveSelection();

In file admin/view/filemanager.tpl
in function

$('a.thumbnail').on('click', function(e) {

before

var range, sel = document.getSelection(); 

add

restoreSelection(document_selection);
@danielkerr
Contributor

great possible fix for something i can not replicate.

maybe if you gave a better description and details of browser used. possibly even a video.

@danielkerr
Contributor

ok i see. you mean the image manager search text field

@danijelGombac
Contributor

Confirm this in OC demo page wtih Firefox 40.0.2. If click in search input field in filemaneger then you can't add image to summernote editor.

@danielkerr
Contributor

@GomDani

did you read where i said

"ok i see. you mean the image manager search text field"

no need for confirmation

@danijelGombac
Contributor

I didn't see your second message when i started writing.

@danielkerr
Contributor

sorry.

this fix does not seem to work

@danielkerr danielkerr added a commit that referenced this issue Aug 19, 2015
@danielkerr danielkerr #3253 15d4bf2
@danielkerr danielkerr closed this Aug 19, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment