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

better swipe to delete word #725

Merged
merged 3 commits into from
Feb 17, 2024
Merged

better swipe to delete word #725

merged 3 commits into from
Feb 17, 2024

Conversation

pxeemo
Copy link
Contributor

@pxeemo pxeemo commented Feb 14, 2024

this pattern doesn't separate words only by spaces for example links that were known as one word, now will be deleted like this:
https :// github. com/ => 4 words

@dessalines
Copy link
Owner

This is just for links specifically? I'm not sure why that would be preferred over simple word deletes.

Where did this complicated regex come from? Regex("^\\s?(\\w+\\W?|[^\\s\\w]+|\\s+)")

@pxeemo
Copy link
Contributor Author

pxeemo commented Feb 15, 2024

^ for starting the line (to just match the first after cursor)
$ for end of the line (to match the last one before cursor)
\\s matches whitespaces (spaces, tabs, break lines, ...)
? means one or none
\\w is for characters used in words (A to Z, a to z, 0 to 9 and particularly _, for all languages)
\\W is for non-word characters (.,!?-*;:=+({[]}), ... and whitespaces)
+ means one or more
* means none or many
[^\\s\\w]: not whitespaces (\\s) and not word characters (\\w)
(one|two): matches "one" or "two"

so simply it's not used only for links it matches:

  • a whitespace (if exist) and one word and a non-word character after that (if exist) (matches end of the line signs)
  • non-word and non-whitespace characters together (..., == like in codes or link :// or any other)
  • all the whitespaces together

and delete last word regex matches:

  • one word and a non-word character after that (if exist) and any whitespaces after that (if exist)
  • non-word and non-whitespace characters together and any whitespaces after that (if exits)
  • delete all whitespaces if there isn't any words

then it can split things like math (123+635=??) and codes in any language print("hello_world") and any others those not separated with spaces (like thumb-key) (it also has the same functionality as before)

@dessalines
Copy link
Owner

Did you come up with this regex on your own? Is there an SO link or something for this desired pattern?

@pxeemo
Copy link
Contributor Author

pxeemo commented Feb 16, 2024

I actually wrote it myself but it can be tested in sites like regex101.com it also has explaination in right panel
Screenshot_20240216-182838_Firefox
I was thinking it was better to remove \W? or change it to [^\s\w]? to not match space after word in this regex. I also tested it on a debug build and worked fine.

Copy link
Owner

@dessalines dessalines left a comment

Choose a reason for hiding this comment

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

K I tested and it seemed to work well. In the future add some code comments as to what this matches for.

@dessalines dessalines merged commit aef51ae into dessalines:main Feb 17, 2024
1 check passed
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

2 participants