From c5fbbbbb5c294559a5832ba668fdcc4c3ef0a9b8 Mon Sep 17 00:00:00 2001 From: ed Date: Fri, 17 Sep 2021 01:36:06 +0200 Subject: [PATCH] show current line number in md-editor --- copyparty/web/md.css | 4 ++++ copyparty/web/md.html | 1 + copyparty/web/md2.js | 36 ++++++++++++++++++++++++++++++++++++ docs/notes.sh | 6 ++---- srv/test.md | 16 +++++++++++----- 5 files changed, 54 insertions(+), 9 deletions(-) diff --git a/copyparty/web/md.css b/copyparty/web/md.css index 39a9b1d7..495de5a7 100644 --- a/copyparty/web/md.css +++ b/copyparty/web/md.css @@ -212,6 +212,10 @@ blink { #toolsbox a+a { text-decoration: none; } + #lno { + position: absolute; + right: 0; + } diff --git a/copyparty/web/md.html b/copyparty/web/md.html index e38c069d..a4b482bf 100644 --- a/copyparty/web/md.html +++ b/copyparty/web/md.html @@ -26,6 +26,7 @@ non-ascii: whitelist help + L# {%- else %} edit (basic) edit (fancy) diff --git a/copyparty/web/md2.js b/copyparty/web/md2.js index 42f22553..899f0022 100644 --- a/copyparty/web/md2.js +++ b/copyparty/web/md2.js @@ -875,6 +875,40 @@ function cfg_uni(e) { } +var set_lno = (function () { + var t = null, + pi = null, + pv = null, + lno = ebi('lno'); + + function poke() { + clearTimeout(t); + t = setTimeout(fire, 20); + } + + function fire() { + try { + clearTimeout(t); + + var i = dom_src.selectionStart; + if (i === pi) + return; + + var v = 'L' + dom_src.value.slice(0, i).split('\n').length; + if (v != pv) + lno.innerHTML = v; + + pi = i; + pv = v; + } + catch (e) { } + } + + timer.add(fire); + return poke; +})(); + + // hotkeys / toolbar (function () { function keydown(ev) { @@ -893,6 +927,8 @@ function cfg_uni(e) { if (document.activeElement != dom_src) return true; + set_lno(); + if (ctrl(ev)) { if (ev.code == "KeyH" || kc == 72) { md_header(ev.shiftKey); diff --git a/docs/notes.sh b/docs/notes.sh index a4063842..aa3df7c2 100644 --- a/docs/notes.sh +++ b/docs/notes.sh @@ -79,10 +79,8 @@ command -v gdate && date() { gdate "$@"; }; while true; do t=$(date +%s.%N); (ti # get all up2k search result URLs var t=[]; var b=document.location.href.split('#')[0].slice(0, -1); document.querySelectorAll('#u2tab .prog a').forEach((x) => {t.push(b+encodeURI(x.getAttribute("href")))}); console.log(t.join("\n")); -# rename all selected songs to + + <extension> -var sel=msel.getsel(), ci=find_file_col('Title')[0], re=[]; for (var a=0; a<sel.length; a++) { var url=sel[a].vp, tag=ebi(sel[a].id).closest('tr').querySelectorAll('td')[ci].textContent, name=uricom_dec(vsplit(url)[1])[0], m=/^([0-9]+[\. -]+)?.*(\.[^\.]+$)/.exec(name), name2=(m[1]||'')+tag+m[2], url2=vsplit(url)[0]+uricom_enc(name2,false); if (url!=url2) re.push([url, url2]); } -console.log(JSON.stringify(re, null, ' ')); -function f() { if (!re.length) return treectl.goto(get_evpath()); var [u1,u2] = re.shift(); fetch(u1+'?move='+u2).then((rsp) => {if (rsp.ok) f(); }); }; f(); +# debug md-editor line tracking +var s=mknod('style');s.innerHTML='*[data-ln]:before {content:attr(data-ln)!important;color:#f0c;background:#000;position:absolute;left:-1.5em;font-size:1rem}';document.head.appendChild(s); ## ## bash oneliners diff --git a/srv/test.md b/srv/test.md index 7338b982..05affa33 100644 --- a/srv/test.md +++ b/srv/test.md @@ -1,11 +1,17 @@ ### hello world * qwe -* asd - * zxc - * 573 - * one - * two +* rty +* uio + * asd + * fgh + * jkl + * zxc + * vbn + * 573 + * one + * two + * three * ||| |--|--|