home · contact · privacy
Browser: In by_1st view's prompt summaries, ellipsize prompt into two parts. master
authorChristian Heller <c.heller@plomlompom.de>
Wed, 13 Nov 2024 02:32:59 +0000 (03:32 +0100)
committerChristian Heller <c.heller@plomlompom.de>
Wed, 13 Nov 2024 02:32:59 +0000 (03:32 +0100)
browser.py

index 81ec8870d69555a08bd48d18bda3eb9d8883338d..89eabadfa7c5b80b14c2405b36c5909e122a82f3 100755 (executable)
@@ -854,10 +854,21 @@ class Gallery:
             if suffix:
                 for i, p in enumerate(cores):
                     cores[i] = p[:-len(suffix)]
+            longest_total = ''
+            for i in range(len(cores[0])):
+                temp_longest = find_longest_equal(cores, j=i, matcher='in')
+                if len(temp_longest) > len(longest_total):
+                    longest_total = temp_longest
+            middle = longest_total
             for i, p in enumerate(prompts):
+                remains = p[len(prefix):]
+                idx_middle = remains.index(middle)
+                second = remains[:idx_middle]
+                remains = remains[idx_middle + len(middle):]
+                first = remains[:-len(suffix)] if suffix else remains
                 pre_ell = '…' if prefix else ''
                 post_ell = '…' if suffix else ''
-                prompts_diff[p] = f'{pre_ell}{cores[i]}{post_ell}'
+                prompts_diff[p] = f'{pre_ell}{first}…{second}{post_ell}'
             return prompts_diff
 
         basic_items_attrs = {}