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

feat: improved escape and backspace behavior in menus #719

Merged
merged 1 commit into from
Oct 21, 2023

Conversation

tomasklaen
Copy link
Owner

escape now only closes the menu, and nothing else (before it would clear search if present first).

New shortcuts:

  • ctrl+backspace - Delete search query by word.
  • shift+backspace - Clear search query.

`escape` now only closes the menu, and nothing else (before it would clear search if present first).

New shortcuts:

- `ctrl+backspace` - Delete search query by word.
- `shift+backspace` - Clear search query.
Comment on lines +820 to +828
local word_pat, other_pat = '[^%c%s%p]+$', '[%c%s%p]+$'
local init_pat = old_query:sub(#old_query):match(word_pat) and word_pat or other_pat
-- First we match all same type consecutive chars at the end
local tail = old_query:match(init_pat)
-- If there's only one, we extend the tail with opposite type chars
if tail and #tail == 1 then
tail = tail .. old_query:sub(1, #old_query - #tail):match(init_pat == word_pat and other_pat or word_pat)
end
pos = pos - #tail
Copy link
Contributor

Choose a reason for hiding this comment

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

I would have expected ctrl+backspace to always delete back to the beginning of the last word. From a quick test at least KDE things seem to consistently behave that way.

Suggested change
local word_pat, other_pat = '[^%c%s%p]+$', '[%c%s%p]+$'
local init_pat = old_query:sub(#old_query):match(word_pat) and word_pat or other_pat
-- First we match all same type consecutive chars at the end
local tail = old_query:match(init_pat)
-- If there's only one, we extend the tail with opposite type chars
if tail and #tail == 1 then
tail = tail .. old_query:sub(1, #old_query - #tail):match(init_pat == word_pat and other_pat or word_pat)
end
pos = pos - #tail
pos = old_query:find('[^%c%s%p]*[%c%s%p]*$') - 1

Copy link
Contributor

Choose a reason for hiding this comment

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

Apparently that's not the case for vscode, it behaves like your original code. It doesn't really matter i guess.

Copy link
Owner Author

Choose a reason for hiding this comment

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

Yeah I've tried making it like vscode, which is how I expected it to work from the beginning.

For example, if I have a string like:

abc.--

I'd want ctrl+backspace to end before c, not delete the whole string.

vscode has a bit more conditional behaviors, but I didn't want to make it that complex.

Choose a reason for hiding this comment

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

I would have expected ctrl+backspace to always delete back to the beginning of the last word.

This behavior is iconsistent across applications, unfortunately. Sublime Text, for example, deletes until the next boundary between word characters, punctuation, or whitespace.

@tomasklaen tomasklaen merged commit a0dccc7 into main Oct 21, 2023
@tomasklaen tomasklaen deleted the search_backspace branch October 27, 2023 07:47
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.

3 participants