diff --git a/build.sh b/build.sh index d16a029..2bc251a 100755 --- a/build.sh +++ b/build.sh @@ -1,12 +1,15 @@ #!/bin/bash set -e -[ -z $EM_DIR] && EM_DIR=~/src/emscripten +[ -z "$EM_DIR" ] && EM_DIR=~/src/emscripten + +OPTZ="-Oz -O3" do_config() { echo config # something wrong with emcc + cproto, use gcc as CPP instead -CPPFLAGS="-Os -DFEAT_GUI_WEB" \ -CPP="gcc -E" \ +CPPFLAGS="$OPTZ -DFEAT_GUI_WEB" \ +CFLAGS="$OPTZ" \ +CPP="emcc -E" \ $EM_DIR/emconfigure ./configure \ --enable-gui=web \ --with-features=small \ @@ -46,7 +49,7 @@ $EM_DIR/emconfigure ./configure \ } do_make() { -$EM_DIR/emmake make -j8 +$EM_DIR/emmake make CFLAGS="$OPTZ" -j8 } do_link() { @@ -58,7 +61,7 @@ cat vim_lib.js | sed -e "1 s/\(foldmethod\|foldmarker\)[^ ]\+//g" > usr/local/sh # Use vim.js as filename to generate vim.js.mem $EM_DIR/emcc vim.bc \ -o vim.js \ - -Oz \ + $OPTZ \ --memory-init-file 1 \ --js-library vim_lib.js \ -s ASYNCIFY=1 \ diff --git a/web/usr/local/share/vim/vimrc b/web/usr/local/share/vim/vimrc index 39cf7e4..b99c257 100644 --- a/web/usr/local/share/vim/vimrc +++ b/web/usr/local/share/vim/vimrc @@ -55,6 +55,8 @@ set wildmenu set tabstop=4 set expandtab set nocompatible +set encoding=utf8 +set termencoding=utf8 set fileencodings=utf8 set backspace=indent,eol,start set wildmode=longest,list,full diff --git a/web/vim_lib.js b/web/vim_lib.js index 0792b28..ec9877c 100644 --- a/web/vim_lib.js +++ b/web/vim_lib.js @@ -86,13 +86,27 @@ var LibraryVIM = { if(charCode == 0) { var special = vimjs.special_keys[keyCode]; if(special !== undefined) { - vimjs.gui_web_handle_key(charCode || keyCode, modifiers, special.charCodeAt(0), special.charCodeAt(1)); + vimjs.gui_web_handle_key(keyCode, modifiers, special.charCodeAt(0), special.charCodeAt(1)); handled = true; - } + } else { + vimjs.gui_web_handle_key(keyCode, modifiers, 0, 0); + handled = true; + } } - if(!handled) - vimjs.gui_web_handle_key(charCode || keyCode, modifiers, 0, 0); + if(!handled) { + var MAX_UTF8_BYTES = 6; + var chars = new Uint8Array(MAX_UTF8_BYTES + 1); // null-terminated + var charLen = stringToUTF8Array(String.fromCharCode(charCode), chars, 0, MAX_UTF8_BYTES); + if (charLen == 1) { + vimjs.gui_web_handle_key(chars[0], 0, 0, 0); + } else { + // no modifers for UTF-8, should be handled in chars already + for (var i = 0; i < charLen; i++) { + vimjs.gui_web_handle_key(chars[i], 0, 0, 0); + } + } + } },//VIMJS_FOLD_END @@ -685,6 +699,7 @@ var LibraryVIM = { * C means "needed for Chrome" */ var keys_to_intercept_upon_keydown = {}; + var ctrl_keys_to_intercept_upon_keydown = {}; [ KeyEvent.DOM_VK_ESCAPE, // CF KeyEvent.DOM_VK_TAB, // C KeyEvent.DOM_VK_BACK_SPACE, // C @@ -695,14 +710,24 @@ var LibraryVIM = { KeyEvent.DOM_VK_DELETE, // C KeyEvent.DOM_VK_PAGE_UP, // C KeyEvent.DOM_VK_PAGE_DOWN, // C + KeyEvent.DOM_VK_HOME, // C + KeyEvent.DOM_VK_END, // C ].forEach(function(k) { keys_to_intercept_upon_keydown[k] = 1; }); + [ + KeyEvent.DOM_VK_F, + KeyEvent.DOM_VK_B, + ].forEach(function(k) { + ctrl_keys_to_intercept_upon_keydown[k] = 1; + }); + /* capture some special keys that won't trigger 'keypress' */ document.addEventListener('keydown', function(e) { if (ignoreKeys()) return true; - if(e.keyCode in keys_to_intercept_upon_keydown) { + if((e.keyCode in keys_to_intercept_upon_keydown) || + (e.ctrlKey && (e.keyCode in ctrl_keys_to_intercept_upon_keydown))) { e.preventDefault(); vimjs.handle_key(0, e.keyCode, e); } @@ -778,7 +803,15 @@ var LibraryVIM = { }, vimjs_draw_string__deps: ['vimjs_clear_block'], - vimjs_draw_string: function(row, col, s, len, flags) { + vimjs_draw_string: function(row, col, s_ptr, len, flags) { + var byteArray = []; + for (var i = 0; i < len; i++) { + c = getValue(s_ptr + i, 'i8', true); + byteArray.push(c); + } + byteArray.push(0); + var s = UTF8ArrayToString(byteArray, 0); + len = s.length; // TODO: use macros for flag constants if(!(flags & 0x01)) { @@ -788,8 +821,6 @@ var LibraryVIM = { var font = vimjs.font; if(flags & 0x02) font = 'bold ' + font; - s = Pointer_stringify(s, len); - var ctx = vimjs.canvas_ctx; ctx.font = font;