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

Support Ctrl+[backspace/delete] to delete the word to the left or right of the cursor #4662

Open
wants to merge 3 commits into
base: develop
Choose a base branch
from

Conversation

dweymouth
Copy link
Contributor

@dweymouth dweymouth commented Feb 21, 2024

Adds Ctrl+Backspace and Ctrl+Delete shortcuts to Entry for deleting the word to the left and right of the cursor, respectively. On Mac OS, the modifier is option (aka alt) instead.

Fixes #4524

Checklist:

  • Tests included.
  • Lint and formatter run with no errors.
  • Tests all pass.

@coveralls
Copy link

coveralls commented Feb 21, 2024

Coverage Status

coverage: 64.797% (+0.04%) from 64.756%
when pulling da4d56c on dweymouth:ctrl-backspace
into 3c111a2 on fyne-io:develop.

@dweymouth dweymouth marked this pull request as ready for review February 21, 2024 02:42
Copy link
Member

@Jacalz Jacalz left a comment

Choose a reason for hiding this comment

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

Nice work. A much better implementation than what I had. However, I managed to get it to crash in two ways.

  1. Write a single space into the entry and move the cursor to the left.
  2. Clicking CTRL + BACKSPACE or CTRL + DELETE will now crash.
panic: runtime error: makeslice: len out of range

goroutine 66 [running]:
fyne.io/fyne/v2/widget.(*RichText).deleteFromTo(0xc00292d800, 0x14, 0x13)
	/var/home/jacob/git/fyne/widget/richtext.go:184 +0x2cf
fyne.io/fyne/v2/widget.(*Entry).deleteWord(0xc003ceb400, 0x1)
	/var/home/jacob/git/fyne/widget/entry.go:907 +0xe5
fyne.io/fyne/v2/widget.(*Entry).registerShortcut.func12({0xc003ceb450, 0xbe0d60})
	/var/home/jacob/git/fyne/widget/entry.go:1214 +0x1c
fyne.io/fyne/v2.(*ShortcutHandler).TypedShortcut(0xc003ceb450, {0xe4c340, 0xc0035ae060})
	/var/home/jacob/git/fyne/shortcut.go:21 +0x6e
fyne.io/fyne/v2/widget.(*Entry).TypedShortcut(0xc00010e360?, {0xe4c340?, 0xc0035ae060?})
	/var/home/jacob/git/fyne/widget/entry.go:963 +0x25
fyne.io/fyne/v2/internal/driver/glfw.(*window).triggersShortcut.func1()
	/var/home/jacob/git/fyne/internal/driver/glfw/window.go:907 +0x24
fyne.io/fyne/v2/internal/driver/common.(*Window).RunEventQueue(0x0?)
	/var/home/jacob/git/fyne/internal/driver/common/window.go:35 +0x38
created by fyne.io/fyne/v2/internal/driver/glfw.(*gLDriver).createWindow.func1 in goroutine 1
	/var/home/jacob/git/fyne/internal/driver/glfw/window.go:961 +0x145

@dweymouth
Copy link
Contributor Author

Hmm, I'm getting a different crash:

panic: runtime error: slice bounds out of range [-1:]

goroutine 11 [running]:
fyne.io/fyne/v2/widget.getTextWhitespaceRegion({0x1400150ff30?, 0x1?, 0x140000d0270?}, 0x14001261ef0?, 0x1)
	/Users/drew/fyne/widget/entry.go:2181 +0x17c
fyne.io/fyne/v2/widget.(*Entry).deleteWord(0x140001e8000, 0x1)
	/Users/drew/fyne/widget/entry.go:890 +0x50
fyne.io/fyne/v2/widget.(*Entry).registerShortcut.func12({0x140001e8050, 0x102a38e20})
	/Users/drew/fyne/widget/entry.go:1214 +0x24
fyne.io/fyne/v2.(*ShortcutHandler).TypedShortcut(0x140001e8050, {0x102b21258, 0x14001c84fc0})
	/Users/drew/fyne/shortcut.go:21 +0x78
fyne.io/fyne/v2/widget.(*Entry).TypedShortcut(0x14000100120?, {0x102b21258?, 0x14001c84fc0?})
	/Users/drew/fyne/widget/entry.go:963 +0x2c
fyne.io/fyne/v2/internal/driver/glfw.(*window).triggersShortcut.func1()
	/Users/drew/fyne/internal/driver/glfw/window.go:907 +0x30
fyne.io/fyne/v2/internal/driver/common.(*Window).RunEventQueue(0x0?)
	/Users/drew/fyne/internal/driver/common/window.go:35 +0x3c
created by fyne.io/fyne/v2/internal/driver/glfw.(*gLDriver).createWindow.func1 in goroutine 1
	/Users/drew/fyne/internal/driver/glfw/window.go:961 +0x150

will try to dig deeper when I have some time

@Jacalz
Copy link
Member

Jacalz commented Apr 30, 2024

@dweymouth Did you manage to have another look at it? :)

@dweymouth
Copy link
Contributor Author

@dweymouth Did you manage to have another look at it? :)

No I have not. If you happen to find the problem feel free to add a code suggestion :)

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

3 participants