Make oneshot stay active across layer changes
This commit is contained in:
		@@ -1,5 +1,6 @@
 | 
			
		||||
from kmk.keys import make_argumented_key
 | 
			
		||||
from kmk.modules.holdtap import ActivationType, HoldTap, HoldTapKeyMeta
 | 
			
		||||
from kmk.modules.layers import LayerKeyMeta
 | 
			
		||||
from kmk.utils import Debug
 | 
			
		||||
 | 
			
		||||
debug = Debug(__name__)
 | 
			
		||||
@@ -31,7 +32,9 @@ class OneShot(HoldTap):
 | 
			
		||||
            if key == current_key:
 | 
			
		||||
                continue
 | 
			
		||||
 | 
			
		||||
            if isinstance(current_key.meta, OneShotKeyMeta):
 | 
			
		||||
            if (isinstance(current_key.meta, OneShotKeyMeta)) or (
 | 
			
		||||
                isinstance(current_key.meta, LayerKeyMeta)
 | 
			
		||||
            ):
 | 
			
		||||
                keyboard.cancel_timeout(state.timeout_key)
 | 
			
		||||
                if key.meta.tap_time is None:
 | 
			
		||||
                    tap_time = self.tap_time
 | 
			
		||||
@@ -50,13 +53,14 @@ class OneShot(HoldTap):
 | 
			
		||||
            elif state.activated == ActivationType.INTERRUPTED:
 | 
			
		||||
                if is_pressed:
 | 
			
		||||
                    send_buffer = True
 | 
			
		||||
                keyboard.set_timeout(0, lambda k=key: self.ht_released(k, keyboard))
 | 
			
		||||
                self.key_buffer.insert(0, (0, key, False))
 | 
			
		||||
 | 
			
		||||
        if send_buffer:
 | 
			
		||||
            self.key_buffer.append((int_coord, current_key, is_pressed))
 | 
			
		||||
            keyboard.set_timeout(0, lambda: self.send_key_buffer(keyboard))
 | 
			
		||||
            current_key = None
 | 
			
		||||
 | 
			
		||||
        self.send_key_buffer(keyboard)
 | 
			
		||||
 | 
			
		||||
        return current_key
 | 
			
		||||
 | 
			
		||||
    def osk_pressed(self, key, keyboard, *args, **kwargs):
 | 
			
		||||
 
 | 
			
		||||
@@ -1,6 +1,7 @@
 | 
			
		||||
import unittest
 | 
			
		||||
 | 
			
		||||
from kmk.keys import KC
 | 
			
		||||
from kmk.modules.layers import Layers
 | 
			
		||||
from kmk.modules.oneshot import OneShot
 | 
			
		||||
from tests.keyboard_test import KeyboardTest
 | 
			
		||||
 | 
			
		||||
@@ -8,17 +9,17 @@ from tests.keyboard_test import KeyboardTest
 | 
			
		||||
class TestHoldTap(unittest.TestCase):
 | 
			
		||||
    def test_oneshot(self):
 | 
			
		||||
        keyboard = KeyboardTest(
 | 
			
		||||
            [OneShot()],
 | 
			
		||||
            [Layers(), OneShot()],
 | 
			
		||||
            [
 | 
			
		||||
                [
 | 
			
		||||
                    KC.A,
 | 
			
		||||
                    KC.B,
 | 
			
		||||
                    KC.OS(KC.MO(1), tap_time=50),
 | 
			
		||||
                    KC.MO(1),
 | 
			
		||||
                    KC.C,
 | 
			
		||||
                    KC.D,
 | 
			
		||||
                    KC.OS(KC.E, tap_time=50),
 | 
			
		||||
                    KC.OS(KC.F, tap_time=50),
 | 
			
		||||
                ],
 | 
			
		||||
                [KC.N0, KC.N1, KC.N2, KC.N3, KC.N4],
 | 
			
		||||
                [KC.N0, KC.N1, KC.N2, KC.N3, KC.OS(KC.LSFT, tap_time=50), KC.TRNS],
 | 
			
		||||
            ],
 | 
			
		||||
            debug_enabled=False,
 | 
			
		||||
        )
 | 
			
		||||
@@ -93,7 +94,7 @@ class TestHoldTap(unittest.TestCase):
 | 
			
		||||
                (3, True),
 | 
			
		||||
                (3, False),
 | 
			
		||||
            ],
 | 
			
		||||
            [{KC.E}, {KC.E, KC.F}, {KC.E, KC.F, KC.D}, {KC.E, KC.F}, {KC.F}, {}],
 | 
			
		||||
            [{KC.E}, {KC.E, KC.F}, {KC.E, KC.F, KC.D}, {KC.E, KC.F}, {KC.E}, {}],
 | 
			
		||||
        )
 | 
			
		||||
 | 
			
		||||
        keyboard.test(
 | 
			
		||||
@@ -109,3 +110,38 @@ class TestHoldTap(unittest.TestCase):
 | 
			
		||||
            ],
 | 
			
		||||
            [{KC.E}, {KC.E, KC.F}, {KC.E}, {}, {KC.D}, {}],
 | 
			
		||||
        )
 | 
			
		||||
 | 
			
		||||
        keyboard.test(
 | 
			
		||||
            'OS stacking with OS-layer',
 | 
			
		||||
            [
 | 
			
		||||
                (0, True),
 | 
			
		||||
                (0, False),
 | 
			
		||||
                (4, True),
 | 
			
		||||
                (4, False),
 | 
			
		||||
                (1, True),
 | 
			
		||||
                (1, False),
 | 
			
		||||
            ],
 | 
			
		||||
            [{KC.LSFT}, {KC.LSFT, KC.N1}, {KC.LSFT}, {}],
 | 
			
		||||
        )
 | 
			
		||||
 | 
			
		||||
        keyboard.test(
 | 
			
		||||
            'OS stacking with layer change',
 | 
			
		||||
            [
 | 
			
		||||
                (1, True),
 | 
			
		||||
                (4, True),
 | 
			
		||||
                (4, False),
 | 
			
		||||
                (1, False),
 | 
			
		||||
                (4, True),
 | 
			
		||||
                (4, False),
 | 
			
		||||
                (2, True),
 | 
			
		||||
                (2, False),
 | 
			
		||||
            ],
 | 
			
		||||
            [
 | 
			
		||||
                {KC.LSFT},
 | 
			
		||||
                {KC.LSFT, KC.E},
 | 
			
		||||
                {KC.LSFT, KC.E, KC.C},
 | 
			
		||||
                {KC.LSFT, KC.E},
 | 
			
		||||
                {KC.LSFT},
 | 
			
		||||
                {},
 | 
			
		||||
            ],
 | 
			
		||||
        )
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user