1 | "use strict";
|
2 |
|
3 |
|
4 |
|
5 |
|
6 |
|
7 |
|
8 |
|
9 |
|
10 |
|
11 |
|
12 |
|
13 |
|
14 |
|
15 |
|
16 |
|
17 | Object.defineProperty(exports, "__esModule", { value: true });
|
18 | exports.SearchBoxDebounce = exports.SearchBoxDebounceOptions = void 0;
|
19 | const event_1 = require("../../common/event");
|
20 | const disposable_1 = require("../../common/disposable");
|
21 | const debounce = require("lodash.debounce");
|
22 | var SearchBoxDebounceOptions;
|
23 | (function (SearchBoxDebounceOptions) {
|
24 | |
25 |
|
26 |
|
27 | SearchBoxDebounceOptions.DEFAULT = {
|
28 | delay: 200
|
29 | };
|
30 | })(SearchBoxDebounceOptions = exports.SearchBoxDebounceOptions || (exports.SearchBoxDebounceOptions = {}));
|
31 |
|
32 |
|
33 |
|
34 | class SearchBoxDebounce {
|
35 | constructor(options) {
|
36 | this.options = options;
|
37 | this.disposables = new disposable_1.DisposableCollection();
|
38 | this.emitter = new event_1.Emitter();
|
39 | this.disposables.push(this.emitter);
|
40 | this.handler = debounce(() => this.fireChanged(this.state), this.options.delay).bind(this);
|
41 | }
|
42 | append(input) {
|
43 | if (input === undefined) {
|
44 | this.reset();
|
45 | return undefined;
|
46 | }
|
47 | if (this.state === undefined) {
|
48 | this.state = input;
|
49 | }
|
50 | else {
|
51 | if (input === '\b') {
|
52 | this.state = this.state.length === 1 ? '' : this.state.substring(0, this.state.length - 1);
|
53 | }
|
54 | else {
|
55 | this.state += input;
|
56 | }
|
57 | }
|
58 | this.handler();
|
59 | return this.state;
|
60 | }
|
61 | get onChanged() {
|
62 | return this.emitter.event;
|
63 | }
|
64 | dispose() {
|
65 | this.disposables.dispose();
|
66 | }
|
67 | fireChanged(value) {
|
68 | this.emitter.fire(value);
|
69 | }
|
70 | reset() {
|
71 | this.state = undefined;
|
72 | this.fireChanged(undefined);
|
73 | }
|
74 | }
|
75 | exports.SearchBoxDebounce = SearchBoxDebounce;
|
76 |
|
\ | No newline at end of file |