Skip to content

Commit a788909

Browse files
committed
Manual (non-automatic) completion update
Command completions (e.g. for 'open' commands) were previously automatically updated when command characters are being typed. With this commit the completion is only updated when TAB key is pressed.
1 parent 328e37d commit a788909

File tree

3 files changed

+29
-18
lines changed

3 files changed

+29
-18
lines changed

content_scripts/command.js

Lines changed: 18 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ Command.dataElements = [];
4545
Command.matches = [];
4646
Command.customCommands = {};
4747
Command.lastInputValue = '';
48+
Command.completionsNeedUpdate = false;
4849

4950
Command.setupFrameElements = function() {
5051
this.bar = document.createElement('div');
@@ -180,12 +181,17 @@ Command.completionOrder = {
180181
}
181182
};
182183

184+
Command.markCompletionsForUpdate = function() {
185+
this.completionsNeedUpdate = true;
186+
};
187+
183188
Command.updateCompletions = function(useStyles) {
184189
if (!window.isCommandFrame)
185190
return;
186191
this.completionResults = [];
187192
this.dataElements = [];
188193
this.data.innerHTML = '';
194+
this.completionsNeedUpdate = false;
189195
var key, i;
190196
var completionKeys = Object.keys(this.completions).sort(function(a, b) {
191197
return this.completionOrder.getImportance(b) -
@@ -311,18 +317,18 @@ Command.callCompletionFunction = (function() {
311317
]);
312318
}
313319
}
314-
self.updateCompletions(true);
320+
self.markCompletionsForUpdate();
315321
self.completions.topsites = Search.topSites.filter(function(e) {
316322
return ~(e[0] + ' ' + e[1]).toLowerCase()
317323
.indexOf(search.slice(0).join(' ').toLowerCase());
318324
}).slice(0, 5).map(function(e) {
319325
return [e[0], e[1]];
320326
});
321-
self.updateCompletions(true);
327+
self.markCompletionsForUpdate();
322328
if (search.length) {
323329
Marks.match(search.join(' '), function(response) {
324330
self.completions.bookmarks = response;
325-
self.updateCompletions(true);
331+
self.markCompletionsForUpdate();
326332
}, 2);
327333
}
328334
self.historyMode = false;
@@ -343,7 +349,7 @@ Command.callCompletionFunction = (function() {
343349
Complete.hasOwnProperty(search[0])) {
344350
Complete[search[0]](search.slice(1).join(' '), function(response) {
345351
self.completions = { search: response };
346-
self.updateCompletions();
352+
self.markCompletionsForUpdate();
347353
});
348354
}
349355
};
@@ -357,7 +363,7 @@ Command.callCompletionFunction = (function() {
357363
limit: settings.searchlimit
358364
})
359365
};
360-
self.updateCompletions();
366+
self.markCompletionsForUpdate();
361367
});
362368
};
363369

@@ -373,7 +379,7 @@ Command.callCompletionFunction = (function() {
373379
.indexOf(value.replace(/^\S+\s+/, '').toLowerCase());
374380
})
375381
};
376-
self.updateCompletions();
382+
self.markCompletionsForUpdate();
377383
});
378384
};
379385

@@ -393,7 +399,7 @@ Command.callCompletionFunction = (function() {
393399
return e[0].substring(0, search.length) === search;
394400
})
395401
};
396-
self.updateCompletions();
402+
self.markCompletionsForUpdate();
397403
};
398404

399405
return function(value) {
@@ -410,7 +416,7 @@ Command.callCompletionFunction = (function() {
410416
case 'chrome':
411417
Search.chromeMatch(search, function(matches) {
412418
self.completions = { chrome: matches };
413-
self.updateCompletions();
419+
self.markCompletionsForUpdate();
414420
});
415421
return true;
416422
case 'tabhistory':
@@ -431,7 +437,7 @@ Command.callCompletionFunction = (function() {
431437
})
432438
};
433439
Command.completions.windows.unshift(['0 (New window)', '']);
434-
Command.updateCompletions();
440+
Command.markCompletionsForUpdate();
435441
}
436442
});
437443
self.completions = {};
@@ -450,7 +456,7 @@ Command.callCompletionFunction = (function() {
450456
case 'set':
451457
Search.settingsMatch(search, function(matches) {
452458
self.completions = {settings: matches};
453-
self.updateCompletions();
459+
self.markCompletionsForUpdate();
454460
});
455461
return true;
456462
case 'let': // TODO
@@ -476,7 +482,7 @@ Command.callCompletionFunction = (function() {
476482
}
477483
Marks.match(search, function(response) {
478484
self.completions.bookmarks = response;
479-
self.updateCompletions();
485+
self.markCompletionsForUpdate();
480486
});
481487
return true;
482488
}
@@ -500,7 +506,7 @@ Command.complete = function(value) {
500506
return originalValue === element[0].slice(0, originalValue.length);
501507
})
502508
};
503-
this.updateCompletions();
509+
this.markCompletionsForUpdate();
504510
};
505511

506512
Command.execute = function(value, repeats) {

content_scripts/keys.js

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -387,8 +387,13 @@ var KeyHandler = {
387387
case '<S-Tab>':
388388
if (Command.type === 'action') {
389389
event.preventDefault();
390-
Mappings.actions[ (key === '<Tab>' ? 'next' : 'previous') +
391-
'CompletionResult' ]();
390+
391+
if (Command.completionsNeedUpdate) {
392+
Command.updateCompletions(true);
393+
} else {
394+
Mappings.actions[ (key === '<Tab>' ? 'next' : 'previous') +
395+
'CompletionResult' ]();
396+
}
392397
}
393398
break;
394399
case '<C-p>':

content_scripts/messenger.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -84,13 +84,13 @@ port.onMessage.addListener(function(response) {
8484
if (Command.historyMode) {
8585
if (Command.active && Command.bar.style.display !== 'none') {
8686
Command.completions = { history: matches };
87-
Command.updateCompletions(false);
87+
Command.markCompletionsForUpdate();
8888
}
8989
} else if (Command.searchMode) {
9090
Command.searchMode = false;
9191
if (Command.active && Command.bar.style.display !== 'none') {
9292
Command.completions.history = matches;
93-
Command.updateCompletions(true);
93+
Command.markCompletionsForUpdate();
9494
}
9595
}
9696
break;
@@ -118,7 +118,7 @@ port.onMessage.addListener(function(response) {
118118
return [ response.buffers[+val - 1] ] || [];
119119
})()
120120
};
121-
Command.updateCompletions();
121+
Command.markCompletionsForUpdate();
122122
}
123123
break;
124124
case 'sessions':
@@ -131,7 +131,7 @@ port.onMessage.addListener(function(response) {
131131
if (response.path.length) {
132132
Command.completions = {};
133133
Command.completions.paths = response.path;
134-
Command.updateCompletions();
134+
Command.markCompletionsForUpdate();
135135
} else {
136136
Command.hideData();
137137
}

0 commit comments

Comments
 (0)