Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 406
Discard lines in file diff#487
Uh oh!
There was an error while loading. Please reload this page.
Changes from all commits
5178dbfe10790beb6dcbe476e12ae3c4dafeb6d14e6ff442f02639469bd128a569a1fa2044feb4a5a4893d0df0f097782b803e8d5853b6305093966e2a97378455e3f2b1fdc042c6a61d1862a82650171d6725673f4ce849a5747ebba2bfccac3ccf357a8132adf514d72302dfb0d10a038c09f2f218fd9c8a2e0455cf459ebd6a7be5e4001738ea534bdd81d6799a05281ad98073c37bb3d953771c58203a9a6811960f93f3633d0a222b3405710918d768e3dd6f961a048a07ffcfb4684d72950b306da2195187e62f54b78833406cfcd5File filter
Filter by extension
Conversations
Uh oh!
There was an error while loading. Please reload this page.
Jump to
Uh oh!
There was an error while loading. Please reload this page.
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,35 @@ | ||
| export default function discardChangesInBuffer(buffer, filePatch, discardedLines) { | ||
| buffer.transact(() => { | ||
| let addedCount = 0; | ||
| let removedCount = 0; | ||
| let deletedCount = 0; | ||
| filePatch.getHunks().forEach(hunk => { | ||
Contributor There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. | ||
| hunk.getLines().forEach(line => { | ||
| if (discardedLines.has(line)) { | ||
| if (line.status === 'deleted') { | ||
| const row = (line.oldLineNumber - deletedCount) + addedCount - removedCount - 1; | ||
| buffer.insert([row, 0], line.text + '\n'); | ||
| addedCount++; | ||
| } else if (line.status === 'added') { | ||
| const row = line.newLineNumber + addedCount - removedCount - 1; | ||
| if (buffer.lineForRow(row) === line.text) { | ||
| buffer.deleteRow(row); | ||
| removedCount++; | ||
| } else { | ||
| throw new Error(buffer.lineForRow(row) + ' does not match ' + line.text); | ||
| } | ||
| } else if (line.status === 'nonewline') { | ||
| // TODO: handle no new line case | ||
| } else { | ||
| throw new Error(`unrecognized status: ${line.status}. Must be 'added' or 'deleted'`); | ||
| } | ||
| } | ||
| if (line.getStatus() === 'deleted') { | ||
| deletedCount++; | ||
| } | ||
| }); | ||
| }); | ||
| }); | ||
| buffer.save(); | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -9,6 +9,14 @@ export function readFile(absoluteFilePath, encoding = 'utf8') { | ||
| }); | ||
| } | ||
| export function writeFile(absoluteFilePath, contents) { | ||
| return new Promise((resolve, reject) => { | ||
| fs.writeFile(absoluteFilePath, contents, err => { | ||
Contributor There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I could swear I saw a pull request on node.js that would make Fake edit: here it is; nodejs/node#5020. Looks like it won't be in Node 6 in any case. | ||
| if (err) { return reject(err); } else { return resolve(); } | ||
| }); | ||
| }); | ||
| } | ||
| export function deleteFileOrFolder(path) { | ||
| return new Promise((resolve, reject) => { | ||
| fs.remove(path, err => { | ||
Uh oh!
There was an error while loading. Please reload this page.

There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good catch!