Skip to content
This repository has been archived by the owner on Dec 15, 2022. It is now read-only.

'whole word' search fails when the string starts with $ (dollar sign) #576

Open
a7madgamal opened this issue Oct 28, 2015 · 12 comments
Open
Labels

Comments

@a7madgamal
Copy link

Atom 1.0.19 on Mac

$example = x;
when I search for $example and turn on 'whole word' I get 0 results and when I turn it off works normally.

As a node developer and Atom lover, I took a quick look (ok not very quick :D) and found the exact problem. for some reason, regex.exec fail to work when \b$ are next to each other.
this is from the next function inside text-buffer/lib/match-iterator.js

    Forwards.prototype.next = function() {
      var match, matchEndIndex, matchLength, matchStartIndex, submatch;
      if (match = this.regex.exec(this.text)) {
@winstliu
Copy link
Contributor

winstliu commented Nov 3, 2015

I'm going to assume that this was fixed by #583.

@winstliu winstliu closed this as completed Nov 3, 2015
@benogle
Copy link
Contributor

benogle commented Nov 4, 2015

This is still an issue because $ is not a word char.

@benogle benogle reopened this Nov 4, 2015
@benogle benogle added the bug label Nov 4, 2015
@PhiLhoSoft
Copy link

PhiLhoSoft commented Sep 1, 2016

I confirm it is still an issue even after I declared $ as a word character (for JS, Java, PHP, etc.) via the nonWordCharacters setting:

".source.stylus":
  editor:
    nonWordCharacters: "/\\()\"':,;<>~!%^&*|+=[]{}`?…"

for example.
I also removed - (and #, etc.) from non word chars, and Find in Whole word mode ignores it too. This module should take in account this setting.
Thanks.

@a7madgamal
Copy link
Author

I don't think this this should be connected or related to nonWordCharacters or any other other settings
this should work out of the box regardless of language or grammer
I'm saying this to point that even if it's fixed with nonWordCharacters it shouldn't be considered closed i think

@PhiLhoSoft
Copy link

@a7madgamal Why? The concept of word IS dependent on language. In CSS, foo-bar is a "word" (identifier), and it is not in JS. $ is allowed in identifier names in some languages, not in others. Etc.
Even in English / Markdown (for example), in-line or e-mail are words.
Beside, it will work "out of the box" as there is a default value for this setting.

@a7madgamal
Copy link
Author

a7madgamal commented Sep 3, 2016

@PhiLhoSoft mmm never thought of it like that
I still think it's better to blindly replace without considering any rules, search shouldn't assume that I'm looking for identifier or any other type, just text

if I replace $test in the whole project I don't want to think about every file grammer, I just want to see ALL the results where this TEXT is found and followed only by a white character, end of line or a new line.

processing this will probably make the search slower, introduce more issues in the future for current and new grammers

the find and replace in project is crucial to all developers, failing to detect some or all results for find and replace can be disastrous and very hard to fix specially if the tool I probably use fails me. I was really annoyed when i found this issue by luck seeing the exact string I'm looking for in front of me but not detected by atom, you don't want that :D

@PhiLhoSoft
Copy link

@a7madgamal I am not sure what you are talking about.
Here, the discussion is about the "Whole word" option of the search. Which is generally used to find identifiers: we want to find the fooBar variable, not the fooBarWithSuffix one.
If you don't want the feature, just deactivate it.

It can be done with regular expressions, but that's more typing, and potentially escaping.

@a7madgamal
Copy link
Author

@PhiLhoSoft I don't think "whole word" is tied to variables only.
I'm not an expert so whatever the maintainers think is fine by me, maybe I was using it wrong my whole life!

@menocomp
Copy link

The issue is still there. However, I found a different workaround by using regular expression search. So if you are searching for $example write it in the search box as [$]example and tick regex search box and then hit search.

@mikebronner
Copy link

I would agree that this is still an issue. For the purposes of searching, any consecutive set characters should be considered a word, determined only be surrounding whitespace.

@Daijobou
Copy link

Daijobou commented Feb 27, 2018

I want report this issue too. Thats very frustrating for PHP/JavaScript developers.

@tkulis

This comment has been minimized.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

8 participants