Skip to content

Commit

Permalink
Only save history file when needed (file opened and no leading space)
Browse files Browse the repository at this point in the history
  • Loading branch information
AdrieanKhisbe committed Aug 29, 2018
1 parent 73e522e commit fba8357
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions quickinput-sample/src/promptCommandWithHistory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@ async function pickCommand() {
input.placeholder = 'Type a command';
input.items = commandsItems;


const updateQuickPick = value => {
if (!value) {
input.items = commandsItems;
Expand Down Expand Up @@ -72,9 +71,11 @@ async function pickCommand() {
resolve(item.label);
input.hide();
// record new input in history
fs.appendFile(historyPath, item.label + '\n', function (err) {
if (err) console.error('Problem while updating history file', err);
});
if (historyShouldBeUpdated && !item.label.startsWith(' ')) {
fs.appendFile(historyPath, item.label + '\n', function (err) {
if (err) console.error('Problem while updating history file', err);
});
}
}
}),
input.onDidHide(() => {
Expand All @@ -95,7 +96,8 @@ async function pickCommand() {
updateQuickPick(currentValue);
});
} else {
console.log('history file does not exist yet')
console.log('history file does not exist yet');
historyShouldBeUpdated = true;
}

});
Expand Down

0 comments on commit fba8357

Please sign in to comment.