From 1c0d978979a703edeb792e552b18d3b7695b2d90 Mon Sep 17 00:00:00 2001 From: ed Date: Thu, 31 Aug 2023 19:29:37 +0000 Subject: [PATCH] ios/iphone: autoreplace smart-quotes with sane quotes, as the iphone keyboard is not able to produce ' or " --- copyparty/web/browser.js | 8 ++++---- copyparty/web/util.js | 11 +++++++++++ 2 files changed, 15 insertions(+), 4 deletions(-) diff --git a/copyparty/web/browser.js b/copyparty/web/browser.js index 5781b6e4..c4080027 100644 --- a/copyparty/web/browser.js +++ b/copyparty/web/browser.js @@ -4962,7 +4962,7 @@ document.onkeydown = function (e) { search_in_progress = 0; function ev_search_input() { - var v = this.value, + var v = unsmart(this.value), id = this.getAttribute('id'); if (id.slice(-1) == 'v') { @@ -4999,7 +4999,7 @@ document.onkeydown = function (e) { if (search_in_progress) return; - var q = ebi('q_raw').value, + var q = unsmart(ebi('q_raw').value), vq = ebi('files').getAttribute('q_raw'); srch_msg(false, (q == vq) ? '' : L.sm_prev + (vq ? vq : '(*)')); @@ -5011,7 +5011,7 @@ document.onkeydown = function (e) { for (var b = 1; b < sconf[a].length; b++) { var k = sconf[a][b][0], chk = 'srch_' + k + 'c', - vs = ebi('srch_' + k + 'v').value, + vs = unsmart(ebi('srch_' + k + 'v').value), tvs = []; if (a == 1) @@ -5104,7 +5104,7 @@ document.onkeydown = function (e) { xhr.setRequestHeader('Content-Type', 'text/plain'); xhr.onload = xhr.onerror = xhr_search_results; xhr.ts = Date.now(); - xhr.q_raw = ebi('q_raw').value; + xhr.q_raw = unsmart(ebi('q_raw').value); xhr.send(JSON.stringify({ "q": xhr.q_raw, "n": cap })); } diff --git a/copyparty/web/util.js b/copyparty/web/util.js index 2ecab4b1..c43cb7b1 100644 --- a/copyparty/web/util.js +++ b/copyparty/web/util.js @@ -369,6 +369,15 @@ function import_js(url, cb) { } +function unsmart(txt) { + return !IPHONE ? txt : (txt. + replace(/[\u2014]/g, "--"). + replace(/[\u2022]/g, "*"). + replace(/[\u2018\u2019]/g, "'"). + replace(/[\u201c\u201d]/g, '"')); +} + + var crctab = (function () { var c, tab = []; for (var n = 0; n < 256; n++) { @@ -1654,6 +1663,8 @@ function repl(e) { if (!cmd) return toast.inf(3, 'eval aborted'); + cmd = unsmart(cmd); + if (cmd.startsWith(',')) { evalex_fatal = true; return modal.alert(esc(eval(cmd.slice(1)) + ''));