Author Topic: pop-bookmark switching splitter windows  (Read 2957 times)

microvu

  • Junior Community Member
  • Posts: 9
  • Hero Points: 0
pop-bookmark switching splitter windows
« on: January 18, 2018, 10:58:38 PM »
Hi all,
I did a search and couldn't find anything about this.
- I have a file open and split into two windows, for moving/redoing code from another part of the file.
- I do a push-tag to see a function definition, which opens in the same window.
- I do a pop-bookmark, which places the cursor in the other window and goes back the original location.
This causes me to have to realign the windows. Is there a way around this? It's so ingrained it hits me often.
Version 22.0.1.0 x64 Windows C/C++
Thanks

Graeme

  • Senior Community Member
  • Posts: 2793
  • Hero Points: 347
Re: pop-bookmark switching splitter windows
« Reply #1 on: January 19, 2018, 11:22:46 AM »
I can't reproduce this using V22.0.0.  Does it go wrong every single time with all files and projects?  Are the windows floating or docked  - I tried both.

You could try a new empty configuration folder  - start slick with VS.EXE +new -sc c:\some-new-empty-folder   -  if it's ok then migrate your settings.

microvu

  • Junior Community Member
  • Posts: 9
  • Hero Points: 0
Re: pop-bookmark switching splitter windows
« Reply #2 on: January 19, 2018, 05:37:55 PM »
Yes. It seems to do this with all projects (all of mine are C/C++ right now). I rarely use floating windows. These are docked.
I tried your experiment, with a new configuration directory. It still happens, though I did notice a couple of details:
- If the file navigated to closes on pop-bookmark, the cursor might return to the same window.
- If the file navigated to is already in the other window, the pop-bookmark returned to the proper window.
So it appears the problem happens when the push-tag navigates to another file in the same docked window, and that file does not close when pop-bookmark is used.
This may sound rare, but it's a scenario that happen a lot; I often have multiple files open in each window. (For that matter, I often have multiple copies of SlickEdit open)
Thanks

Graeme

  • Senior Community Member
  • Posts: 2793
  • Hero Points: 347
Re: pop-bookmark switching splitter windows
« Reply #3 on: January 19, 2018, 11:07:47 PM »
ok, after a zillion attempts I finally got it to go wrong on slick 22.0.0 with a new empty config.  I'm not familiar with a window closing after push-tag pop-bookmark so I turned off "automatically close visited files" but I still couldn't repro.  I eventually got a scenario to repro by having the second copy of the other window already visible/ active in the second window when push-tag is used in the first window.  It seems that pop-bookmark and go-to bookmark prefer the visible copy of the file to go to which isn't what you want in this case. 

You should report it to SlickEdit (just refer them to this thread) - I'm not sure how you do that if you don't have maintenance and support.

I'm not sure it's easily fixable. push-bookmark would probably have to record the window-id or maybe the system needs to keep track of which window a buffer was last active in.


microvu

  • Junior Community Member
  • Posts: 9
  • Hero Points: 0
Re: pop-bookmark switching splitter windows
« Reply #4 on: January 19, 2018, 11:28:02 PM »
Thanks for the work on this, especially since it was difficult for you to reproduce. If there were a setting that fixed it I'd be thrilled, but it sounds like it's not been thought about before.
I do have maintenance so that's not an issue. I agree this might not be easy to fix, but it happens often for me so it's worth trying. I delved into SlickC many years ago but this might be more than I want to take on.
Best Regards,
Guy

Graeme

  • Senior Community Member
  • Posts: 2793
  • Hero Points: 347
Re: pop-bookmark switching splitter windows
« Reply #5 on: January 20, 2018, 11:27:52 PM »
I've written some code that lets you save and restore the active editor windows and line numbers for the document groups in the current window.  So you could set up two views into the same buffer in two different windows, then call save_win_list.  To restore, call restore_win_list.  It took a lot of trial and error and it might not be exactly what you want but you can probably change it or ask slickedit support for help, since you have maintenance and support.  e.g. currently if one of the edit windows has been closed before you run the restore, it doesn't get re-opened.
You might be able to add a wrapper around pop-bookmark that can figure out whether you need to adjust the active windows and line numbers if pop-bookmark has done the wrong thing.  You could also generalize it so that there is one "win_list" array for every buffer.

You can also use the slickedit functions save-named-state and load-named-state to save/ restore an edit session.


Code: [Select]
#include "slick.sh"

#pragma option(strictsemicolons,on)
#pragma option(strict,on)
#pragma option(autodecl,off)
#pragma option(strictparens,on)


static int GetEditorCtlWid(int wid)
{
   int editorctl_wid = wid._MDIGetActiveMDIChild();
   if ( editorctl_wid != null && _iswindow_valid(editorctl_wid) && editorctl_wid._isEditorCtl()) {
      return editorctl_wid;
   }
   if (_no_child_windows())
      return -1;

   return _mdi.p_child;
}

struct x1 {
   int wid;
   _str buf_name;
   int xp_line;
   int xp_col;
};

static x1 win_list[];

_command void save_win_list()
{
   int mx = 16;
   int wid1 = p_window_id;
   x1 xx1;
   int nxw;
   win_list._makeempty();
   int first = GetEditorCtlWid(p_window_id);
   if ( first <= 0 ) {
      p_window_id = wid1;
      p_window_id._set_focus();
      return;
   }
   p_window_id = first;
   while ( --mx ) {
      if ( !_iswindow_valid(p_window_id) || !p_window_id._isEditorCtl() ) {
         //say('vvv');
         p_window_id = wid1;
         p_window_id._set_focus();
         return;
      }
      p_window_id._set_focus();
      xx1.wid = p_window_id;
      xx1.buf_name = p_buf_name;
      xx1.xp_line = p_line;
      xx1.xp_col = p_col;
      win_list[win_list._length()] = xx1;
      //say(mx :+ ' z ' :+ p_buf_name :+ ' ' :+ win_list._length());
      next_tab_group();
      nxw = GetEditorCtlWid(p_window_id);
      if ( nxw <= 0 ) {
         p_window_id = wid1;
         p_window_id._set_focus();
         return;
      }
      p_window_id = nxw;
      if ( p_window_id == first ) {
         //say(mx :+ ' ' :+ p_buf_name);
         p_window_id = wid1;
         p_window_id._set_focus();
         return;
      }
   }
   p_window_id = wid1;
   p_window_id._set_focus();
}


_command void restore_win_list()
{
   int wid1 = p_window_id;
   int kk;
   if ( win_list._length() == 0 ) {
      //say('yyy');
      return;
   }
   for ( kk = 0; kk < win_list._length(); ++kk  ) {
      if ( !_iswindow_valid(win_list[kk].wid) || !win_list[kk].wid._isEditorCtl() ) {
         return;
      }
      //say('rrr' :+ ' ' :+ win_list[kk].buf_name);
      p_window_id = win_list[kk].wid;
      p_window_id._set_focus();
      edit(win_list[kk].buf_name);
      p_line = win_list[kk].xp_line;
      p_col = win_list[kk].xp_col;
      center_line();
   }
   p_window_id = win_list[0].wid;
   edit(win_list[0].buf_name);
}


Graeme

  • Senior Community Member
  • Posts: 2793
  • Hero Points: 347
Re: pop-bookmark switching splitter windows
« Reply #6 on: January 20, 2018, 11:32:01 PM »
Forgot to mention, if you turn off "one file per window" - tools -> options -> editing -> editor windows  -  the problem might go away, I'm not sure.  It seems a bit erratic.

microvu

  • Junior Community Member
  • Posts: 9
  • Hero Points: 0
Re: pop-bookmark switching splitter windows
« Reply #7 on: January 21, 2018, 05:45:44 PM »
Thanks! I'll check that out on Monday. Even if it's not perfect it'll give me some idea where to go from there.