Skip to content

feate add motions dt dT df df ct cT cf cF and fix f/F and t/T not working on capital letters#130

Closed
BrettKulp wants to merge 4 commits into
leohenon:ocvfrom
BrettKulp:feat/delete_to_and_change_to
Closed

feate add motions dt dT df df ct cT cf cF and fix f/F and t/T not working on capital letters#130
BrettKulp wants to merge 4 commits into
leohenon:ocvfrom
BrettKulp:feat/delete_to_and_change_to

Conversation

@BrettKulp
Copy link
Copy Markdown

Add motions dt dT df df ct cT cf cF

The regular t/T and f/F now correctly work with capital letters

lmk if anything needs changed.

Also could make this logic that is similar in multiple motions more reusable if you want want to go that way. They are different enough that I wasn't sure if that would be the right thing to do

if (isPrintable(event) && !hasModifier(event)) {
const forward = deleteFind === "df" || deleteFind === "dt"
const till = deleteFind === "dt" || deleteFind === "dT"
const textarea = input.textarea()
const start = textarea.cursorOffset
const char = value(event)
findChar(textarea, char, forward, till)
if (textarea.cursorOffset !== start) {
const span = forward
? { start, end: textarea.cursorOffset + 1 }
: { start: textarea.cursorOffset, end: start + 1 }
const text = textarea.plainText.slice(span.start, span.end)
edit(() => {
deleteSpan(textarea, span)
if (text) setRegister({ text, linewise: false })
textarea.cursorOffset = Math.min(start, textarea.cursorOffset)
})
}
input.state.setLastFind({ char, forward, till })
input.state.clearPending()
event.preventDefault()
return true
}
input.state.clearPending()
event.preventDefault()
return true

Copy link
Copy Markdown
Owner

@leohenon leohenon left a comment

Choose a reason for hiding this comment

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

Thanks, the uppercase f/F/t/T fix looks good. Please split that into a separate PR so we can merge it independently.

For th rest, I don’t want to add separate pending states for each combination. I know the current operator handling is already pretty explicit, but these motions add another level of pending input, so I think this is the right point to introduce shared operator/motion abstraction instead.

Current issues:

  • failed cf/ct should not enter insert mode
  • findChar() moves the cursor before the edit snapshot, so undo cursor restore can be wrong

I’m going to take over this part and implement it around shared logic that computes the f/t span first. Thanks for the initial implementation/tests.

@BrettKulp
Copy link
Copy Markdown
Author

Sounds good. Here is that PR #132 with f/F/t/T fix only. Thanks!

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.

2 participants