Skip to content

Commit

Permalink
fix: code highlight doesn't update unless model is linked
Browse files Browse the repository at this point in the history
  • Loading branch information
jefrydco committed Feb 11, 2020
1 parent e421a78 commit 7318e2d
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 7318e2d

Please sign in to comment.