Help creating a shortcut/macro to jump between window splits

Hi, all

I respectfully ask any guru to help me creating a macro (that I could bind to a keyboard shortcut) to jump between window splits in Calc using the keyboard.

Or if there is some command that I am not aware, please let me know.

Here is someone else who asks exactly like me for a kb shortcut: Is there a keyboard shortcut to switch between windows when in the split window mode?

I know I can duplicate the window and then, thanks to my windows manager, split and jump between them, but I loose valuable real state pixels in both windows (because of the menu and toolbars). Yes, I can hide them, but that is a hassle, specially if I need to break the splits, now and then, and go back to normal view mode.

For what is needed, I’m in Arch/Openbox

Version: 7.6.4.1 (X86_64) / LibreOffice Community
Build ID: 60(Build:1)
CPU threads: 16; OS: Linux 6.6; UI render: default; VCL: kf5 (cairo+xcb)
Locale: es-MX (es_MX.UTF-8); UI: en-US
7.6.4-2
Calc: threaded Jumbo

1 Like

An interesting task.
There seems to be no direct path, so we need to look for workarounds. :slightly_smiling_face:

Do you need to jump between two different cells?
While working with two (or more) windows, each window can have different cells active.
But when you change from one split to other, the actual cell active is the same.

1 Like

Let’s try (even though I’m not a guru). :slightly_smiling_face:
Assign the following macro to a keyboard shortcut that is convenient for you.

' lang:en
' Moves between split window panes in a Calc document.
Sub JumpToNextPane(Optional ByVal oDoc As Object)
  Dim oCont As Object, nPanes As Long, arr, arr2, iSheet As Long, shInfo As String, sep As String
  If IsMissing(oDoc) Then oDoc=ThisComponent
  If Not HasUnoInterfaces(oDoc, "com.sun.star.sheet.XSpreadsheetDocument") Then Exit Sub
  oCont=oDoc.CurrentController
  If Not HasUnoInterfaces(oCont, "com.sun.star.sheet.XSpreadsheetView") Then Exit Sub
  
  nPanes=oCont.Count               ' Number of Panes
  If nPanes<2 Then Exit Sub
  
  arr=Split(oCont.ViewData, ";")   ' View Data: https://docs.libreoffice.org/sc/html/classScViewData.html#abb5889c04d6857f169f07e4fc15c03b8 
  iSheet=Clng(arr(1)) + 3          ' Active sheet index in arr
  shInfo=arr(iSheet)               ' Sheet info
  sep="+"                          ' Token separator: + or /
  arr2=Split(shInfo, sep)         
  If Ubound(arr2)=0 Then
    sep="/"
    arr2=Split(shInfo, sep)
  End If    
 
  If nPanes=4 Then                            '  Hori and Vert Split
     arr2(6)=Cstr((Clng(arr2(6))+ 1) Mod 4)  
  ElseIf arr2(2)="1" Then                     ' Vert    
     arr2(6)=IIf(arr2(6)="2", "3", "2")
  Else                                        ' Hori
     arr2(6)=IIf(arr2(6)="0", "2", "0")     
  End If   
 
  arr(iSheet)=Join(arr2, sep)
  oCont.restoreViewData Join(arr, ";")
End Sub

Yes, @LeroyG, I need to get access to different cells in the same sheet, that’s why splitting the same window is useful. I can see the header, where I copy some cells from, then paste them into some other lower part.

Not in my case that actual cell is the same, at least is not when “jumping” using the mouse :unamused:

I have a windows splited in two; one split, with cells in row 30, and another split with row 250, for example. Only the column remains the same when copy/pasting (in my case, of course).

Hi, @sokol92, good day

I suppose the macro works for you.

In my case, I noted the following: the cursor does change between splits, but unfortunately in split 2 it cannot go to a cell different than in split 1. After all, both splits lock in sync, sort of saying.

This is the nature of split windows (see @LeroyG’s answer). The selected cell(s) are the same for all panels.
If you want to change the selected cell to another, how can you tell a macro (assigned to a hotkey) about the new cell?

I would need a clarification:
Is this about one Window split into 2 or 4 panes
OR
is it actually about 2 Windows containing views of the same document?

One window split in two panes (in my case), @Lupp. But could it also work for 4 panes?

(So, the right name for “splits” is “panes”; glad to know it. Whenever you do not know tech names, it’s difficult to search help or ask for it. Thanks!)

I do not know if I am misunderstood, @sokol92.

Let’s say that I start my sheet divided into two panes (or split, as I used to say). I position my cursor in different rows in each split (let’s say B4 in pane 1 and B200 in pane 2). Then I jump from pane 1 to pane 2. Can the macro gets to remember the former position in each pane?

Is that possible? If i do it with mouse, the panes do not reset positions/views/row between jumps… neither they lock in sync.

This isn’t what I meant. But if you use the splitter, what you get is very different from what you get if you create an additional window for the same document. I therefore wanted to make undoubtably clear, not only for myself, what case you have.
(And the relevant API service for the parts of a splitted view is com.sun.star.sheet.SpreadsheetViewPane. I took the “Pane” out.)

@Lupp I am using the splitter, yes

…“split window”.

You can’t.
imagen

And there is no split when there are rows or columns freezed. Maybe that is what do you need.

This isn’t quite correct. The Freeze tool also creates SpreadSheetViewPane objects, but they are presented in a slightly different way in the View to the user.
See attatched.
disask101322reportAboutCurrentViewPanes.ods (13.1 KB)

For simplicity’s sake these sheets don’t suppress an error occurring during recalculation onLoad.
Simply click the messages away, and recalc again (Shift+Ctrl+F9).

What the OriginalQuestioner wanted, however, may be implemented basically without regarding splitting or freezing at all in different ways. One probably recommendable way should be to use named ranges, and (if actually needed) to create a macro supporting a choice out of some of them. I would prefer to use the Navigator for the purpose (if there not are all too many named rangesmade with different intentions).

Not sure to understand your point. Split and freeze functions couldn’t be simultaneous.

We can try writing a macro like this. At the same time, if the position (cell) in target pane was not previously remembered, or the previously remembered cell is not on target pane (the pane has changed due to scrolling), then go to the upper left cell of target pane.
Is it good?

Yes. Generally. Noneteheless you get panes by freezing. In addition the behaviour concerening some user actions (cursor movements, mouse dragging) is different, and the draggable splitters (at least one of them) are removed.
(At least in V 24.2.0.2 the second splitter is not immediately removed if only rows or only columns were frozen. It will be removed, however, as soon as once used. See
disask101322reportAboutCurrentViewPanesB.ods (12.6 KB) )

1 Like

No. That’s because the panes mostly (and especially if created with the splitters) aren’ fix ranges. Therefore a new selection you make can -at best- be assigned to a variable based on the current view. The same cell or range selected at a different time may point into a range beleonging to a different pane - or even to more than one pane. Try it and you will see that split panes may both show a specific cell, and that this cell when clicked in one place will get the “active border” in both panes.

@sokol92 Better way if it goes to the upper left cell of target pane, in case of scrolling. That would be a great solution!

Yes, I can, @Leroy. See:

(Well, you cannot actually see the cursor in both panes at the same time, but both panes or windows splits or whatever show different parts of the same sheet.)