Site > Viewer > Add line modifications

This commit is contained in:
brunosimon
2017-08-30 22:02:48 +02:00
parent fccffc2a2b
commit 5d745928ee
7 changed files with 154 additions and 24 deletions
+78 -2
View File
@@ -23,9 +23,85 @@ export default
return this.$store.state.files.currentVersion
},
linesCount()
lines()
{
return (this.$store.state.files.currentVersion.content.match(/\n/g) || []).length + 1
const lines = []
const lineBreaks = (this.version.content.match(/\n/g) || []).length + 1
// Create all lines
for(let i = 0; i < lineBreaks; i++)
{
const line = {}
line.index = lines.length + 1
line.added = false
line.removed = false
lines.push(line)
}
// Loop through each diff and add line infos
if(this.version.diff)
{
let lineProgress = 0
// Added lines and unchanged lines
for(const diffKey in this.version.diff)
{
const diff = this.version.diff[diffKey]
let lineBreaks = (diff.value.match(/\n/g) || []).length
if(parseInt(diffKey) === this.version.diff.length - 1)
{
lineBreaks += 1
}
if(diff.added)
{
for(let i = 0; i < lineBreaks; i++)
{
const line = lines[lineProgress + i]
line.added = true
}
}
if(!diff.removed)
{
lineProgress += lineBreaks
}
}
lineProgress = 0
// Removed lines
for(const diffKey in this.version.diff)
{
const diff = this.version.diff[diffKey]
let lineBreaks = (diff.value.match(/\n/g) || []).length
if(parseInt(diffKey) === this.version.diff.length - 1)
{
lineBreaks += 1
}
if(diff.removed)
{
const line = lines[lineProgress]
const nextLine = lines[lineProgress + 1]
if(!line.added && (!nextLine || nextLine.added === false))
{
line.removed = true
}
}
if(!diff.removed)
{
lineProgress += lineBreaks
}
}
}
return lines
}
},