Skip to content

Commit

Permalink
Fixed default shortcutPos and capslock
Browse files Browse the repository at this point in the history
  • Loading branch information
39aldo39 committed Dec 3, 2016
1 parent dc51d10 commit ed32772
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 9 deletions.
4 changes: 2 additions & 2 deletions doc/key.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ Shortcut position

The `shortcutPos` attribute corresponds to the position used in shortcuts. If `qwertyShortcuts` is `true`, it will be set to the QWERTY location.

By default, the shortcut position will be the (QWERTY) position of the first character. If the first character has no corresponding position, the shortcut position will be the same as the normal position.
By default, the shortcut position will be the (QWERTY) position of the default letter. That is, the letter that is typed when no modifier is pressed. If the default letter has no corresponding position, the shortcut position will be the same as the normal position.

Letters
-------
Expand All @@ -79,7 +79,7 @@ Caps Lock

The `capslock` attribute corresponds to the influence of the Caps Lock state. If `capslock` is `true` and Caps Lock is active, the pressed letter will be capitalized. If `capslock` is `false`, the Caps Lock state will be ignored.

By default, Caps Lock will be set iff the first letter is an alphabetic character.
By default, Caps Lock will be set iff the default letter is an alphabetic character. The default letter is the letter that is types when no modifiers are pressed.

Filter
------
Expand Down
14 changes: 7 additions & 7 deletions src/Layout/Key.hs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ module Layout.Key
import BasePrelude
import Prelude.Unicode hiding ((∈))
import Data.Foldable.Unicode ((∈))
import Data.Monoid.Unicode ((⊕))
import Data.Monoid.Unicode ((∅), (⊕))
import qualified Data.Set.Unicode as S
import Util (HumanReadable(..), lensWithDefault, expectedKeys, (!?), (>$>), combineWithOn, nubWithOn, split)

Expand Down Expand Up @@ -173,17 +173,17 @@ data Key = Key
makeLenses ''Key
_shortcutPos Lens' Key Pos
_shortcutPos = lensWithDefault guess (\y x x {keyShortcutPos = y}) keyShortcutPos
where guess = liftA2 shortcutPosGuess __pos __letters
where guess = liftA2 shortcutPosGuess __pos id
_capslock Lens' Key Bool
_capslock = lensWithDefault guess (\y x x {keyCapslock = y}) keyCapslock
where guess = capslockGuess __letters
where guess = capslockGuess

shortcutPosGuess Pos [Letter] Pos
shortcutPosGuess Pos Key Pos
shortcutPosGuess p =
(listToMaybe >=> letterToChar >=> toUpper >>> (:[]) >>> parseString) >>> fromMaybe p
(flip getLetter (∅) >>> letterToChar >=> toUpper >>> (:[]) >>> parseString) >>> fromMaybe p

capslockGuess [Letter] Bool
capslockGuess = (listToMaybe >=> letterToChar >$> isAlpha) >>> fromMaybe False
capslockGuess Key Bool
capslockGuess = (flip getLetter (∅) >>> letterToChar >$> isAlpha) >>> fromMaybe False

instance ToJSON Key where
toJSON (Key pos maybeShortcutPos shiftstates letters maybeCapslock) = object $
Expand Down

0 comments on commit ed32772

Please sign in to comment.