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

Code difference preview #92

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
78 changes: 78 additions & 0 deletions src/renderer/components/diff/diffLine.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
<template>
<div class="diff__preview-line">
<div :style="{ backgroundColor: '#' + color.gutter }" class="diff__gutter">
<div
:style="{ borderRightColor: '#' + color.border }"
class="diff__gutter-left"
>
{{ gutter[0] }}
</div>
<div
:style="{ borderRightColor: '#' + color.border }"
class="diff__gutter-right"
>
{{ gutter[1] }}
</div>
</div>
<div :style="{ backgroundColor: '#' + color.code }" class="diff__code">
<div class="diff__code-status">
{{ status }}
</div>
<div class="diff__code-line">
{{ code }}
</div>
</div>
</div>
</template>

<script>
export default {
name: "DiffLine",
props: {
color: {
type: Object,
required: true
},
gutter: {
type: Array,
required: true
},
status: {
type: String,
required: true
},
code: {
type: String,
required: true
}
}
};
</script>

<style lang="sass">
.diff
&__preview-line, &__gutter, &__code
display: flex
flex-direction: row

&__gutter, &__code
font-size: .875rem

&__gutter-left, &__gutter-right, &__code
padding-top: 6px
padding-bottom: 6px

&__gutter-left, &__gutter-right
padding-left: 1.125rem
padding-right: 10px
border-right:
width: 1px
style: solid

&__code
padding-left: 4px
padding-right: 4px

&-status
margin-right: .875rem
</style>
65 changes: 62 additions & 3 deletions src/renderer/components/diff/diffPreview.vue
Original file line number Diff line number Diff line change
@@ -1,26 +1,85 @@
<template>
<VueScrollbar class="diff__preview">
<div>
<div v-for="(line, index) in preview" :key="index">
{{ line }}
<div v-for="(data, index) in preview" :key="index">
<diff-line
:gutter="codeGutter(data, index)"
:color="codeColor(data)"
:status="codeStatus(data)"
:code="codeLine(data)"
/>
</div>
</div>
</VueScrollbar>
</template>

<script>
import VueScrollbar from "vue2-scrollbar";
import DiffLine from "./diffLine";

export default {
name: "DiffPreview",
components: {
VueScrollbar
VueScrollbar,
DiffLine
},
props: {
preview: {
type: Array,
required: true
}
},
data() {
return {
gutterChunk: []
};
},
methods: {
codeGutter(code, index) {
let gutterData = [];
if (code.charAt(0) === "@") {
let gutterString = code.split(/@@(.*?)@@/)[1].trim();
gutterData = gutterString.split(" ");
this.gutterChunk = gutterData;
return ["", ""];
}
return this.gutterChunk;
},
codeStatus(code) {
if (code.charAt(0) !== ("@" || " ")) {
return code.charAt(0);
}
},
codeLine(code) {
if (code.charAt(0) === "@") return code;
return code.slice(1, code.length);
},
codeColor(code) {
switch (code.charAt(0)) {
case "@":
return {
code: "F1F8FF",
gutter: "DBEDFF",
border: "C8E1FF"
};
case "+":
return {
code: "E6FFED",
gutter: "CDFFD8",
border: "85E89D"
};
case "-":
return {
code: "FFEEF0",
gutter: "FFDCE0",
border: "FDAEB7"
};
case " ":
return {
border: "E1E4E8"
};
}
}
}
};
</script>
Expand Down
5 changes: 1 addition & 4 deletions src/renderer/pages/repository/history.vue
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
</VueScrollbar>
</div>
</div>
<div class="history__preview">
<div>
<diffPreview
v-if="this.$store.state.history.filePreview.isActive"
:preview="commitFileDiffPreview"
Expand Down Expand Up @@ -146,7 +146,4 @@ export default {

&__scrollbar
max-height: 90vh

&__preview
padding: 10px
</style>