Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add ctrl-_ undo support #13

Closed
wants to merge 1 commit into from
Closed

Add ctrl-_ undo support #13

wants to merge 1 commit into from

Conversation

wader
Copy link
Collaborator

@wader wader commented Mar 19, 2023

TODO: better pos only changes
TODO: config

@wader
Copy link
Collaborator Author

wader commented Mar 19, 2023

This one probably needs some cleanup

@wader
Copy link
Collaborator Author

wader commented Apr 1, 2023

Rebased on master and reworked it a bit.

@slingamn what do you think about the approach? i feel like it sprinkle small undo calls a bit to much hmm. Any idea how to make it nicer?

Also this implementation does not behave exactly as gnu readline undo etc but maybe it's close enough?

@slingamn
Copy link
Member

slingamn commented Apr 2, 2023

Thanks for fixing the conflicts on this! I will definitely look at this but I may not have time until April 16th or so.

@wader
Copy link
Collaborator Author

wader commented Apr 2, 2023

👍 no hurry!

@wader
Copy link
Collaborator Author

wader commented Apr 18, 2023

Rebased on master

runebuf.go Outdated
@@ -442,6 +445,9 @@ func (r *runeBuffer) Refresh(f func()) {
}

func (r *runeBuffer) refresh(f func()) {
prevIdx := r.idx
prevBuf := append([]rune{}, r.buf...)

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe this should be after interactive check? seems to work fine, moving it

@slingamn
Copy link
Member

Sorry I keep introducing conflicts in this :-)

I'm not sure about how important this feature is to end users? Is it something that's important in the fq context? Or is the point more to get to parity with GNU Readline? Unless there's a clear case for it, I'm not sure about including it at this stage.

(I was also considering removing Vim mode, but there seems to be a fair amount of user interest in it, e.g. upstream's #36 and #120).

At a code level this patch seems pretty good except that it increases implementation complexity, and also the size of the undo buffer is unbounded. (I'm thinking about writing a generic expandable ring buffer with a size limit that could replace uses of container/list for history and search, so if I end up doing that, it would be applicable here as well.)

@wader
Copy link
Collaborator Author

wader commented Apr 23, 2023

No worries. Don't know how many other use undo, the reason i added it is i'm used to it from other readline implementations. It would of course be nice to not have to maintain my own fork with some addition (only undo i think atm?) but basing it on ergochat/readline would still be a big improvement!

TODO: better pos only changes
TODO: config
@slingamn
Copy link
Member

If it's important to fq, then I'll get it merged in this cycle :-)

@wader
Copy link
Collaborator Author

wader commented Apr 23, 2023

If it's important to fq, then I'll get it merged in this cycle :-)

That would be great of course 👍 what should be improved before merge, ring buffer? less complex somehow, better way to reset/init undo?

BTW here is draft PR to use ergochat/readline with fq wader/fq#646


if r.OnChange != nil {
if !runes.Equal(r.buf, prevBuf) {
if prevIdx != r.lastChangeIdx+1 {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is the idea of this check to stop undo() from writing its own undo entry?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If i remember correctly it's to skip triggering change when just typing "normally" and not moving around so that we don't add undo entries for each character change

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe it would be cleaner to move that kind of logic into opUndo by passing some more arguments to OnChange?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

but i'm not very happy with the this whole undo implementation, feels a bit adhoc hacky, so if you have some idea how to implement it in a nicer way please do!

@wader
Copy link
Collaborator Author

wader commented Jul 7, 2023

@slingamn hey, just curious, any progress on rewrite things to resolve this in a nicer way?

@slingamn
Copy link
Member

slingamn commented Jul 7, 2023

Sorry, work keeps getting in the way, but I'll put it on the list for this weekend.

@wader
Copy link
Collaborator Author

wader commented Jul 8, 2023

@slingamn no stress! Did a fq release and tags my forked deps and got thinking of this :)

@slingamn
Copy link
Member

slingamn commented Nov 5, 2023

I promise I haven't forgotten about this :-)

@wader
Copy link
Collaborator Author

wader commented Nov 5, 2023

@slingamn no worries :)

@slingamn slingamn mentioned this pull request Dec 24, 2023
@slingamn
Copy link
Member

Done in #46

@slingamn slingamn closed this Dec 24, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants