Skip to content

Instantly share code, notes, and snippets.

@sainu
Created November 14, 2017 14:37
Show Gist options
  • Save sainu/50e71dd3157d9890eb280d684159ce34 to your computer and use it in GitHub Desktop.
Save sainu/50e71dd3157d9890eb280d684159ce34 to your computer and use it in GitHub Desktop.
日本語入力が確定しているかどうかを判定するクラス
/*
* How to use in Vue
* export default {
* template: `
* <input type="text" @keydown="imeChecker.keydownEvent" @keyup.enter="keyupEvent">
* `,
* data() {
* return {
* imeChecker: new ImeChecker()
* }
* },
* methods: {
* keyupEvent($event) {
* if (imeChecker.imeIsNotActive) {
* do something...
* }
* }
* }
* }
*/
export default class ImeChecker {
constructor() {
this.imeFlag = false;
}
keydownEvent(e) {
this.imeFlag = e.keyCode == 229;
}
// 日本語入力が確定しているかどうか
// 確定している true
// 確定していない false
get imeIsNotActive() {
return !this.imeFlag;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment