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: d6e3ac8d1d1be0fb52da6c3f3fce4059dc1f578a https://github.com/geany/geany-plugins/commit/d6e3ac8d1d1be0fb52da6c3f3fce40...
Log Message: ----------- vimode: fix detection of missing EOL at EOF
The previous code was incorrect. The new code just
1. Goes to the last position in document 2. Goes one position before that 3. Checks if the lines corresponding to (1) and (2) are identical - in this case the NL is missing at EOF
Modified Paths: -------------- vimode/src/cmds/edit.c
Modified: vimode/src/cmds/edit.c 16 lines changed, 8 insertions(+), 8 deletions(-) =================================================================== @@ -84,12 +84,13 @@ 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 last_line = SSM(p->sci, SCI_GETLINECOUNT, 0, 0); - gint line_start_pos = SSM(p->sci, SCI_POSITIONFROMLINE, last_line, 0); - gint line_end_pos = SSM(p->sci, SCI_GETLINEENDPOSITION, last_line, 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 (line_start_pos == line_end_pos) { - SET_POS(p->sci, line_end_pos, FALSE); + 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); return TRUE; @@ -101,10 +102,9 @@ 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 last_line = SSM(p->sci, SCI_GETLINECOUNT, 0, 0); - gint line_end_pos = SSM(p->sci, SCI_GETLINEENDPOSITION, last_line, 0); + gint eof_pos = SSM(p->sci, SCI_GETLENGTH, 0, 0);
- SET_POS(p->sci, line_end_pos, FALSE); + SET_POS(p->sci, eof_pos, FALSE); SSM(p->sci, SCI_DELETEBACK, 0, 0); SET_POS(p->sci, pos, FALSE); }
-------------- This E-Mail was brought to you by github_commit_mail.py (Source: https://github.com/geany/infrastructure).
plugins-commits@lists.geany.org