diff --git a/.gitignore b/.gitignore index c5338832..be25b99f 100644 --- a/.gitignore +++ b/.gitignore @@ -11,14 +11,12 @@ dist/ sfx/ .venv/ -# sublime +# ide *.sublime-workspace # winmerge *.bak -# other licenses -contrib/ - -# deps -copyparty/web/deps \ No newline at end of file +# derived +copyparty/web/deps/ +srv/ diff --git a/copyparty/httpcli.py b/copyparty/httpcli.py index 371d6d56..919b0b5a 100644 --- a/copyparty/httpcli.py +++ b/copyparty/httpcli.py @@ -859,6 +859,7 @@ class HttpCli(object): file_ts = max(ts_md, ts_html) file_lastmod, do_send = self._chk_lastmod(file_ts) self.out_headers["Last-Modified"] = file_lastmod + self.out_headers["Cache-Control"] = "no-cache" status = 200 if do_send else 304 targs = { diff --git a/copyparty/web/md2.js b/copyparty/web/md2.js index f93b9296..5b6873be 100644 --- a/copyparty/web/md2.js +++ b/copyparty/web/md2.js @@ -287,12 +287,15 @@ function save_chk() { } -// returns [before,selection,after] -function getsel() { +// get selection bounds, expanded to whole lines +function linebounds(just_car) { var car = dom_src.selectionStart; var cdr = dom_src.selectionEnd; console.log(car, cdr); + if (just_car) + cdr = car; + var txt = dom_src.value; car = Math.max(car, 0); cdr = Math.min(cdr, txt.length - 1); @@ -308,10 +311,19 @@ function getsel() { if (cdr < car) cdr = txt.length; + return [car, cdr]; +} + + +// returns [before,selection,after] +function getsel() { + var lb = linebounds(false), + txt = dom_src.value; + return [ - txt.substring(0, car), - txt.substring(car, cdr), - txt.substring(cdr) + txt.substring(0, lb[0]), + txt.substring(lb[0], lb[1]), + txt.substring(lb[1]) ]; } @@ -356,6 +368,30 @@ function md_header(dedent) { } +// smart-home +function md_home(shift) { + var car = dom_src.selectionStart, + sb = linebounds(true), + n1 = sb[0], + n2 = sb[1]; + + var ln = dom_src.value.substring(n1, n2); + var m = /^[ \t#>*_~`+-]*([0-9]+\. +)?/.exec(ln); + if (!m) + return true; + + var home = n1 + m[0].length; + car = (car == home) ? n1 : home; + + var cdr = shift ? dom_src.selectionEnd : car; + if (car > cdr) + car = [cdr, cdr = car][0]; + + dom_src.setSelectionRange(car, cdr); + return false; +} + + // hotkeys / toolbar (function () { function keydown(ev) { @@ -376,6 +412,9 @@ function md_header(dedent) { md_header(ev.shiftKey); return false; } + if (!ctrl && (ev.code == "Home" || kc == 36)) { + return md_home(ev.shiftKey); + } } } document.onkeydown = keydown;