aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAkshay Nair <phenax5@gmail.com>2024-12-26 21:53:49 +0530
committerAkshay Nair <phenax5@gmail.com>2024-12-26 21:54:13 +0530
commit3d461b234d0b30cb7085251390b264089f447a97 (patch)
tree06115a2e632baebc7516b7ef3d94719fe9c2b6df
parent2819868eb398ebe7da0e59391367e5825f8fe2c5 (diff)
downloadchelleport-3d461b234d0b30cb7085251390b264089f447a97.tar.gz
chelleport-3d461b234d0b30cb7085251390b264089f447a97.zip
Add fuzzy search for search mode
-rw-r--r--README.md2
-rw-r--r--chelleport.cabal1
-rw-r--r--src/Chelleport/AppState.hs3
3 files changed, 4 insertions, 2 deletions
diff --git a/README.md b/README.md
index 2d48431..ef1d775 100644
--- a/README.md
+++ b/README.md
@@ -6,7 +6,7 @@ Control your mouse pointer entirely with your keyboard.
## Modes
- **Labelled Hints mode (default. `ctrl+t`)**: Displays a grid overlay on your screen, where each cell is labeled with a unique two-key combination. Press the corresponding keys to move the cursor to the desired cell.
-- **Text Search mode (`ctrl+s`)**: Uses OCR to identify and highlight words on the screen, allowing you to search for text and move the cursor directly to matching text.
+- **Text Search mode (`ctrl+s`)**: Uses OCR to identify and highlight words on the screen, allowing you to fuzzy search for text and move the cursor directly to matching text.
---
diff --git a/chelleport.cabal b/chelleport.cabal
index e06cbc6..24ee97f 100644
--- a/chelleport.cabal
+++ b/chelleport.cabal
@@ -75,6 +75,7 @@ library lib-chelleport
build-depends:
bytestring,
file-embed == 0.0.16.0,
+ fuzzy == 0.1.1.0,
sdl2-ttf == 2.1.3,
vector == 0.13.1.0,
X11 == 1.10.3
diff --git a/src/Chelleport/AppState.hs b/src/Chelleport/AppState.hs
index 697e9c4..72a1afe 100644
--- a/src/Chelleport/AppState.hs
+++ b/src/Chelleport/AppState.hs
@@ -11,6 +11,7 @@ import Control.Monad (replicateM_)
import Data.Char (toLower)
import Data.List (isInfixOf)
import Data.Maybe (fromMaybe, isJust)
+import qualified Text.Fuzzy as Fuzzy
initialState :: (Monad m) => m (State, Maybe AppAction)
initialState = do
@@ -67,7 +68,7 @@ update state@(State {stateMode = ModeSearch {searchWords, searchInputText}}) (Ha
mode = stateMode state
filterMatches text
| isEmpty text = searchWords
- | otherwise = filter (isInfixOf text . map toLower . matchText) searchWords
+ | otherwise = Fuzzy.original <$> Fuzzy.filter text searchWords "" "" matchText False
-- Increment highlighted index for search mode
update state (IncrementHighlightIndex n) = do