@techee requested changes on this pull request.
Looks good to me apart from the few formal comments above and the possible goto_nonempty()
use. Would you incorporate those changes into this PR?
> @@ -162,14 +163,14 @@ void cmd_del_word_left(CmdContext *c, CmdParams *p) void cmd_undo(CmdContext *c, CmdParams *p) { gint i; - gint pos = SSM(p->sci, SCI_GETCURRENTPOS, 0, 0); + start_undo(c); for (i = 0; i < p->num; i++) { if (!SSM(p->sci, SCI_CANUNDO, 0, 0)) break; SSM(p->sci, SCI_UNDO, 0, 0); }
Shouldn't goto_nonempty()
be used here to go to the first non-white character on a line? vim seems to behave this way, even though in a bit inconsistent manner - when you perform dd
, undo goes to the first non-white character while when you use 2dd
, it goes where the cursor was before.
If goto_nonempty()
is used, it should only be run when some actual undo happened and also when the cursor is at the beginning of a line so it doesn't jump somewhere else when you e.g. delete a word in the middle of a sentence.
> @@ -0,0 +1,41 @@ +/* + * Copyright 2024 Jiri Techet <techet@gmail.com>
Your file, your name :-). You can skip the email address if you are worried of spam.
> + * 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 start_undo(CmdContext *c);
I'd prefer the names to start with undo_
, so e.g. undo_start()
here.
> + */ + +#include "undo.h" +#include "utils.h" + +void start_undo(CmdContext *c) +{ + c->undo_pos = -1; +} + +void update_undo(CmdContext *c, gint pos) +{ + c->undo_pos = pos; +} + +gboolean end_undo(CmdContext *c)
Is the gboolean return value used for anything?
> + +void start_undo(CmdContext *c) +{ + c->undo_pos = -1; +} + +void update_undo(CmdContext *c, gint pos) +{ + c->undo_pos = pos; +} + +gboolean end_undo(CmdContext *c) +{ + ScintillaObject *sci = c->sci; + + if (c->undo_pos != -1) {
{ on a separate line to match the style of the rest of the code.
> @@ -0,0 +1,28 @@ +/* + * Copyright 2024 Jiri Techet <techet@gmail.com>
Like above.
> + * 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 start_undo(CmdContext *c); +void update_undo(CmdContext *c, gint pos); +gboolean end_undo(CmdContext *c);
void instead of gboolean?
—
Reply to this email directly, view it on GitHub, or unsubscribe.
You are receiving this because you are subscribed to this thread.