ZyX_I avatar ZyX_I committed caedde4

ftplugin/aurumlog: Made Prev/Next mappings aware of revisions possibly missing in log. Fixes #3

Comments (0)

Files changed (1)

ftplugin/aurumlog.vim

     endif
     return ''
 endfunction
+"▶1 findfirstvisible :: n → hex
+function s:F.findfirstvisible(n)
+    let bvar=s:_r.bufvars[bufnr('%')]
+    let repo=bvar.repo
+    let [blockstart, blockend, hex]=s:F.getblock(bvar)
+    let n=abs(a:n)
+    let direction=((a:n>0)?('parents'):('children'))
+    let tocheck=[]
+    while n>0
+        let tocheck+=repo.functions.getcsprop(repo, hex, direction)
+        let prevn=n
+        while !empty(tocheck)
+            let hex=remove(tocheck, 0)
+            if has_key(bvar.csstarts, hex)
+                let tocheck=[]
+                let n-=1
+            else
+                let tocheck+=repo.functions.getcsprop(repo, hex, direction)
+            endif
+        endwhile
+        if n==prevn
+            return ''
+        endif
+    endwhile
+    return "\<C-\>\<C-n>".(bvar.csstarts[hex]+1).'gg'
+endfunction
 "▶1 next
 function s:F.next()
-    let bvar=s:_r.bufvars[bufnr('%')]
-    let [blockstart, blockend, hex]=s:F.getblock(bvar)
-    let hex=bvar.repo.functions.getnthparent(bvar.repo, hex, -v:count1).hex
-    return "\<C-\>\<C-n>".(bvar.csstarts[hex]+1).'gg'
+    return s:F.findfirstvisible(-v:count1)
 endfunction
 "▶1 prev
 function s:F.prev()
-    let bvar=s:_r.bufvars[bufnr('%')]
-    let [blockstart, blockend, hex]=s:F.getblock(bvar)
-    let hex=bvar.repo.functions.getnthparent(bvar.repo, hex, v:count1).hex
-    return "\<C-\>\<C-n>".(bvar.csstarts[hex]+1).'gg'
+    return s:F.findfirstvisible(v:count1)
 endfunction
 "▶1 filehistory
 function s:F.filehistory()
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.