const $insertTags = function(target, tagOpen, tagClose) {
    tagOpen = tagOpen || '';
    tagClose = tagClose || '';

    if(document.selection) {
        target.focus();
        const selected = document.selection.createRange();
        selected.text = tagOpen + selected.text + tagClose;
        target.focus();
    } else if(target.selectionStart || target.selectionStart === 0) {
        const startPos = target.selectionStart,
            endPos = target.selectionEnd,
            scrollTop = target.scrollTop;

        target.value = target.value.substring(0, startPos)
            + tagOpen
            + target.value.substring(startPos, endPos)
            + tagClose
            + target.value.substring(endPos, target.value.length);

        target.focus();
        target.selectionStart = startPos + tagOpen.length;
        target.selectionEnd = endPos + tagOpen.length;
        target.scrollTop = scrollTop;
    } else {
        target.value += tagOpen + tagClose;
        target.focus();
    }
};