From da74f281fd2f857abc4b006a215fea42a20d4622 Mon Sep 17 00:00:00 2001 From: David Hall Date: Sun, 14 Aug 2016 16:16:59 +0200 Subject: [PATCH 1/2] =?UTF-8?q?Add=20support=20for=20entering=20=C3=A5,=20?= =?UTF-8?q?=C3=A4=20and=20=C3=B6=20in=20Swedish=20character=20set?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- teletext-editor.js | 27 +++++++++++++++++++++++---- 1 file changed, 23 insertions(+), 4 deletions(-) diff --git a/teletext-editor.js b/teletext-editor.js index 2eeee49..582b324 100644 --- a/teletext-editor.js +++ b/teletext-editor.js @@ -4133,17 +4133,24 @@ var keymap = function(keypress) { if ( cset == 0 && keypress == 95 ) { return 0x60; } if ( cset == 6 && keypress == 95 ) { return 0x60; } + // The Swedish character set (2) is identical to the German (1) + // for A and O with umlauts. + // German: capital A with umlaut - if ( cset == 1 && keypress == 196 ) { return 0x5b; } + if ( cset == 1 && keypress == 196 ) { return 0x5b; } + if ( cset == 2 && keypress == 196 ) { return 0x5b; } // German: lowercase a with umlaut - if ( cset == 1 && keypress == 228 ) { return 0x7b; } + if ( cset == 1 && keypress == 228 ) { return 0x7b; } + if ( cset == 2 && keypress == 228 ) { return 0x7b; } // German: capital O with umlaut - if ( cset == 1 && keypress == 214 ) { return 0x5c; } + if ( cset == 1 && keypress == 214 ) { return 0x5c; } + if ( cset == 2 && keypress == 214 ) { return 0x5c; } // German: lowercase o with umlaut - if ( cset == 1 && keypress == 246 ) { return 0x7c; } + if ( cset == 1 && keypress == 246 ) { return 0x7c; } + if ( cset == 2 && keypress == 246 ) { return 0x7c; } // German: capital U with umlaut if ( cset == 1 && keypress == 220 ) { return 0x5d; } @@ -4160,6 +4167,18 @@ var keymap = function(keypress) { // German: degree symbol if ( cset == 1 && keypress == 176 ) { return 0x60; } + // Swedish: capital A with ring + if ( cset == 2 && keypress == 197 ) { return 0x5d; } + + // Swedish: lowercase a with ring + if ( cset == 2 && keypress == 229 ) { return 0x7d; } + + // Swedish: capital U with umlaut (if entered on German keyboard) + if ( cset == 2 && keypress == 220 ) { return 0x5e; } + + // Swedish: lowercase u with umlaut (if entered on German keyboard) + if ( cset == 2 && keypress == 220 ) { return 0x7e; } + // The Hebrew alphabet. if ( cset == 6 && keypress >= 1488 && keypress <= 1514) { return 0x60 + ( keypress - 1488 ); From 21a751ad0787783b361c952f489b627a2bba358c Mon Sep 17 00:00:00 2001 From: David Hall Date: Sun, 14 Aug 2016 16:19:28 +0200 Subject: [PATCH 2/2] Add support for entering characters using dead keys MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit When characters with diacritical marks have no dedicated key on the keyboard. Support for ü and é in Swedish character set. Introduces global variable dead_key. --- teletext-editor.js | 28 +++++++++++++++++++++++++--- 1 file changed, 25 insertions(+), 3 deletions(-) diff --git a/teletext-editor.js b/teletext-editor.js index 582b324..0e14cfe 100644 --- a/teletext-editor.js +++ b/teletext-editor.js @@ -71,7 +71,8 @@ var curx = 0; // the column at which the cursor is currently. var cury = 0; // the row at which the cursor is currently. var escape = 0; // has escape been pressed? 0 if no, 1 if yes. -var statusmode = 0; // what is the statusbar showing? +var dead_key = 0; // dead key pressed previously. 0 if not, otherwise char code +var statusmode = 0; // what is the statusbar showing? // 0 means the usual information about the current cell. // 1 means the additional teletext metadata var statushidden = 1; // is the statusbar temporarily hidden with ESC-0? @@ -1288,6 +1289,11 @@ this.keydown = function(event) { // with preventDefault(). if ( code == 8 ) { event.preventDefault(); cursor_bs(); return; } if ( code == 9 ) { event.preventDefault(); cursor_tab(); return; } + + // Handle dead keys for input of diacritical marks + if ( code == 221) { dead_key = code; } + if ( code == 187) { dead_key = code; } + } this.keypress = function(event) { @@ -1296,7 +1302,10 @@ this.keypress = function(event) { // Code 0 means there was simply no keypress. if ( code == 0 ) { return; } - code = keymap(code); + code = keymap(code, dead_key); + + // If dead key was set it has been used by now + dead_key = 0 // On Internet Explorer, ESC key triggers keypress too, // so return since we've already handled ESC in keydown @@ -4114,7 +4123,7 @@ var init_font = function(charset) { // associated with the character set we're using, we convert it to its // correct teletext character set code. -var keymap = function(keypress) { +var keymap = function(keypress, dead_key) { //console.log("[key] " + keypress); @@ -4179,6 +4188,19 @@ var keymap = function(keypress) { // Swedish: lowercase u with umlaut (if entered on German keyboard) if ( cset == 2 && keypress == 220 ) { return 0x7e; } + // Swedish keyboards has no assigned keys for ü and é + // Swedish: capital U with umlaut + if ( cset == 2 && keypress == 85 && dead_key == 221 ) { return 0x5e; } + + // Swedish: lowercase u with umlaut + if ( cset == 2 && keypress == 117 && dead_key == 221 ) { return 0x7e; } + + // Swedish: capital E with accent + if ( cset == 2 && keypress == 69 && dead_key == 187 ) { return 0x40; } + + // Swedish: lowercase e with accent + if ( cset == 2 && keypress == 101 && dead_key == 187 ) { return 0x60; } + // The Hebrew alphabet. if ( cset == 6 && keypress >= 1488 && keypress <= 1514) { return 0x60 + ( keypress - 1488 );