show current line number in md-editor

This commit is contained in:
ed 2021-09-17 01:36:06 +02:00
parent 5010387d8a
commit c5fbbbbb5c
5 changed files with 54 additions and 9 deletions

View file

@ -212,6 +212,10 @@ blink {
#toolsbox a+a { #toolsbox a+a {
text-decoration: none; text-decoration: none;
} }
#lno {
position: absolute;
right: 0;
}

View file

@ -26,6 +26,7 @@
<a id="cfg_uni" href="#">non-ascii: whitelist</a> <a id="cfg_uni" href="#">non-ascii: whitelist</a>
<a id="help" href="#">help</a> <a id="help" href="#">help</a>
</div> </div>
<span id="lno">L#</span>
{%- else %} {%- else %}
<a href="?edit" tt="good: higher performance$Ngood: same document width as viewer$Nbad: assumes you know markdown">edit (basic)</a> <a href="?edit" tt="good: higher performance$Ngood: same document width as viewer$Nbad: assumes you know markdown">edit (basic)</a>
<a href="?edit2" tt="not in-house so probably less buggy">edit (fancy)</a> <a href="?edit2" tt="not in-house so probably less buggy">edit (fancy)</a>

View file

@ -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 // hotkeys / toolbar
(function () { (function () {
function keydown(ev) { function keydown(ev) {
@ -893,6 +927,8 @@ function cfg_uni(e) {
if (document.activeElement != dom_src) if (document.activeElement != dom_src)
return true; return true;
set_lno();
if (ctrl(ev)) { if (ctrl(ev)) {
if (ev.code == "KeyH" || kc == 72) { if (ev.code == "KeyH" || kc == 72) {
md_header(ev.shiftKey); md_header(ev.shiftKey);

View file

@ -79,10 +79,8 @@ command -v gdate && date() { gdate "$@"; }; while true; do t=$(date +%s.%N); (ti
# get all up2k search result URLs # 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")); 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 <leading-track-number> + <Title> + <extension> # debug md-editor line tracking
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]); } 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);
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();
## ##
## bash oneliners ## bash oneliners

View file

@ -1,11 +1,17 @@
### hello world ### hello world
* qwe * qwe
* asd * rty
* zxc * uio
* 573 * asd
* one * fgh
* two * jkl
* zxc
* vbn
* 573
* one
* two
* three
* ||| * |||
|--|--| |--|--|