Giter Site home page Giter Site logo

Comments (7)

voldikss avatar voldikss commented on August 16, 2024 1

Hi @sakhnik Have you found the solution for this problem?

I've made a patch which basically works

diff --git a/autoload/nvimgdb.vim b/autoload/nvimgdb.vim
index 71673f0..4fb1c66 100644
--- a/autoload/nvimgdb.vim
+++ b/autoload/nvimgdb.vim
@@ -99,3 +99,18 @@ function! nvimgdb#GlobalCleanup()
   delcommand GdbLopenBacktrace
   delcommand GdbLopenBreakpoints
 endfunction
+
+function! nvimgdb#KeepCursor(winid) abort
+  let curr = win_getid()
+  noa keepalt call win_gotoid(a:winid)
+  let wininfo = getwininfo(a:winid)[0]
+  let botline = wininfo['botline']
+  let topline = wininfo['topline']
+  let currlnum = line('.')
+  let lastlnum = line('$')
+  if botline - topline > &scrolloff && botline - currlnum < &scrolloff && botline < lastlnum
+    let topline += &scrolloff - (botline - currlnum)
+    call winrestview({'topline': topline})
+  endif
+  noa keepalt call win_gotoid(curr)
+endfunction
diff --git a/rplugin/python3/gdb/win.py b/rplugin/python3/gdb/win.py
index 87d453c..a7ee547 100644
--- a/rplugin/python3/gdb/win.py
+++ b/rplugin/python3/gdb/win.py
@@ -84,7 +84,11 @@ class Win(Common):
         # Ensure the jump window is available
         with self._saved_mode():
             self._ensure_jump_window()
-        if not self.jump_win:
+        if self.jump_win:
+            winid = self.vim.call("bufwinid", target_buf)
+            if winid > 0:
+                self.vim.call('nvimgdb#KeepCursor', winid)
+        else:
             raise AssertionError("No jump window")
 
         # The terminal buffer may contain the name of the source file

gdb

from nvim-gdb.

sakhnik avatar sakhnik commented on August 16, 2024

That's a good idea. You could set the option scrolloff to a positive number to keep the cursor off the edges. Consider using setlocal scrolloff=5 to make the change local to the window.
Could you please prepare a pull request?

from nvim-gdb.

zhoupro avatar zhoupro commented on August 16, 2024

#38 Please check the pr, tks.

from nvim-gdb.

voldikss avatar voldikss commented on August 16, 2024

The problem still exists for me. Can anyone please reproduce it?

gdb

from nvim-gdb.

sakhnik avatar sakhnik commented on August 16, 2024

Thanks for the report! I think I understand the issue. The option 'scrolloff' only handles the cursor. So we just need to let the cursor follow the current line sign.
UPD: The code is actually there:

self.jump_win.cursor = (line, 0)
, but it doesn't work. The cursor is only adjusted when I jump to the code window. Need to investigate.

from nvim-gdb.

voldikss avatar voldikss commented on August 16, 2024

The scrolloff is set only the first time the code window is opened(BufEnter event is fired and the code related to set scrolloff is executed). After that the cursor won't enter the code window again, correspondingly the BufEnter event won't be fired.

from nvim-gdb.

sakhnik avatar sakhnik commented on August 16, 2024

That's a good solution, I like it. Could you please prepare a pull request?
I'd like to run it through the test suite, then we can accept it as is.
But there's a bigger change coming in the branch lua (fa1e3d9). I'll take your change into it.

from nvim-gdb.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.