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

Fix view is updated unintentionally when inputting words via input method #16

Merged
merged 2 commits into from
Apr 27, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
49 changes: 42 additions & 7 deletions src/components/Editor.vue
Original file line number Diff line number Diff line change
@@ -1,12 +1,28 @@
<template>
<div class="prism-editor-wrapper">
<div class="prism-editor__line-numbers" aria-hidden="true" v-if="lineNumbers" :style="{'min-height': lineNumbersHeight}">
<div class="prism-editor__line-width-calc" style="height: 0px; visibility: hidden; pointer-events: none;">999</div>
<div class="prism-editor__line-number token comment" v-for="line in lineNumbersCount" :key="line">{{line}}</div>
<div
class="prism-editor__line-numbers"
aria-hidden="true"
v-if="lineNumbers"
:style="{ 'min-height': lineNumbersHeight }"
>
<div
class="prism-editor__line-width-calc"
style="height: 0px; visibility: hidden; pointer-events: none;"
>
999
</div>
<div
class="prism-editor__line-number token comment"
v-for="line in lineNumbersCount"
:key="line"
>
{{ line }}
</div>
</div>
<pre
class="prism-editor__code"
:class="{['language-'+language]: true}"
:class="{ ['language-' + language]: true }"
ref="pre"
v-html="content"
:contenteditable="!readonly"
Expand All @@ -18,7 +34,7 @@
autocomplete="off"
autocorrect="off"
data-gramm="false"
></pre>
></pre>
</div>
</template>

Expand Down Expand Up @@ -69,7 +85,8 @@ export default {
undoOffset: 0,
undoTimestamp: 0,
lastPos: 0,
codeData: ""
codeData: "",
composing: false
};
},
watch: {
Expand Down Expand Up @@ -141,6 +158,13 @@ export default {
this.$once("hook:beforeDestroy", () => {
$pre.removeEventListener("paste", onPaste);
});
$pre.addEventListener("compositionstart", () => {
this.composing = true;
});
$pre.addEventListener("compositionend", () => {
// for canceling input.
this.composing = false;
});
},

methods: {
Expand Down Expand Up @@ -304,6 +328,18 @@ export default {
}
},
handleKeyUp(evt) {
const keyupCode = evt.which;
if (this.composing) {
if (keyupCode === 13) {
// finish inputting via IM.
this.composing = false;
} else {
// now inputting words using IM.
// must not update view.
return;
}
}

if (this.emitEvents) {
this.$emit("keyup", evt);
}
Expand Down Expand Up @@ -341,7 +377,6 @@ export default {
};
</script>


<style>
.prism-editor-wrapper code {
font-family: inherit;
Expand Down