Commit e9026158 authored by Phil Hughes's avatar Phil Hughes

changed data into a array of objects

this saves a load of computational stuff happening in the template
the data the template recieves is the data that should be rendered
parent f50c6977
...@@ -25,16 +25,19 @@ export default { ...@@ -25,16 +25,19 @@ export default {
}, },
computed: { computed: {
allLines() { allLines() {
return this.text.replace(/\n$/g, '\n\n').split('\n'); return this.text.split('\n').map((line, i) => ({
text: line.substr(0, this.getLineLength(i)) || ' ',
highlightedText: line.substr(this.getLineLength(i)),
}));
}, },
}, },
methods: { methods: {
handleScroll() { handleScroll() {
this.$nextTick(() => {
if (this.$refs.textarea) { if (this.$refs.textarea) {
this.$nextTick(() => {
this.scrollTop = this.$refs.textarea.scrollTop; this.scrollTop = this.$refs.textarea.scrollTop;
}
}); });
}
}, },
getLineLength(i) { getLineLength(i) {
return i === 0 ? MAX_TITLE_LENGTH : MAX_BODY_LENGTH; return i === 0 ? MAX_TITLE_LENGTH : MAX_BODY_LENGTH;
...@@ -99,11 +102,11 @@ export default { ...@@ -99,11 +102,11 @@ export default {
:key="index" :key="index"
> >
<span <span
v-text="line.substr(0, getLineLength(index)) || ' '" v-text="line.text"
> >
</span><mark </span><mark
v-show="line.length > getLineLength(index)" v-show="line.highlightedText"
v-text="line.substr(getLineLength(index))" v-text="line.highlightedText"
> >
</mark> </mark>
</div> </div>
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment