Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Partial fix for #9. Swedish chars plus dead key input method #46

Merged
merged 2 commits into from
Aug 29, 2016
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
55 changes: 48 additions & 7 deletions teletext-editor.js
Original file line number Diff line number Diff line change
Expand Up @@ -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?
Expand Down Expand Up @@ -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) {
Expand All @@ -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
Expand Down Expand Up @@ -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);

Expand All @@ -4133,17 +4142,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; }
Expand All @@ -4160,6 +4176,31 @@ 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; }

// 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 );
Expand Down