Branch: refs/heads/master Author: Jiří Techet techet@gmail.com Committer: Jiří Techet techet@gmail.com Date: Sun, 07 May 2023 18:58:05 UTC Commit: 14f306bff5b699d5715fd166e194762e346978bc https://github.com/geany/geany-plugins/commit/14f306bff5b699d5715fd166e19476...
Log Message: ----------- vimode: avoid caret position change when inserting EOL at EOF
When current position is changed in the document and this position is outside the visibility of the current screen, when returning back, the call of SCI_GOTOPOS causes window scroll to a different position than before.
To avoid this problem, insert_eof_nl_if_missing() and remove_char_from_eof() avoid setting the position now and, instead, insert/remove the EOL character using operations that don't change caret position.
Modified Paths: -------------- vimode/src/cmds/edit.c
Modified: vimode/src/cmds/edit.c 19 lines changed, 11 insertions(+), 8 deletions(-) =================================================================== @@ -83,16 +83,21 @@ void cmd_clear_right(CmdContext *c, CmdParams *p)
static gboolean insert_eof_nl_if_missing(CmdParams *p) { - gint pos = SSM(p->sci, SCI_GETCURRENTPOS, 0, 0); gint eof_pos = SSM(p->sci, SCI_GETLENGTH, 0, 0); gint eof_line_num = SSM(p->sci, SCI_LINEFROMPOSITION, eof_pos, 0); gint before_eof = PREV(p->sci, eof_pos); gint before_eof_line_num = SSM(p->sci, SCI_LINEFROMPOSITION, before_eof, 0);
if (eof_line_num == before_eof_line_num) { - SET_POS(p->sci, eof_pos, FALSE); - SSM(p->sci, SCI_NEWLINE, 0, 0); - SET_POS(p->sci, pos, FALSE); + const gchar *nl = "\n"; + gint eol_mode = SSM(p->sci, SCI_GETEOLMODE, 0, 0); + if (eol_mode == SC_EOL_CRLF) { + nl = "\r\n"; + } + else if (eol_mode == SC_EOL_CR) { + nl = "\r"; + } + SSM(p->sci, SCI_INSERTTEXT, eof_pos, (sptr_t)nl); return TRUE; } return FALSE; @@ -101,12 +106,10 @@ static gboolean insert_eof_nl_if_missing(CmdParams *p)
static void remove_char_from_eof(CmdParams *p) { - gint pos = SSM(p->sci, SCI_GETCURRENTPOS, 0, 0); gint eof_pos = SSM(p->sci, SCI_GETLENGTH, 0, 0); + gint before_eof_pos = PREV(p->sci, eof_pos);
- SET_POS(p->sci, eof_pos, FALSE); - SSM(p->sci, SCI_DELETEBACK, 0, 0); - SET_POS(p->sci, pos, FALSE); + SSM(p->sci, SCI_DELETERANGE, before_eof_pos, eof_pos - before_eof_pos); }
-------------- This E-Mail was brought to you by github_commit_mail.py (Source: https://github.com/geany/infrastructure).
plugins-commits@lists.geany.org