Branch: refs/heads/master
Author: Jiří Techet <techet(a)gmail.com>
Committer: GitHub <noreply(a)github.com>
Date: Sat, 25 May 2024 18:42:12 UTC
Commit: 3e38966d6baf53a84d2c3644aaa6eaadd38e532e
https://github.com/geany/geany-plugins/commit/3e38966d6baf53a84d2c3644aaa6e…
Log Message:
-----------
Merge pull request #1350 from scresto09/vimode-fold-support-fix
Vimode: implement fold in vimode plugin
Modified Paths:
--------------
vimode/README
vimode/src/Makefile.am
vimode/src/cmd-runner.c
vimode/src/cmds/fold.c
vimode/src/cmds/fold.h
Modified: vimode/README
11 lines changed, 10 insertions(+), 1 deletions(-)
===================================================================
@@ -96,7 +96,7 @@ This is an incomplete list of known limitations of the plugin:
* named registers and related commands are not implemented
* Ctrl+X mode is not implemented
* marks are not implemented
-* fold commands are not implemented
+* many fold commands are not implemented
* most commands starting with "'", "z", and "g" are not implemented
* most ex mode commands are not implemented (excluding basic stuff like search,
replace, saving, etc.)
@@ -501,7 +501,16 @@ a new command, please do not forget to update the table below.::
cursor on first non-blank
z. z. redraw, cursor line to center of window,
cursor on first non-blank
+ zA zA open a closed fold or close an open fold
+ recursively
+ zC zC close folds recursively
+ zM zM set 'foldlevel' to zero
+ zO zO open folds recursively
+ zR zR set 'foldlevel' to the deepest fold
+ za za open a closed fold, close an open fold
zb zb redraw, cursor line at bottom of window
+ zc zc close a fold
+ zo zo open fold
zt zt redraw, cursor line at top of window
zz zz redraw, cursor line at center of window
Modified: vimode/src/Makefile.am
4 lines changed, 3 insertions(+), 1 deletions(-)
===================================================================
@@ -37,7 +37,9 @@ vi_srcs = \
cmds/excmds.h \
cmds/excmds.c \
cmds/undo.h \
- cmds/undo.c
+ cmds/undo.c \
+ cmds/fold.h \
+ cmds/fold.c
vimode_la_SOURCES = \
backends/backend-geany.c \
Modified: vimode/src/cmd-runner.c
10 lines changed, 10 insertions(+), 0 deletions(-)
===================================================================
@@ -25,6 +25,7 @@
#include "cmds/changemode.h"
#include "cmds/edit.h"
#include "cmds/special.h"
+#include "cmds/fold.h"
#include <gdk/gdkkeysyms.h>
@@ -262,6 +263,15 @@ CmdDef text_object_cmds[] = {
{cmd_copy_line, GDK_KEY_Y, 0, 0, 0, FALSE, FALSE}, \
{cmd_paste_after, GDK_KEY_p, 0, 0, 0, FALSE, FALSE}, \
{cmd_paste_before, GDK_KEY_P, 0, 0, 0, FALSE, FALSE}, \
+ /* fold */ \
+ {cmd_toggle_fold, GDK_KEY_z, GDK_KEY_a, 0, 0, FALSE, FALSE}, \
+ {cmd_open_fold, GDK_KEY_z, GDK_KEY_o, 0, 0, FALSE, FALSE}, \
+ {cmd_close_fold, GDK_KEY_z, GDK_KEY_c, 0, 0, FALSE, FALSE}, \
+ {cmd_toggle_fold_child, GDK_KEY_z, GDK_KEY_A, 0, 0, FALSE, FALSE}, \
+ {cmd_open_fold_child, GDK_KEY_z, GDK_KEY_O, 0, 0, FALSE, FALSE}, \
+ {cmd_close_fold_child, GDK_KEY_z, GDK_KEY_C, 0, 0, FALSE, FALSE}, \
+ {cmd_open_fold_all, GDK_KEY_z, GDK_KEY_R, 0, 0, FALSE, FALSE}, \
+ {cmd_close_fold_all, GDK_KEY_z, GDK_KEY_M, 0, 0, FALSE, FALSE}, \
/* changing text */ \
{cmd_enter_insert_cut_line, GDK_KEY_c, GDK_KEY_c, 0, 0, FALSE, FALSE}, \
{cmd_enter_insert_cut_line, GDK_KEY_S, 0, 0, 0, FALSE, FALSE}, \
Modified: vimode/src/cmds/fold.c
127 lines changed, 127 insertions(+), 0 deletions(-)
===================================================================
@@ -0,0 +1,127 @@
+/*
+ * Copyright 2024 Sylvain Cresto <scresto(a)gmail.com>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+
+#include "cmds/fold.h"
+#include "utils.h"
+
+#define GOTO_NEAREST_PARENT 0
+#define GOTO_TOPMOST_PARENT 1
+#define GOTO_CONTRACTED_PARENT 2
+
+static gint goto_above_fold(CmdParams *p, gint type)
+{
+ /* foldparent of the next line */
+ gint line = SSM(p->sci, SCI_GETFOLDPARENT, p->line + 1, 0);
+
+ if (p->line == line)
+ ; /* we are already on the fold point line */
+ else
+ {
+ /* foldparent of the current line */
+ line = SSM(p->sci, SCI_GETFOLDPARENT, p->line, 0);
+ }
+
+ /* retreive first parent when type != GOTO_NEAREST_PARENT
+ when type == GOTO_CONTRACTED_PARENT we stop on first contracted parent if exist
+ */
+ if (type == GOTO_CONTRACTED_PARENT && line != -1 && ! SSM(p->sci, SCI_GETFOLDEXPANDED, line, 0))
+ ; /* this fold point is contracted and type == GOTO_CONTRACTED_PARENT */
+ else if (type != GOTO_NEAREST_PARENT)
+ {
+ gint prev_line = line;
+ while (prev_line != -1)
+ {
+ prev_line = SSM(p->sci, SCI_GETFOLDPARENT, prev_line, 0);
+ if (prev_line != -1)
+ {
+ line = prev_line;
+ if (type == GOTO_CONTRACTED_PARENT && ! SSM(p->sci, SCI_GETFOLDEXPANDED, line, 0))
+ break;
+ }
+ }
+ }
+
+ if (line != -1)
+ {
+ /* move the cursor on the visible line before the fold */
+ gint pos = SSM(p->sci, SCI_POSITIONFROMLINE, line, 0);
+ SET_POS_NOX(p->sci, pos, TRUE);
+ }
+
+ return line;
+}
+
+
+void cmd_toggle_fold(CmdContext *c, CmdParams *p)
+{
+ gint line = goto_above_fold(p, GOTO_NEAREST_PARENT);
+ if (line != -1)
+ SSM(p->sci, SCI_FOLDLINE, (uptr_t) line, SC_FOLDACTION_TOGGLE);
+}
+
+
+void cmd_open_fold(CmdContext *c, CmdParams *p)
+{
+ gint line = goto_above_fold(p, GOTO_NEAREST_PARENT);
+ if (line != -1)
+ SSM(p->sci, SCI_FOLDLINE, (uptr_t) line, SC_FOLDACTION_EXPAND);
+}
+
+
+void cmd_close_fold(CmdContext *c, CmdParams *p)
+{
+ gint line = goto_above_fold(p, GOTO_NEAREST_PARENT);
+ if (line != -1)
+ SSM(p->sci, SCI_FOLDLINE, (uptr_t) line, SC_FOLDACTION_CONTRACT);
+}
+
+
+void cmd_toggle_fold_child(CmdContext *c, CmdParams *p)
+{
+ gint line = goto_above_fold(p, GOTO_CONTRACTED_PARENT);
+ if (line != -1)
+ SSM(p->sci, SCI_FOLDCHILDREN, (uptr_t) line, SC_FOLDACTION_TOGGLE);
+}
+
+
+void cmd_open_fold_child(CmdContext *c, CmdParams *p)
+{
+ gint line = goto_above_fold(p, GOTO_NEAREST_PARENT);
+ SSM(p->sci, SCI_FOLDCHILDREN, (uptr_t) line, SC_FOLDACTION_EXPAND);
+}
+
+
+void cmd_close_fold_child(CmdContext *c, CmdParams *p)
+{
+ gint line = goto_above_fold(p, GOTO_TOPMOST_PARENT);
+ if (line != -1)
+ SSM(p->sci, SCI_FOLDCHILDREN, (uptr_t) line, SC_FOLDACTION_CONTRACT);
+}
+
+
+void cmd_open_fold_all(CmdContext *c, CmdParams *p)
+{
+ SSM(p->sci, SCI_FOLDALL, SC_FOLDACTION_EXPAND | SC_FOLDACTION_CONTRACT_EVERY_LEVEL, 0);
+}
+
+
+void cmd_close_fold_all(CmdContext *c, CmdParams *p)
+{
+ goto_above_fold(p, GOTO_TOPMOST_PARENT);
+ SSM(p->sci, SCI_FOLDALL, SC_FOLDACTION_CONTRACT | SC_FOLDACTION_CONTRACT_EVERY_LEVEL, 0);
+}
Modified: vimode/src/cmds/fold.h
37 lines changed, 37 insertions(+), 0 deletions(-)
===================================================================
@@ -0,0 +1,37 @@
+/*
+ * Copyright 2024 Sylvain Cresto <scresto(a)gmail.com>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+
+#ifndef __VIMODE_CMDS_FOLD_H__
+#define __VIMODE_CMDS_FOLD_H__
+
+#include "context.h"
+#include "cmd-params.h"
+
+void cmd_toggle_fold(CmdContext *c, CmdParams *p);
+void cmd_open_fold(CmdContext *c, CmdParams *p);
+void cmd_close_fold(CmdContext *c, CmdParams *p);
+
+void cmd_toggle_fold_child(CmdContext *c, CmdParams *p);
+void cmd_open_fold_child(CmdContext *c, CmdParams *p);
+void cmd_close_fold_child(CmdContext *c, CmdParams *p);
+
+void cmd_toggle_fold_all(CmdContext *c, CmdParams *p);
+void cmd_open_fold_all(CmdContext *c, CmdParams *p);
+void cmd_close_fold_all(CmdContext *c, CmdParams *p);
+
+#endif
--------------
This E-Mail was brought to you by github_commit_mail.py (Source: https://github.com/geany/infrastructure).
Branch: refs/heads/master
Author: Sylvain Cresto <scresto(a)gmail.com>
Committer: Sylvain Cresto <scresto(a)gmail.com>
Date: Sat, 25 May 2024 09:20:22 UTC
Commit: 5c74ce1d1a5b4f7a52b232e7b198a0d07242120a
https://github.com/geany/geany-plugins/commit/5c74ce1d1a5b4f7a52b232e7b198a…
Log Message:
-----------
Vimode: implement fold in vimode plugin
Modified Paths:
--------------
vimode/README
vimode/src/Makefile.am
vimode/src/cmd-runner.c
vimode/src/cmds/fold.c
vimode/src/cmds/fold.h
Modified: vimode/README
11 lines changed, 10 insertions(+), 1 deletions(-)
===================================================================
@@ -96,7 +96,7 @@ This is an incomplete list of known limitations of the plugin:
* named registers and related commands are not implemented
* Ctrl+X mode is not implemented
* marks are not implemented
-* fold commands are not implemented
+* many fold commands are not implemented
* most commands starting with "'", "z", and "g" are not implemented
* most ex mode commands are not implemented (excluding basic stuff like search,
replace, saving, etc.)
@@ -501,7 +501,16 @@ a new command, please do not forget to update the table below.::
cursor on first non-blank
z. z. redraw, cursor line to center of window,
cursor on first non-blank
+ zA zA open a closed fold or close an open fold
+ recursively
+ zC zC close folds recursively
+ zM zM set 'foldlevel' to zero
+ zO zO open folds recursively
+ zR zR set 'foldlevel' to the deepest fold
+ za za open a closed fold, close an open fold
zb zb redraw, cursor line at bottom of window
+ zc zc close a fold
+ zo zo open fold
zt zt redraw, cursor line at top of window
zz zz redraw, cursor line at center of window
Modified: vimode/src/Makefile.am
4 lines changed, 3 insertions(+), 1 deletions(-)
===================================================================
@@ -37,7 +37,9 @@ vi_srcs = \
cmds/excmds.h \
cmds/excmds.c \
cmds/undo.h \
- cmds/undo.c
+ cmds/undo.c \
+ cmds/fold.h \
+ cmds/fold.c
vimode_la_SOURCES = \
backends/backend-geany.c \
Modified: vimode/src/cmd-runner.c
10 lines changed, 10 insertions(+), 0 deletions(-)
===================================================================
@@ -25,6 +25,7 @@
#include "cmds/changemode.h"
#include "cmds/edit.h"
#include "cmds/special.h"
+#include "cmds/fold.h"
#include <gdk/gdkkeysyms.h>
@@ -262,6 +263,15 @@ CmdDef text_object_cmds[] = {
{cmd_copy_line, GDK_KEY_Y, 0, 0, 0, FALSE, FALSE}, \
{cmd_paste_after, GDK_KEY_p, 0, 0, 0, FALSE, FALSE}, \
{cmd_paste_before, GDK_KEY_P, 0, 0, 0, FALSE, FALSE}, \
+ /* fold */ \
+ {cmd_toggle_fold, GDK_KEY_z, GDK_KEY_a, 0, 0, FALSE, FALSE}, \
+ {cmd_open_fold, GDK_KEY_z, GDK_KEY_o, 0, 0, FALSE, FALSE}, \
+ {cmd_close_fold, GDK_KEY_z, GDK_KEY_c, 0, 0, FALSE, FALSE}, \
+ {cmd_toggle_fold_child, GDK_KEY_z, GDK_KEY_A, 0, 0, FALSE, FALSE}, \
+ {cmd_open_fold_child, GDK_KEY_z, GDK_KEY_O, 0, 0, FALSE, FALSE}, \
+ {cmd_close_fold_child, GDK_KEY_z, GDK_KEY_C, 0, 0, FALSE, FALSE}, \
+ {cmd_open_fold_all, GDK_KEY_z, GDK_KEY_R, 0, 0, FALSE, FALSE}, \
+ {cmd_close_fold_all, GDK_KEY_z, GDK_KEY_M, 0, 0, FALSE, FALSE}, \
/* changing text */ \
{cmd_enter_insert_cut_line, GDK_KEY_c, GDK_KEY_c, 0, 0, FALSE, FALSE}, \
{cmd_enter_insert_cut_line, GDK_KEY_S, 0, 0, 0, FALSE, FALSE}, \
Modified: vimode/src/cmds/fold.c
127 lines changed, 127 insertions(+), 0 deletions(-)
===================================================================
@@ -0,0 +1,127 @@
+/*
+ * Copyright 2024 Sylvain Cresto <scresto(a)gmail.com>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+
+#include "cmds/fold.h"
+#include "utils.h"
+
+#define GOTO_NEAREST_PARENT 0
+#define GOTO_TOPMOST_PARENT 1
+#define GOTO_CONTRACTED_PARENT 2
+
+static gint goto_above_fold(CmdParams *p, gint type)
+{
+ /* foldparent of the next line */
+ gint line = SSM(p->sci, SCI_GETFOLDPARENT, p->line + 1, 0);
+
+ if (p->line == line)
+ ; /* we are already on the fold point line */
+ else
+ {
+ /* foldparent of the current line */
+ line = SSM(p->sci, SCI_GETFOLDPARENT, p->line, 0);
+ }
+
+ /* retreive first parent when type != GOTO_NEAREST_PARENT
+ when type == GOTO_CONTRACTED_PARENT we stop on first contracted parent if exist
+ */
+ if (type == GOTO_CONTRACTED_PARENT && line != -1 && ! SSM(p->sci, SCI_GETFOLDEXPANDED, line, 0))
+ ; /* this fold point is contracted and type == GOTO_CONTRACTED_PARENT */
+ else if (type != GOTO_NEAREST_PARENT)
+ {
+ gint prev_line = line;
+ while (prev_line != -1)
+ {
+ prev_line = SSM(p->sci, SCI_GETFOLDPARENT, prev_line, 0);
+ if (prev_line != -1)
+ {
+ line = prev_line;
+ if (type == GOTO_CONTRACTED_PARENT && ! SSM(p->sci, SCI_GETFOLDEXPANDED, line, 0))
+ break;
+ }
+ }
+ }
+
+ if (line != -1)
+ {
+ /* move the cursor on the visible line before the fold */
+ gint pos = SSM(p->sci, SCI_POSITIONFROMLINE, line, 0);
+ SET_POS_NOX(p->sci, pos, TRUE);
+ }
+
+ return line;
+}
+
+
+void cmd_toggle_fold(CmdContext *c, CmdParams *p)
+{
+ gint line = goto_above_fold(p, GOTO_NEAREST_PARENT);
+ if (line != -1)
+ SSM(p->sci, SCI_FOLDLINE, (uptr_t) line, SC_FOLDACTION_TOGGLE);
+}
+
+
+void cmd_open_fold(CmdContext *c, CmdParams *p)
+{
+ gint line = goto_above_fold(p, GOTO_NEAREST_PARENT);
+ if (line != -1)
+ SSM(p->sci, SCI_FOLDLINE, (uptr_t) line, SC_FOLDACTION_EXPAND);
+}
+
+
+void cmd_close_fold(CmdContext *c, CmdParams *p)
+{
+ gint line = goto_above_fold(p, GOTO_NEAREST_PARENT);
+ if (line != -1)
+ SSM(p->sci, SCI_FOLDLINE, (uptr_t) line, SC_FOLDACTION_CONTRACT);
+}
+
+
+void cmd_toggle_fold_child(CmdContext *c, CmdParams *p)
+{
+ gint line = goto_above_fold(p, GOTO_CONTRACTED_PARENT);
+ if (line != -1)
+ SSM(p->sci, SCI_FOLDCHILDREN, (uptr_t) line, SC_FOLDACTION_TOGGLE);
+}
+
+
+void cmd_open_fold_child(CmdContext *c, CmdParams *p)
+{
+ gint line = goto_above_fold(p, GOTO_NEAREST_PARENT);
+ SSM(p->sci, SCI_FOLDCHILDREN, (uptr_t) line, SC_FOLDACTION_EXPAND);
+}
+
+
+void cmd_close_fold_child(CmdContext *c, CmdParams *p)
+{
+ gint line = goto_above_fold(p, GOTO_TOPMOST_PARENT);
+ if (line != -1)
+ SSM(p->sci, SCI_FOLDCHILDREN, (uptr_t) line, SC_FOLDACTION_CONTRACT);
+}
+
+
+void cmd_open_fold_all(CmdContext *c, CmdParams *p)
+{
+ SSM(p->sci, SCI_FOLDALL, SC_FOLDACTION_EXPAND | SC_FOLDACTION_CONTRACT_EVERY_LEVEL, 0);
+}
+
+
+void cmd_close_fold_all(CmdContext *c, CmdParams *p)
+{
+ goto_above_fold(p, GOTO_TOPMOST_PARENT);
+ SSM(p->sci, SCI_FOLDALL, SC_FOLDACTION_CONTRACT | SC_FOLDACTION_CONTRACT_EVERY_LEVEL, 0);
+}
Modified: vimode/src/cmds/fold.h
37 lines changed, 37 insertions(+), 0 deletions(-)
===================================================================
@@ -0,0 +1,37 @@
+/*
+ * Copyright 2024 Sylvain Cresto <scresto(a)gmail.com>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+
+#ifndef __VIMODE_CMDS_FOLD_H__
+#define __VIMODE_CMDS_FOLD_H__
+
+#include "context.h"
+#include "cmd-params.h"
+
+void cmd_toggle_fold(CmdContext *c, CmdParams *p);
+void cmd_open_fold(CmdContext *c, CmdParams *p);
+void cmd_close_fold(CmdContext *c, CmdParams *p);
+
+void cmd_toggle_fold_child(CmdContext *c, CmdParams *p);
+void cmd_open_fold_child(CmdContext *c, CmdParams *p);
+void cmd_close_fold_child(CmdContext *c, CmdParams *p);
+
+void cmd_toggle_fold_all(CmdContext *c, CmdParams *p);
+void cmd_open_fold_all(CmdContext *c, CmdParams *p);
+void cmd_close_fold_all(CmdContext *c, CmdParams *p);
+
+#endif
--------------
This E-Mail was brought to you by github_commit_mail.py (Source: https://github.com/geany/infrastructure).
Branch: refs/heads/master
Author: Jiří Techet <techet(a)gmail.com>
Committer: GitHub <noreply(a)github.com>
Date: Wed, 22 May 2024 15:09:58 UTC
Commit: 0e299a898165cedfc8010d1ae43fa14a0c9f8e00
https://github.com/geany/geany-plugins/commit/0e299a898165cedfc8010d1ae43fa…
Log Message:
-----------
Merge pull request #1328 from scresto09/vimode-fix-undo-pos
Vimode: fix cursor position after using undo
Modified Paths:
--------------
vimode/src/Makefile.am
vimode/src/cmds/edit.c
vimode/src/cmds/excmds.c
vimode/src/cmds/undo.c
vimode/src/cmds/undo.h
vimode/src/context.h
vimode/src/utils.c
vimode/src/vi.c
Modified: vimode/src/Makefile.am
4 lines changed, 3 insertions(+), 1 deletions(-)
===================================================================
@@ -35,7 +35,9 @@ vi_srcs = \
cmds/edit.h \
cmds/edit.c \
cmds/excmds.h \
- cmds/excmds.c
+ cmds/excmds.c \
+ cmds/undo.h \
+ cmds/undo.c
vimode_la_SOURCES = \
backends/backend-geany.c \
Modified: vimode/src/cmds/edit.c
9 lines changed, 2 insertions(+), 7 deletions(-)
===================================================================
@@ -17,6 +17,7 @@
*/
#include "cmds/edit.h"
+#include "cmds/undo.h"
#include "utils.h"
@@ -161,13 +162,7 @@ void cmd_del_word_left(CmdContext *c, CmdParams *p)
void cmd_undo(CmdContext *c, CmdParams *p)
{
- gint i;
- for (i = 0; i < p->num; i++)
- {
- if (!SSM(p->sci, SCI_CANUNDO, 0, 0))
- break;
- SSM(p->sci, SCI_UNDO, 0, 0);
- }
+ undo_apply(c, p->num);
}
Modified: vimode/src/cmds/excmds.c
3 lines changed, 2 insertions(+), 1 deletions(-)
===================================================================
@@ -18,6 +18,7 @@
#include "cmds/excmds.h"
#include "cmds/edit.h"
+#include "cmds/undo.h"
#include "utils.h"
void excmd_save(CmdContext *c, ExCmdParams *p)
@@ -93,7 +94,7 @@ void excmd_put(CmdContext *c, ExCmdParams *p)
void excmd_undo(CmdContext *c, ExCmdParams *p)
{
- SSM(c->sci, SCI_UNDO, 0, 0);
+ undo_apply(c, 1);
}
Modified: vimode/src/cmds/undo.c
59 lines changed, 59 insertions(+), 0 deletions(-)
===================================================================
@@ -0,0 +1,59 @@
+/*
+ * Copyright 2024 Sylvain Cresto <scresto(a)gmail.com>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+
+#include "undo.h"
+#include "utils.h"
+
+void undo_update(CmdContext *c, gint pos)
+{
+ c->undo_pos = pos;
+}
+
+
+static gboolean is_start_of_line(ScintillaObject *sci, gint pos)
+{
+ gint line = SSM(sci, SCI_LINEFROMPOSITION, pos, 0);
+ gint line_pos = SSM(sci, SCI_POSITIONFROMLINE, line, 0);
+
+ return pos == line_pos;
+}
+
+
+void undo_apply(CmdContext *c, gint num)
+{
+ ScintillaObject *sci = c->sci;
+ gint i;
+
+ c->undo_pos = -1;
+
+ for (i = 0; i < num; i++)
+ {
+ if (!SSM(sci, SCI_CANUNDO, 0, 0))
+ break;
+ SSM(sci, SCI_UNDO, 0, 0);
+ }
+
+ /* exit when no undo has been applied */
+ if (c->undo_pos == -1)
+ return;
+
+ if (is_start_of_line(sci, c->undo_pos))
+ goto_nonempty(sci, SSM(sci, SCI_LINEFROMPOSITION, c->undo_pos, 0), FALSE);
+ else
+ SET_POS(sci, c->undo_pos, FALSE);
+}
Modified: vimode/src/cmds/undo.h
27 lines changed, 27 insertions(+), 0 deletions(-)
===================================================================
@@ -0,0 +1,27 @@
+/*
+ * Copyright 2024 Sylvain Cresto <scresto(a)gmail.com>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+
+#ifndef __UNDO_H__
+#define __UNDO_H__
+
+#include "context.h"
+
+void undo_update(CmdContext *c, gint pos);
+void undo_apply(CmdContext *c, gint num);
+
+#endif
Modified: vimode/src/context.h
3 lines changed, 3 insertions(+), 0 deletions(-)
===================================================================
@@ -57,6 +57,9 @@ typedef struct
* copied N times when e.g. 'i' is preceded by a number or when using '.' */
gchar insert_buf[INSERT_BUF_LEN];
gint insert_buf_len;
+
+ /* cursor position to restore after undo */
+ gint undo_pos;
} CmdContext;
#endif
Modified: vimode/src/utils.c
1 lines changed, 1 insertions(+), 0 deletions(-)
===================================================================
@@ -210,6 +210,7 @@ gint get_line_number_rel(ScintillaObject *sci, gint shift)
return new_line;
}
+
void goto_nonempty(ScintillaObject *sci, gint line, gboolean scroll)
{
gint line_end_pos = SSM(sci, SCI_GETLINEENDPOSITION, line, 0);
Modified: vimode/src/vi.c
8 lines changed, 7 insertions(+), 1 deletions(-)
===================================================================
@@ -21,6 +21,7 @@
#include "utils.h"
#include "keypress.h"
#include "excmd-prompt.h"
+#include "cmds/undo.h"
#include <gdk/gdkkeysyms.h>
@@ -51,7 +52,8 @@ CmdContext ctx =
NULL, NULL, NULL,
FALSE, FALSE,
0, 1,
- "", 0
+ "", 0,
+ -1
};
@@ -306,6 +308,10 @@ gboolean vi_notify_sci(SCNotification *nt)
}
}
+ /* Keep position of undo operation */
+ if (nt->nmhdr.code == SCN_MODIFIED && (nt->modificationType & SC_MOD_BEFOREINSERT && nt->modificationType & SC_PERFORMED_UNDO) && nt->length > 1)
+ undo_update(&ctx, nt->position);
+
/* This makes sure that when we click behind the end of line in command mode,
* the cursor is not placed BEHIND the last character but ON the last character.
* We want to ignore this when doing selection with mouse as it breaks things. */
--------------
This E-Mail was brought to you by github_commit_mail.py (Source: https://github.com/geany/infrastructure).
Branch: refs/heads/master
Author: Sylvain Cresto <scresto(a)gmail.com>
Committer: Sylvain Cresto <scresto(a)gmail.com>
Date: Wed, 22 May 2024 08:42:16 UTC
Commit: cc7d25d426b107ff033c71ea051a90bd4310c7be
https://github.com/geany/geany-plugins/commit/cc7d25d426b107ff033c71ea051a9…
Log Message:
-----------
vimode: fix cursor position after using undo (u key)
Modified Paths:
--------------
vimode/src/Makefile.am
vimode/src/cmds/edit.c
vimode/src/cmds/excmds.c
vimode/src/cmds/undo.c
vimode/src/cmds/undo.h
vimode/src/context.h
vimode/src/utils.c
vimode/src/vi.c
Modified: vimode/src/Makefile.am
4 lines changed, 3 insertions(+), 1 deletions(-)
===================================================================
@@ -35,7 +35,9 @@ vi_srcs = \
cmds/edit.h \
cmds/edit.c \
cmds/excmds.h \
- cmds/excmds.c
+ cmds/excmds.c \
+ cmds/undo.h \
+ cmds/undo.c
vimode_la_SOURCES = \
backends/backend-geany.c \
Modified: vimode/src/cmds/edit.c
9 lines changed, 2 insertions(+), 7 deletions(-)
===================================================================
@@ -17,6 +17,7 @@
*/
#include "cmds/edit.h"
+#include "cmds/undo.h"
#include "utils.h"
@@ -161,13 +162,7 @@ void cmd_del_word_left(CmdContext *c, CmdParams *p)
void cmd_undo(CmdContext *c, CmdParams *p)
{
- gint i;
- for (i = 0; i < p->num; i++)
- {
- if (!SSM(p->sci, SCI_CANUNDO, 0, 0))
- break;
- SSM(p->sci, SCI_UNDO, 0, 0);
- }
+ undo_apply(c, p->num);
}
Modified: vimode/src/cmds/excmds.c
3 lines changed, 2 insertions(+), 1 deletions(-)
===================================================================
@@ -18,6 +18,7 @@
#include "cmds/excmds.h"
#include "cmds/edit.h"
+#include "cmds/undo.h"
#include "utils.h"
void excmd_save(CmdContext *c, ExCmdParams *p)
@@ -93,7 +94,7 @@ void excmd_put(CmdContext *c, ExCmdParams *p)
void excmd_undo(CmdContext *c, ExCmdParams *p)
{
- SSM(c->sci, SCI_UNDO, 0, 0);
+ undo_apply(c, 1);
}
Modified: vimode/src/cmds/undo.c
59 lines changed, 59 insertions(+), 0 deletions(-)
===================================================================
@@ -0,0 +1,59 @@
+/*
+ * Copyright 2024 Sylvain Cresto <scresto(a)gmail.com>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+
+#include "undo.h"
+#include "utils.h"
+
+void undo_update(CmdContext *c, gint pos)
+{
+ c->undo_pos = pos;
+}
+
+
+static gboolean is_start_of_line(ScintillaObject *sci, gint pos)
+{
+ gint line = SSM(sci, SCI_LINEFROMPOSITION, pos, 0);
+ gint line_pos = SSM(sci, SCI_POSITIONFROMLINE, line, 0);
+
+ return pos == line_pos;
+}
+
+
+void undo_apply(CmdContext *c, gint num)
+{
+ ScintillaObject *sci = c->sci;
+ gint i;
+
+ c->undo_pos = -1;
+
+ for (i = 0; i < num; i++)
+ {
+ if (!SSM(sci, SCI_CANUNDO, 0, 0))
+ break;
+ SSM(sci, SCI_UNDO, 0, 0);
+ }
+
+ /* exit when no undo has been applied */
+ if (c->undo_pos == -1)
+ return;
+
+ if (is_start_of_line(sci, c->undo_pos))
+ goto_nonempty(sci, SSM(sci, SCI_LINEFROMPOSITION, c->undo_pos, 0), FALSE);
+ else
+ SET_POS(sci, c->undo_pos, FALSE);
+}
Modified: vimode/src/cmds/undo.h
27 lines changed, 27 insertions(+), 0 deletions(-)
===================================================================
@@ -0,0 +1,27 @@
+/*
+ * Copyright 2024 Sylvain Cresto <scresto(a)gmail.com>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+
+#ifndef __UNDO_H__
+#define __UNDO_H__
+
+#include "context.h"
+
+void undo_update(CmdContext *c, gint pos);
+void undo_apply(CmdContext *c, gint num);
+
+#endif
Modified: vimode/src/context.h
3 lines changed, 3 insertions(+), 0 deletions(-)
===================================================================
@@ -57,6 +57,9 @@ typedef struct
* copied N times when e.g. 'i' is preceded by a number or when using '.' */
gchar insert_buf[INSERT_BUF_LEN];
gint insert_buf_len;
+
+ /* cursor position to restore after undo */
+ gint undo_pos;
} CmdContext;
#endif
Modified: vimode/src/utils.c
1 lines changed, 1 insertions(+), 0 deletions(-)
===================================================================
@@ -210,6 +210,7 @@ gint get_line_number_rel(ScintillaObject *sci, gint shift)
return new_line;
}
+
void goto_nonempty(ScintillaObject *sci, gint line, gboolean scroll)
{
gint line_end_pos = SSM(sci, SCI_GETLINEENDPOSITION, line, 0);
Modified: vimode/src/vi.c
8 lines changed, 7 insertions(+), 1 deletions(-)
===================================================================
@@ -21,6 +21,7 @@
#include "utils.h"
#include "keypress.h"
#include "excmd-prompt.h"
+#include "cmds/undo.h"
#include <gdk/gdkkeysyms.h>
@@ -51,7 +52,8 @@ CmdContext ctx =
NULL, NULL, NULL,
FALSE, FALSE,
0, 1,
- "", 0
+ "", 0,
+ -1
};
@@ -306,6 +308,10 @@ gboolean vi_notify_sci(SCNotification *nt)
}
}
+ /* Keep position of undo operation */
+ if (nt->nmhdr.code == SCN_MODIFIED && (nt->modificationType & SC_MOD_BEFOREINSERT && nt->modificationType & SC_PERFORMED_UNDO) && nt->length > 1)
+ undo_update(&ctx, nt->position);
+
/* This makes sure that when we click behind the end of line in command mode,
* the cursor is not placed BEHIND the last character but ON the last character.
* We want to ignore this when doing selection with mouse as it breaks things. */
--------------
This E-Mail was brought to you by github_commit_mail.py (Source: https://github.com/geany/infrastructure).