Skip to content
This repository was archived by the owner on Apr 6, 2018. It is now read-only.

Repeat typing - #176

Merged
bhuga merged 54 commits into
masterfrom
undo-typing
May 31, 2014
Merged

bhuga merged 54 commits into
masterfrom
undo-typing

Conversation

@bhuga

@bhuga bhuga commented Mar 15, 2014

Copy link
Copy Markdown
Contributor

This is quite the WIP. I need some help from @nathansobo on things that I have commented on inline.

The goal is to make . work with typing. Currently this works for typing which has no deletions (backspaces). It's also not quite accurate yet; s, for example, deletes a character and enters insert mode, and . currently won't delete the character. I can fix up the edge cases if we can get this to a workable place.

Comment thread spec/vim-state-spec.coffee Outdated

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

@nathansobo This tries to type a character in the main editor, but the editor never gets it.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

The editor uses textInput events rather than keydown.

Comment thread lib/operators.coffee Outdated

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

This nastiness creates a string out of all of the inserted text; it works great if there were no deletions. I can't figure out a way to determine if a deletion in a transaction deletes another piece of text typed in the transaction, or if it's a completely unrelated operation. Other than diffing patch locations to see if the deletion position was already inserted, which is a pretty monstrous task. It doesn't look like Transaction has a better way to do this today, but I'm wondering if there's something planned that I can contribute towards that might make this sort of thing easier.

@nathansobo

Copy link
Copy Markdown
Contributor

Checking my understanding here: The . command can repeat any previous change command, right? Some of these commands are logical in nature, like "join lines". Repeating the last insert mode excursion is just one of a category of commands that need to be repeatable.

I'm thinking that ::commitTransaction and ::transact should return a transaction object that can be replayed at a different location in the buffer. So if the range of an operation in a replayed transaction is [[5, 10], [5, 13]], replaying the transaction at [7, 2] would run the same operation but change the range to [[7, 2], [7, 5]]. I'm not sure about marker positions. Perhaps we can treat them the same. What happens to cursors in vim when operations are replayed?

So I'm thinking of supporting this pseudocode:

@buffer.beginTransaction()
# make changes
transaction = @buffer.commitTransaction()
# later...
transaction.replay([7, 2]) # the position could be optional

@bhuga

bhuga commented Mar 17, 2014

Copy link
Copy Markdown
Contributor Author

@nathansobo we talked about this a little, but just writing this down:

I'm thinking that ::commitTransaction and ::transact should return a transaction object that can be replayed at a different location in the buffer.

This is exactly how I think it should work. It's a little bit weird, because transactions can encompass things like 'replace the current selection', and that's not a concept that's 'repeatable' in vim; there's no . operation in visual mode to repeat a previous s<typing> operation on a previous selection. But if we can just get at the concept of 'a chunk of typing', it opens up all the doors we need.

Comment thread lib/operators/input.coffee Outdated

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

We try to have all potential fields on the object by the time the constructor completes, so it would be a good idea to put typed: false in the prototype.

@nathansobo

Copy link
Copy Markdown
Contributor

Okay, I added some comments in various places. Summary:

  • I'd like to see the facility for getting the most recent contiguous inserted text moved into TextBuffer so we don't rely on its implementation details. We should probably just have a method like ::getLastInsertedText or something along those lines that behaves as desired.
  • I'd like to see the specs be a little more realistic than setting the text of the entire buffer. We want to exercise the transactions for example.

@bhuga

bhuga commented May 27, 2014

Copy link
Copy Markdown
Contributor Author

Fantastic review @nathansobo, thanks! I will clean up the easy stuff.

@bhuga

bhuga commented May 31, 2014

Copy link
Copy Markdown
Contributor Author

Okay, I'm about to merge this. c, s, S, o, O, i, and a are all now support undo and repeat. Finally.

Specific callout to a few recent contributors: would you please get master and see if repeat and undo on typing is not what you expect before I do a release?

@carlosdcastillo @abijr @tony612 @tmm1 @jacobgardener @jcurtis @mcnicholls @mcolyer @nathansobo

Future cleanups include:

  • Getting the tests to support indentation for some newlines (it respects them in coffeescript files, but not the grammar-less test buffers).
  • Cleaner interface to undo history
  • Cleaner interface to transactions
  • Some movement commands in insert mode need to reset their transactions (does anyone page up/page down in insert mode?)

Those are all pretty ugly but I am really tired of not having this when I'm on master.

bhuga pushed a commit that referenced this pull request May 31, 2014
@bhuga
bhuga merged commit c191cdc into master May 31, 2014
@bhuga
bhuga deleted the undo-typing branch May 31, 2014 04:08
@tony612

tony612 commented May 31, 2014

Copy link
Copy Markdown
Contributor

Looks good. Though it behaves a little differently with vim, but I think it's ok to publish.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

But there's a bug when you press a or i, insert nothing then press escape.There'll be a error raised.
It can fixed simply by changing this line to @editor.getBuffer().insert(@editor.getCursorBufferPosition(), @typedText || "", true)

@carlosdcastillo

Copy link
Copy Markdown
Contributor

@bhuga: I coded today with what is in master as my vim-mode version. Everything is looking really good. I did find this obnoxious one:
abc(things here) abcdef ( more things here )

What works:
-If you stand on the first ( and type c%qqq and then go to the next ( and type .
What doesn't:
-If you stand on the first ( and type c%qqq and then go to the closing final ) and type .

I'll try to send a PR tomorrow to fix it.

MarkusSN pushed a commit to MarkusSN/vim-mode that referenced this pull request May 28, 2015
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants