Skip to content

Commit

Permalink
Fixed Regular Expressions reserved characters not escaped in wordlist
Browse files Browse the repository at this point in the history
  • Loading branch information
Tom Doan committed May 8, 2015
1 parent b6bf196 commit 8ee1765
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 5 deletions.
17 changes: 13 additions & 4 deletions Autocomplete.ahk
Expand Up @@ -23,7 +23,7 @@ CorrectCase := True ;whether or not to fix uppercase or lowercase to match the s

NormalKeyList := "a`nb`nc`nd`ne`nf`ng`nh`ni`nj`nk`nl`nm`nn`no`np`nq`nr`ns`nt`nu`nv`nw`nx`ny`nz" ;list of key names separated by `n that make up words in upper and lower case variants
NumberKeyList := "1`n2`n3`n4`n5`n6`n7`n8`n9`n0" ;list of key names separated by `n that make up words as well as their numpad equivalents
OtherKeyList := "<`n'`n-" ;list of key names separated by `n that make up words
OtherKeyList := "<`n(`n{`n'`n-" ;list of key names separated by `n that make up words
ResetKeyList := "Esc`nSpace`nHome`nNumpadHome`nEnd`nNumpadEnd`nLeft`nNumpadLeft`nRight`nNumpadRight`nRButton`nMButton`n,`n.`n/`n[`n]`n;`n\`n=`n```n""" ;list of key names separated by `n that cause suggestions to reset
TriggerKeyList := "Tab`nEnter`nNumpadEnter" ;list of key names separated by `n that trigger completion

Expand Down Expand Up @@ -401,7 +401,11 @@ SetHotkeys(NormalKeyList,NumberKeyList,OtherKeyList,ResetKeyList,TriggerKeyList)

Suggest(CurrentWord,ByRef WordList)
{
Pattern := RegExReplace(CurrentWord,"S).","$0.*") ;subsequence matching pattern
;escape Regular Expressions reserved characters
Pattern := RegExReplace(CurrentWord,"[.?*+(){}\[\]|\\^$]","\$0")
Pattern := RegExReplace(Pattern,".+","$0.*")
;TODO: use below instead if Fuzzy Matching is enabled
;Pattern := RegExReplace(Pattern,"S).","$0.*") ;subsequence matching pattern

;treat accented characters as equivalent to their unaccented counterparts
Pattern := RegExReplace(Pattern,"S)[a" . Chr(224) . Chr(226) . "]","[a" . Chr(224) . Chr(226) . "]")
Expand Down Expand Up @@ -447,10 +451,15 @@ Score(Word,Entry)
Position ++
Score *= Position ** 8

;escape Regular Expressions reserved characters
Pattern := RegExReplace(Word,"[.?*+(){}\[\]|\\^$]","\$0")
Pattern := "`nimS)^" . SubStr(RegExReplace(Pattern,".+","$0.*"),1,-2)
;TODO: use below instead if Fuzzy Matching is enabled
;Pattern := "`nimS)^" . SubStr(RegExReplace(Pattern,"S).","$0.*"),1,-2)

;determine number of superfluous characters
RegExMatch(Entry,"`nimS)^" . SubStr(RegExReplace(Word,"S).","$0.*"),1,-2),Remaining)
RegExMatch(Entry,Pattern,Remaining)
Score *= (1 + StrLen(Remaining) - Length) ** -1.5

Score *= StrLen(Word) ** 0.4

Return, Score
Expand Down
3 changes: 2 additions & 1 deletion README.md
Expand Up @@ -32,7 +32,7 @@ Key settings are URL encoded lists of key names such as `Space` and `d` where ea
Modifications by thdoan
-----------------------

- Added support for "<" character by default (to autocomplete `<tag>`)
- Added support for characters `< ( {` by default (to autocomplete `<tag>`, etc.)
- Added support for NumPad navigation in suggestions list
- Added ability to navigate suggestions list with `PgUp`/`PgDn`
- Added ability to autocomplete code snippets with newlines (\n) and tabs (\t)
Expand All @@ -48,6 +48,7 @@ Modifications by thdoan
- Fixed "0." not displayed in suggestions list
- Fixed incompatibility bug with v1.1.20.00 and higher
- Fixed horizontal scrollbar in Preferences wordlist
- Fixed Regular Expressions reserved characters not escaped in wordlist

Licence
-------
Expand Down

0 comments on commit 8ee1765

Please sign in to comment.