Skip to content

Commit a865d84

Browse files
committed
Clippy Lints page - Delay updating of the URL in response to search input
Update on blur, enter keypress, and a debounced delay of 1000 ms. This keeps the URL updated, but not distractingly so.
1 parent 7c1bca4 commit a865d84

File tree

2 files changed

+26
-9
lines changed

2 files changed

+26
-9
lines changed

util/gh-pages/index.html

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -501,9 +501,11 @@ <h1>Clippy Lints</h1>
501501
<div class="col-12 col-md-7 search-control">
502502
<div class="input-group">
503503
<label class="input-group-addon" id="filter-label" for="search-input">Filter:</label>
504-
<input type="text" class="form-control filter-input" placeholder="Keywords or search string" id="search-input" ng-model="search" ng-model-options="{debounce: 50}"/>
504+
<input type="text" class="form-control filter-input" placeholder="Keywords or search string" id="search-input"
505+
ng-model="search" ng-blur="updatePath()" ng-keyup="$event.keyCode == 13 && updatePath()"
506+
ng-model-options="{debounce: 50}" />
505507
<span class="input-group-btn">
506-
<button class="filter-clear btn" type="button" ng-click="search = ''">
508+
<button class="filter-clear btn" type="button" ng-click="search = ''; updatePath();">
507509
Clear
508510
</button>
509511
</span>

util/gh-pages/script.js

Lines changed: 22 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@
106106
}
107107
};
108108
})
109-
.controller("lintList", function ($scope, $http, $location) {
109+
.controller("lintList", function ($scope, $http, $location, $timeout) {
110110
// Level filter
111111
var LEVEL_FILTERS_DEFAULT = {allow: true, warn: true, deny: true, none: true};
112112
$scope.levels = { ...LEVEL_FILTERS_DEFAULT };
@@ -265,12 +265,6 @@
265265
}
266266
}, true);
267267

268-
$scope.$watch('search', function (newVal, oldVal) {
269-
if (newVal !== oldVal) {
270-
$location.path(newVal);
271-
}
272-
});
273-
274268
// Watch for changes in the URL path and update the search and lint display
275269
$scope.$watch(function () {
276270
return $location.path();
@@ -283,12 +277,33 @@
283277
}
284278
});
285279

280+
let debounceTimeout;
281+
$scope.$watch('search', function (newVal, oldVal) {
282+
if (newVal !== oldVal) {
283+
if (debounceTimeout) {
284+
$timeout.cancel(debounceTimeout);
285+
}
286+
287+
debounceTimeout = $timeout(function () {
288+
$location.path(newVal);
289+
}, 1000);
290+
}
291+
});
292+
286293
$scope.$watch(function () {
287294
return $location.search();
288295
}, function (newParameters) {
289296
loadFromURLParameters();
290297
});
291298

299+
$scope.updatePath = function () {
300+
if (debounceTimeout) {
301+
$timeout.cancel(debounceTimeout);
302+
}
303+
304+
$location.path($scope.search);
305+
}
306+
292307
$scope.selectTheme = function (theme) {
293308
setTheme(theme, true);
294309
}

0 commit comments

Comments
 (0)