Skip to content

Commit 253d2f4

Browse files
committed
Only save history file when needed (file opened and no leading space)
1 parent afae9d4 commit 253d2f4

File tree

1 file changed

+7
-5
lines changed

1 file changed

+7
-5
lines changed

quickinput-sample/src/promptCommandWithHistory.ts

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,6 @@ async function pickCommand() {
4343
input.placeholder = 'Type a command';
4444
input.items = commandsItems;
4545

46-
4746
const updateQuickPick = value => {
4847
if (!value) {
4948
input.items = commandsItems;
@@ -72,9 +71,11 @@ async function pickCommand() {
7271
resolve(item.label);
7372
input.hide();
7473
// record new input in history
75-
fs.appendFile(historyPath, item.label + '\n', function (err) {
76-
if (err) console.error('Problem while updating history file', err);
77-
});
74+
if (historyShouldBeUpdated && !item.label.startsWith(' ')) {
75+
fs.appendFile(historyPath, item.label + '\n', function (err) {
76+
if (err) console.error('Problem while updating history file', err);
77+
});
78+
}
7879
}
7980
}),
8081
input.onDidHide(() => {
@@ -95,7 +96,8 @@ async function pickCommand() {
9596
updateQuickPick(currentValue);
9697
});
9798
} else {
98-
console.log('history file does not exist yet')
99+
console.log('history file does not exist yet');
100+
historyShouldBeUpdated = true;
99101
}
100102

101103
});

0 commit comments

Comments
 (0)