Skip to content

vimMove Variable in TextView#758

Closed
Awesome-Sauces wants to merge 5 commits intorivo:masterfrom
Awesome-Sauces:master
Closed

vimMove Variable in TextView#758
Awesome-Sauces wants to merge 5 commits intorivo:masterfrom
Awesome-Sauces:master

Conversation

@Awesome-Sauces
Copy link
Copy Markdown

This is to block the actions preformed when these keys are pressed in a textview

  • h, left arrow: Move left.
  • l, right arrow: Move right.
  • j, down arrow: Move down.
  • k, up arrow: Move up.
  • g, home: Move to the top.
  • G, end: Move to the bottom.

@rivo
Copy link
Copy Markdown
Owner

rivo commented Aug 20, 2022

Why?

If you want different key binds (or none), you can use SetInputCapture().

@Awesome-Sauces
Copy link
Copy Markdown
Author

Well in my mind I find it easier to just call a function to stop those key binds from moving you around in the textview but still allow scrolling at the same time.

@rivo
Copy link
Copy Markdown
Owner

rivo commented Aug 20, 2022

I'm sorry but you haven't provided a reason yet why offering these key binds is a problem.

Next someone comes and says they only want Vim bindings but no arrow movement.
Then someone comes along and says they need the same flag for all the other primitives, too.

It's precisely the reason why I'm offering SetInputCapture() so everyone can customize it to their own preferences.

So unless there's a good reason to offer this specific option to all users of tview, it's going to be a "no" from my side.

@Awesome-Sauces
Copy link
Copy Markdown
Author

Oh ok would you mind explaining shortly how SetInputCapture would work for me being able to ignore the Vim bindings? I can't really find a way to ignore the Vim bindings with SetInputCapture.

@rivo
Copy link
Copy Markdown
Owner

rivo commented Aug 20, 2022

Sure, no problem. Here's an example:

func main() {
	app := tview.NewApplication()
	textArea := tview.NewTextView().SetText(text)
	textArea.SetInputCapture(func(event *tcell.EventKey) *tcell.EventKey {
		switch event.Key() {
		case tcell.KeyLeft, tcell.KeyRight, tcell.KeyUp, tcell.KeyDown:
			return event // Allow arrow keys.
		}
		return nil // Ignore all others.
	})
	if err := app.SetRoot(textArea, true).EnableMouse(true).Run(); err != nil {
		panic(err)
	}
}

@Awesome-Sauces
Copy link
Copy Markdown
Author

Oh thanks! I can't believe it was as simple as just returning nil :(

@rivo
Copy link
Copy Markdown
Owner

rivo commented Aug 21, 2022

No problem. I'm glad I was able to help!

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