ZyX_I avatar ZyX_I committed 034b2cb

graphlog: Improved `showfiles' option

Comments (0)

Files changed (1)

ftplugin/aurumgraphlog.vim

 setlocal nomodeline
 execute frawor#Setup('0.0', {'@aurum': '0.0',
             \            '@/mappings': '0.0',
-            \        '@/autocommands': '0.0',})
+            \        '@/autocommands': '0.0',
+            \               '@/table': '0.0',})
 let s:F.glog={}
 "▶1 bisect :: [a], function + self → a
 function s:F.bisect(list, function)
         let text+=newtext
     endfor
     "▶3 Add files
-    if get(a:opts, 'showfiles', 0)
+    if get(a:opts, 'showfiles', 0) && !empty(a:cs.files)
         let curline=len(text)
-        let special.files_l=[curline, 0]
-        let text+=['Files: '.join(a:cs.files, ', ')]
-        let flens=map(copy(a:cs.files), 'len(v:val)')
-        let start=stridx(text[-1], ' ')+1
-        let i=0
-        for flen in flens
-            let special['file'.i.'_r']=[[curline, start], [curline, start+flen]]
-            let start+=flen+2
-            let i+=1
+        let ftext=['Files: ']
+        let ww=winwidth(0)-10
+        let lw=s:_r.strdisplaywidth(ftext[-1])
+        let curfilenum=0
+        let fi=0
+        for file in a:cs.files
+            let fw=s:_r.strdisplaywidth(file, lw)
+            if curfilenum && fw+lw>ww
+                let ftext+=['Files: '.file.', ']
+                let lw=s:_r.strdisplaywidth(ftext[-1])
+                let curfilenum=0
+            else
+                let ftext[-1].=file.', '
+                let lw+=fw
+            endif
+            let cl=curline+len(ftext)-1
+            let fl=len(file)
+            let ll=len(ftext[-1])
+            let special['file'.fi.'_r']=[[cl, ll-fl-2], [cl, ll-2]]
+            let fi+=1
+            let curfilenum+=1
         endfor
+        call map(ftext, 'v:val[:-3]')
+        let special.files_R=[[curline, 0], [curline+len(ftext)-1, 0]]
+        let text+=ftext
     endif
     "▶3 Add description
     let description=map(split(a:cs.description, "\n", 1), '"  ".v:val')
                 return r
             endif
         elseif suffix is# 'R'
-            let line=line('.')-1
             if line>=splist[0][0] && line<=splist[1][0]
                 return r
             endif
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.