search bar filter should be case sensitive?
oupala opened this issue · 4 comments
Describe the bug
The search bar is currently case insensitive.
To Reproduce
Steps to reproduce the behavior:
- Open a page modified by apaxy
- Fill the search bar with a string
- See that the search bar is currently case insensitive
Expected behavior
I think that the search bar should be case sensitive, while I'm not sure this would be the best setting.
I'm asking opinions about that: should the search bar be case insensitive or case sensitive?
@woodrowbarlow Do you have an opinion about that?
my opinion is that case-insensitive is a sane default. apaxy is essentially a file browser, and if you open up any mainstream file browser with a graphical UI and search bar (finder, explorer, nautilus), these all use case-insensitive search. most don't even offer an option for case-sensitive search.
do you plan on adding some sort of config system? if you don't add a full-blown config system, there's still a middle ground: add a const variable to the top of apaxy.js so that users can set that variable to true or false.
diff --git a/apaxy/theme/apaxy.js b/apaxy/theme/apaxy.js
index 2cc43b8..ed6120e 100644
--- a/apaxy/theme/apaxy.js
+++ b/apaxy/theme/apaxy.js
@@ -1,3 +1,5 @@
+const FILTER_CASE_SENSITIVE = false;
+
// fix links when not adding a / at the end of the URI
var uri = window.location.pathname.substr(1);
if (uri.substring(uri.length - 1) !== '/') {
@@ -38,8 +40,13 @@ if (uri.substring(uri.length - 1) !== '/') {
}
// only check the 'name' field
- var text = row.getElementsByTagName('td')[1].textContent.toLowerCase();
- var val = _input.value.toLowerCase();
+ var text = row.getElementsByTagName('td')[1].textContent;
+ var val = _input.value;
+
+ if (!FILTER_CASE_SENSITIVE) {
+ text = text.toLowerCase();
+ val = val.toLowerCase();
+ }
// change display type to show / hide this row
row.style.display = text.indexOf(val) === -1 ? 'none' : 'table-row';
Thanks a lot @woodrowbarlow for your answer and for the patch.
I'm convinced by what you said about other file browsers. Meanwhile, a config system might a good idea.
Let's wait a little bit what does the community thinks about the case-sensitivity of the search.