Skip to content

Commit

Permalink
ios/iphone: autoreplace smart-quotes with sane quotes,
Browse files Browse the repository at this point in the history
as the iphone keyboard is not able to produce ' or "
  • Loading branch information
9001 committed Aug 31, 2023
1 parent 0a0364e commit 1c0d978
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 4 deletions.
8 changes: 4 additions & 4 deletions copyparty/web/browser.js
Original file line number Diff line number Diff line change
Expand Up @@ -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') {
Expand Down Expand Up @@ -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 : '(*)'));
Expand All @@ -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)
Expand Down Expand Up @@ -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 }));
}

Expand Down
11 changes: 11 additions & 0 deletions copyparty/web/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -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++) {
Expand Down Expand Up @@ -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)) + ''));
Expand Down

0 comments on commit 1c0d978

Please sign in to comment.