Skip to content

Commit

Permalink
支持中英文模式切换
Browse files Browse the repository at this point in the history
  • Loading branch information
baiyuanneko committed Aug 19, 2023
1 parent 0069358 commit 04bfb2a
Showing 1 changed file with 25 additions and 2 deletions.
27 changes: 25 additions & 2 deletions simple-input-method/simple-input-method.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ var SimpleInputMethod =
pageCount: 0, // 总页数
doublePinyinModeEnabled: false,
doublePinyinTypeIfEnabled: "",
isInEnglishMode: true,
doublePinyinMapping: {
"patterns": [
{
Expand Down Expand Up @@ -231,8 +232,12 @@ var SimpleInputMethod =
var preventDefault = false;
if(keyCode >= 65 && keyCode <= 90) // A-Z
{
that.addChar(String.fromCharCode(keyCode+32), this);
preventDefault = true;
if (that.isInEnglishMode) {
preventDefault = false;
} else {
that.addChar(String.fromCharCode(keyCode+32), this);
preventDefault = true;
}
}
else if(keyCode == 8 && that.pinyin) // 删除键
{
Expand Down Expand Up @@ -261,6 +266,21 @@ var SimpleInputMethod =
that.refreshPage();
preventDefault = true;
}
else if(e.ctrlKey && keyCode === 32)
{
that.isInEnglishMode = !that.isInEnglishMode;
preventDefault = true;
}
else if(e.shiftKey)
{
that.isInEnglishMode = !that.isInEnglishMode;
preventDefault = true;
}
else if(e.shiftKey && keyCode === 32)
{
that.isInEnglishMode = !that.isInEnglishMode;
preventDefault = true;
}
else if(keyCode === 33 || keyCode === 189 || keyCode === 173 || keyCode === 34 || keyCode === 187 || keyCode === 61) {
preventDefault = true;
}
Expand Down Expand Up @@ -361,6 +381,9 @@ var SimpleInputMethod =
},
addChar: function(ch, obj)
{
if(this.isInEnglishMode){
return;
}
if(this.pinyin.length == 0) // 长度为1,显示输入法
{
this.show(obj);
Expand Down

0 comments on commit 04bfb2a

Please sign in to comment.