From 0834d6b78362befbd19b3b88b9d503e41895c8ff Mon Sep 17 00:00:00 2001 From: psoukie Date: Wed, 28 Dec 2022 12:42:38 -0800 Subject: [PATCH 1/2] Refactored suffixes and prefixes to affixes --- source/zipchord.ahk | 39 +++++++++++++++++++++++---------------- 1 file changed, 23 insertions(+), 16 deletions(-) diff --git a/source/zipchord.ahk b/source/zipchord.ahk index 161677f..0d0b210 100644 --- a/source/zipchord.ahk +++ b/source/zipchord.ahk @@ -28,6 +28,11 @@ Class localeClass { ; stores current locale information keys := New localeClass +; affixes constants +global AFFIX_NONE := 0 ; no prefix or suffix +global AFFIX_PREFIX := 1 ; expansion is a prefix +global AFFIX_SUFFIX := 2 ; expansion is a suffix + ; capitalization constants global CAP_OFF = 1 ; no auto-capitalization, global CAP_CHORDS = 2 ; auto-capitalize chords only @@ -319,26 +324,14 @@ KeyUp: expanded := chords[chord] ; store the expanded text shorthand_buffer := "" debug.Log("Chord for:" expanded) - ; detect and adjust expansion for suffixes and prefixes - if (SubStr(expanded, 1, 1) == "~") { - expanded := SubStr(expanded, 2) - suffix := true - } else { - suffix := false - } - if (SubStr(expanded, StrLen(expanded), 1) == "~") { - expanded := SubStr(expanded, 1, StrLen(expanded)-1) - prefix := true - } else { - prefix := false - } + affixes := ProcessAffixes(expanded) ; if we aren't restricted, we print a chord - if (suffix || IsUnrestricted()) { + if ( (affixes & AFFIX_SUFFIX) || IsUnrestricted()) { if (settings.output_delay) Sleep settings.output_delay debug.Log("OUTPUTTING") RemoveRawChord(chord) - OpeningSpace(suffix) + OpeningSpace(affixes & AFFIX_SUFFIX) if (InStr(expanded, "{")) { ; we send any expanded text that includes { as straight directives: SendInput % expanded @@ -351,7 +344,7 @@ KeyUp: } last_output := OUT_CHARACTER | OUT_AUTOMATIC ; i.e. a chord (automated typing) ; ending smart space - if (prefix) { + if (affixes & AFFIX_PREFIX) { last_output |= OUT_PREFIX } else if (settings.spacing & SPACE_AFTER_CHORD) { SendInput {Space} @@ -379,6 +372,20 @@ Return ; Helper functions +; detect and adjust expansion for suffixes and prefixes +ProcessAffixes(ByRef phrase) { + affixes := AFFIX_NONE + if (SubStr(phrase, 1, 1) == "~") { + phrase := SubStr(phrase, 2) + affixes |= AFFIX_SUFFIX + } + if (SubStr(phrase, StrLen(phrase), 1) == "~") { + phrase := SubStr(phrase, 1, StrLen(phrase)-1) + affixes |= AFFIX_PREFIX + } + Return affixes +} + ;remove raw chord output RemoveRawChord(output) { adj :=0 From 78c501c4ddd1f42fe6ddd907d768b3c152d82fee Mon Sep 17 00:00:00 2001 From: psoukie Date: Wed, 28 Dec 2022 12:55:02 -0800 Subject: [PATCH 2/2] Basic affixes support in shorthands --- source/zipchord.ahk | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/source/zipchord.ahk b/source/zipchord.ahk index 0d0b210..c4a8293 100644 --- a/source/zipchord.ahk +++ b/source/zipchord.ahk @@ -206,8 +206,11 @@ KeyDown: debug.Log("BUFFER " shorthand_buffer) if (shorthands.HasKey(shorthand_buffer)) { expanded := shorthands[shorthand_buffer] + affixes := ProcessAffixes(expanded) debug.Log("SHORTHAND " expanded) adj := StrLen(shorthand_buffer) + 1 + if (affixes & AFFIX_SUFFIX) + adj++ SendInput {Backspace %adj%} if (capitalize_shorthand) SendInput % "{Text}" RegExReplace(expanded, "(^.)", "$U1") @@ -217,6 +220,8 @@ KeyDown: SendInput +%key% else SendInput %key% + if (key == " " && (affixes & AFFIX_PREFIX)) + SendInput {Backspace} } } shorthand_buffer := ""