From f2580a366d716dc68d1f6ee744d3003f06cbcfde Mon Sep 17 00:00:00 2001 From: Maxime Coste Date: Tue, 18 Aug 2015 00:19:14 +0100 Subject: Cleanup key to codepoint conversion Fixes #378 Fixes #365 --- src/keys.cc | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) (limited to 'src/keys.cc') diff --git a/src/keys.cc b/src/keys.cc index b01fcc52..349cbd53 100644 --- a/src/keys.cc +++ b/src/keys.cc @@ -10,7 +10,7 @@ namespace Kakoune { -Key canonicalize_ifn(Key key) +static Key canonicalize_ifn(Key key) { if (key.key > 0 and key.key < 27) { @@ -21,6 +21,18 @@ Key canonicalize_ifn(Key key) return key; } +Optional Key::codepoint() const +{ + if (*this == ctrl('m')) + return '\n'; + if (*this == ctrl('i')) + return '\t'; + if (modifiers == Modifiers::None and key > 27 and + (key < 0xD800 or key > 0xDFFF)) // avoid surrogates + return key; + return {}; +} + struct KeyAndName { const char* name; Codepoint key; }; static constexpr KeyAndName keynamemap[] = { { "ret", '\r' }, -- cgit v1.2.3