Skip to content

Commit

Permalink
fix: code highlight doesn't update unless model is linked (#57)
Browse files Browse the repository at this point in the history
Fix #35
  • Loading branch information
jefrydco authored Feb 11, 2020
1 parent e421a78 commit efdd959
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
6 changes: 5 additions & 1 deletion src/components/Editor.vue
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ export default {
},
computed: {
content() {
return prism(this.codeData, this.language);
return prism(this.codeData || "", this.language);
},
lineNumbersCount() {
let totalLines = this.codeData.split(/\r\n|\n/).length;
Expand Down Expand Up @@ -346,6 +346,10 @@ export default {
}
}
if (!this.code) {
this.codeData = evt.target.innerText;
}
if (this.emitEvents) {
this.$emit("keyup", evt);
}
Expand Down
12 changes: 11 additions & 1 deletion tests/unit/Editor.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,17 @@ describe("Editor.vue", () => {
expect(wrapper.vm.code).toEqual("works");
});

it("works without v-model", () => {
const wrapper = mount(Editor, {
emitEvents: true
});

wrapper.vm.codeData = "<html>";
expect(wrapper.vm.content).toBe(
`<code class="language-js"><span class="token operator">&lt;</span>html<span class="token operator">></span></code>`
);
});

it("code with sync modifier works", () => {
const compiled = compileToFunctions(
'<div><Editor class="foo" :code.sync="code" /></div>'
Expand Down Expand Up @@ -156,7 +167,6 @@ describe("Editor.vue", () => {
});
const $pre = wrapper.find("pre");

$pre.element.dispatchEvent(new KeyboardEvent("keyup", { keyCode: 16 }));
$pre.element.dispatchEvent(new KeyboardEvent("keyup", { keyCode: 16 })); // shift
$pre.element.dispatchEvent(new KeyboardEvent("keyup", { keyCode: 17 })); // ctrl
$pre.element.dispatchEvent(new KeyboardEvent("keyup", { keyCode: 18 })); // alt
Expand Down

0 comments on commit efdd959

Please sign in to comment.