c Tests that readonly groups are correctly compiled
c Uses https://help.keyman.com/developer/language/guide/casing-support

c Sample English keyboard with start-of-sentence detection
store(&VERSION) '10.0'
store(&NAME) 'test_readonly_groups'
store(&TARGETS) 'any'

c Note three entry points, rather than the traditional single entry point

begin Unicode > use(main)
begin NewContext > use(NewContext)
begin PostKeystroke > use(PostKeystroke)

c This tells Keyman which keys should have casing behavior applied
store(&CasedKeys) [K_A] .. [K_Z]

c We'll define some useful stores here
store(key) [K_A] .. [K_Z] [SHIFT K_A] .. [SHIFT K_Z]
store(out) 'a' .. 'z'     'A' .. 'Z'

store(caps) 'A'..'Z'
store(digit) '0'..'9'

group(NewContext) readonly
    c Any time we get a new context, by mouse click, tap,
    c cursor movement, new document, etc, we'll try and
    c determine the best layer to use
    nomatch > use(detectStartOfSentence)

group(PostKeystroke) readonly
    c We get here after every keystroke and model action is processed

    c Okay, let's stay on the numeric layer if we are there already
    if(&newLayer = "") if(&layer = 'numeric') any(digit) > context

    c Don't swap off the caps lock layer automatically
    if(&layer = 'caps') > context

    c no other changes, so detect sentence or layer change, as long
    c as the user hasn't attempted to change layer themselves.
    if(&newLayer = "") > use(detectStartOfSentence)

group(detectStartOfSentence) readonly
    c We have a shared group for the start of sentence detection now
    c which will set the current layer according to the current context.

    c Some common end-of-sentence punctuation
    store(sentencePunctuation) '.?!'

    c If we are at the start of a text field, we're at the 'start of a
    c sentence', so we'll move to the Shift layer
    nul > layer('shift')

    c Otherwise, we'll move to the Shift layer only if we see end of a
    c sentence followed by one or two spaces.
    any(sentencePunctuation) ' ' > layer('shift')
    any(sentencePunctuation) '  ' > layer('shift')

    c And because we haven't see any of these situations above, we'll
    c move to the default layer. Note that this effectively drops us
    c back to the default layer after every keystroke that isn't blocked
    c by the `PostKeystroke` or early `detectStartOfSentence` rules.
    nomatch > layer('default')

group(main) using keys
    + any(key) > index(out, 1)

