micro/internal/action
Dmitry Maluka 28e0e20651
Improve buffer view relocation after jumping to a far-away location (#2628)
* Improve buffer view relocation after jumping to a far-away location

When the cursor is moved to a location which is far away from the
current location (e.g. after a search or a goto line), the buffer view
is always relocated in such a way that the cursor is at the bottom or
at the top (minus scrollmargin), i.e. as if we just scrolled to this
location. It's not like in other editors, and IMHO it's annoying. When
we jump to a new location far away, we usually want to see more of its
context, so the cursor should be placed closer to the center of the
view, not near its edges.

This change implements the behavior similar to other editors:

- If the distance between the new and the old location is less than one
  frame (i.e. the view either doesn't change or just slightly "shifts")
  then the current behavior remains unchanged.

- Otherwise the current line is placed at 25% of the window height.

* Postpone calling onBufPaneOpen until the initial resize

It is currently not possible to find out the geometry of a newly created
bufpane in onBufPaneOpen lua callback: bp:GetView() returns {0,0,0,0}
instead of the actual window. The reason is that the bufpane view is not
properly initialized yet when the bufpane is created and the callback is
triggered. It is initialized a bit later, at the initial resize.

So postpone calling onBufPaneOpen until after the initial resize.

* Improve buffer view relocation when opening a file at a far-away location

When a file is opened with the initial cursor location at a given line
which is far away from the beginning of the file, the buffer view is
relocated so that the cursor is at the bottom (minus scrollmargin)
as if we just scrolled to this line, which is annoying since we'd rather
like to see more of the context of this initial location.

So implement the behavior similar to the earlier commit (which addresses
a similar issue about jumping far away after a search or goto):

- If the initial cursor location is less than one frame away from the
  beginning of the buffer, keep the existing behavior i.e. just display
  the beginning of the buffer.

- Otherwise place the cursor location at 25% of the window height.
2022-12-02 19:38:09 -08:00
..
actions.go Improve buffer view relocation after jumping to a far-away location (#2628) 2022-12-02 19:38:09 -08:00
actions_other.go Change project layout and use go.mod 2019-12-25 17:05:10 -05:00
actions_posix.go Fix v2 import path for go mod 2020-05-04 10:16:15 -04:00
bindings.go Fix #2030: warn for invalid pane type 2021-02-18 19:02:23 -05:00
bufpane.go Improve buffer view relocation after jumping to a far-away location (#2628) 2022-12-02 19:38:09 -08:00
command.go Improve buffer view relocation after jumping to a far-away location (#2628) 2022-12-02 19:38:09 -08:00
defaults.go Update keybinding docs 2020-09-06 17:38:23 -04:00
defaults_darwin.go Support for highlighting all search matches (hlsearch) (#1762) 2021-09-28 13:39:03 -07:00
defaults_other.go Support for highlighting all search matches (hlsearch) (#1762) 2021-09-28 13:39:03 -07:00
events.go Replace meta with alt automatically, update tcell 2020-09-05 21:59:19 -04:00
globals.go Improve comments 2021-08-21 17:58:30 -04:00
infocomplete.go Add support for copy-paste via OSC 52 2020-07-04 20:00:39 -04:00
infopane.go Make yes/no prompts case-insensitive (#2182) 2021-08-13 23:56:26 -04:00
keytree.go More style improvements 2021-08-21 18:04:08 -04:00
pane.go More style improvements 2021-08-21 18:04:08 -04:00
rawpane.go Update to tcell v2 2020-09-05 14:52:35 -04:00
tab.go Update to tcell v2 2020-09-05 14:52:35 -04:00
terminal_supported.go Check error in terminal emulator 2020-07-27 17:43:55 -04:00
terminal_unsupported.go Use actual lua functions for callbacks instead of strings 2020-02-08 15:49:41 -05:00
termpane.go Fix internal string binding representation 2020-11-05 15:52:25 -05:00