From 407531bcb1d8cf89513c0028859c9f93c2ea2764 Mon Sep 17 00:00:00 2001 From: ed Date: Tue, 25 Feb 2025 00:03:22 +0000 Subject: [PATCH] fix markdown / text-editor jank * only indicate file-history for markdown files since other files won't load into the editor which makes that entirely pointless; do file extension instead * text-editor: in files containing one single line, ^C followed by ^V ^Z would accidentally a letter and fix unhydrated extensions --- copyparty/httpcli.py | 13 +++++++++---- copyparty/web/md2.js | 12 +++++++----- 2 files changed, 16 insertions(+), 9 deletions(-) diff --git a/copyparty/httpcli.py b/copyparty/httpcli.py index 5f3dec08..431fd545 100644 --- a/copyparty/httpcli.py +++ b/copyparty/httpcli.py @@ -152,6 +152,8 @@ RE_HSAFE = re.compile(r"[\x00-\x1f<>\"'&]") # search always much faster RE_HOST = re.compile(r"[^][0-9a-zA-Z.:_-]") # search faster <=17ch RE_MHOST = re.compile(r"^[][0-9a-zA-Z.:_-]+$") # match faster >=18ch RE_K = re.compile(r"[^0-9a-zA-Z_-]") # search faster <=17ch +RE_HR = re.compile(r"[<>\"'&]") +RE_MDV = re.compile(r"(.*)\.([0-9]+\.[0-9]{3})(\.[Mm][Dd])$") UPARAM_CC_OK = set("doc move tree".split()) @@ -5969,7 +5971,7 @@ class HttpCli(object): # [num-backups, most-recent, hist-path] hist: dict[str, tuple[int, float, str]] = {} histdir = os.path.join(fsroot, ".hist") - ptn = re.compile(r"(.*)\.([0-9]+\.[0-9]{3})(\.[^\.]+)$") + ptn = RE_MDV try: for hfn in bos.listdir(histdir): m = ptn.match(hfn) @@ -6002,6 +6004,7 @@ class HttpCli(object): dirs = [] files = [] + ptn_hr = RE_HR for fn in ls_names: base = "" href = fn @@ -6056,11 +6059,13 @@ class HttpCli(object): zd.second, ) - try: - ext = "---" if is_dir else fn.rsplit(".", 1)[1] + if is_dir: + ext = "---" + elif "." in fn: + ext = ptn_hr.sub("@", fn.rsplit(".", 1)[1]) if len(ext) > 16: ext = ext[:16] - except: + else: ext = "%" if add_fk and not is_dir: diff --git a/copyparty/web/md2.js b/copyparty/web/md2.js index 6df62b13..f7d0b59c 100644 --- a/copyparty/web/md2.js +++ b/copyparty/web/md2.js @@ -1078,26 +1078,28 @@ action_stack = (function () { var p1 = from.length, p2 = to.length; - while (p1-- > 0 && p2-- > 0) + while (p1 --> 0 && p2 --> 0) if (from[p1] != to[p2]) break; - if (car > ++p1) { + if (car > ++p1) car = p1; - } var txt = from.substring(car, p1) return { car: car, - cdr: ++p2, + cdr: p2 + (car && 1), txt: txt, cpos: cpos }; } var undiff = function (from, change) { + var t1 = from.substring(0, change.car), + t2 = from.substring(change.cdr); + return { - txt: from.substring(0, change.car) + change.txt + from.substring(change.cdr), + txt: t1 + change.txt + t2, cpos: change.cpos }; }