Fix issue with truncated queries and prevent copying queries > 1Mb to clipboard

This commit is contained in:
Lionel Laffineur 2023-09-10 20:47:47 +02:00 committed by Gerry Demaret
parent 9d25eff31f
commit ecbbe8de33
3 changed files with 26 additions and 8 deletions

View file

@ -97,7 +97,7 @@ if (!$error && $_POST) {
$empty = false;
$q = substr($query, 0, $pos);
$commands++;
$print = "<pre id='sql-$commands'><code class='jush-$jush copy-to-clipboard'>" . $adminer->sqlCommandQuery($q) . "</code></pre>\n";
$print = "<pre id='sql-$commands'><code class='jush-$jush'>" . $adminer->sqlCommandQuery($q) . "</code></pre>\n";
$print .= generate_linksbar(["<a href='#' class='copy-to-clipboard'>" . lang('Copy to clipboard') . "</a>"]);
if ($jush == "sqlite" && preg_match("~^$space*+ATTACH\\b~i", $q, $match)) {
// PHP doesn't support setting SQLITE_LIMIT_ATTACHED

View file

@ -93,6 +93,7 @@ span.separator { margin-left: 5px; margin-right: 5px; }
#schema .table { border: 1px solid silver; padding: 0 2px; cursor: move; position: absolute; }
#schema .references { position: absolute; }
#help { position: absolute; border: 1px solid #999; background: #eee; padding: 5px; font-family: monospace; z-index: 1; }
a.copy-to-clipboard.icon { font-size: 0; padding: 12px 8px 5px 8px; margin-left: 5px; background-size: 16px; background-repeat: no-repeat; background-position: 0 0; background-color: transparent; background-image: url('data:image/svg+xml;utf-8,<svg xmlns="http://www.w3.org/2000/svg" class="icon icon-tabler icon-tabler-clipboard-copy" width="24" height="24" viewBox="0 0 24 24" stroke-width="2" stroke="currentColor" fill="none" stroke-linecap="round" stroke-linejoin="round"><path stroke="none" d="M0 0h24v24H0z" fill="none"></path><path d="M9 5h-2a2 2 0 0 0 -2 2v12a2 2 0 0 0 2 2h3m9 -9v-5a2 2 0 0 0 -2 -2h-2"></path><path d="M13 17v-1a1 1 0 0 1 1 -1h1m3 0h1a1 1 0 0 1 1 1v1m0 3v1a1 1 0 0 1 -1 1h-1m-3 0h-1a1 1 0 0 1 -1 -1v-1"></path><path d="M9 3m0 2a2 2 0 0 1 2 -2h2a2 2 0 0 1 2 2v0a2 2 0 0 1 -2 2h-2a2 2 0 0 1 -2 -2z"></path></svg>'); }
.rtl h2 { margin: 0 -18px 20px 0; }
.rtl p, .rtl table, .rtl .error, .rtl .message { margin: 1em 0 0 20px; }

View file

@ -868,7 +868,13 @@ function setupCopyToClipboard(document) {
var node = document.querySelector("a.copy-to-clipboard");
if (node) {
node.addEventListener("click", function() {
copyToClipboard(document.querySelector("code.copy-to-clipboard"));
var nodeSql = document.querySelector("code.copy-to-clipboard");
if (nodeSql == null || nodeSql == undefined) {
nodeSql = document.querySelector("textarea.sqlarea");
}
if (nodeSql != null && nodeSql != undefined) {
copyToClipboard(nodeSql);
}
});
}
}
@ -877,12 +883,23 @@ function setupCopyToClipboard(document) {
* @param HTMLElement
*/
function copyToClipboard(el) {
var range = document.createRange();
range.selectNode(el);
window.getSelection().removeAllRanges();
window.getSelection().addRange(range);
document.execCommand("copy");
window.getSelection().removeAllRanges();
var nodeName = el.nodeName.toLowerCase();
if (nodeName == 'code') {
var range = document.createRange();
range.selectNode(el);
window.getSelection().removeAllRanges();
window.getSelection().addRange(range);
document.execCommand("copy");
window.getSelection().removeAllRanges();
} else if (nodeName == 'textarea') {
el.select();
if (document.getSelection().toString().length > 1024 * 1024) {
alert('Too large for clipboard');
} else {
document.execCommand("copy");
document.getSelection().removeAllRanges();
}
}
}
/** Add event listener