diff --git a/index.html b/index.html index 07308b9..4c58ba4 100644 --- a/index.html +++ b/index.html @@ -38,6 +38,7 @@

Snippets

+
diff --git a/src/UIManager.js b/src/UIManager.js index e6a4e6a..7831d9d 100644 --- a/src/UIManager.js +++ b/src/UIManager.js @@ -2,6 +2,7 @@ export class UIManager { constructor(snippetManager) { this.snippetManager = snippetManager; this.setupEventListeners(); + this.setupSearchInput(); } setupEventListeners() { @@ -147,4 +148,25 @@ export class UIManager { 'View Saved' : 'View Draft'; } + + setupSearchInput() { + const searchInput = document.getElementById('snippet-search'); + searchInput.addEventListener('input', (e) => { + const query = e.target.value; + let filteredSnippets; + try { + const regex = new RegExp(query, 'i'); + filteredSnippets = this.snippetManager.snippets.filter(snippet => { + const snippetText = JSON.stringify(snippet); + return regex.test(snippetText); + }); + } catch (err) { + filteredSnippets = this.snippetManager.snippets.filter(snippet => { + const snippetText = JSON.stringify(snippet).toLowerCase(); + return snippetText.includes(query.toLowerCase()); + }); + } + this.renderSnippetList(filteredSnippets, this.snippetManager.currentSnippetId); + }); + } } diff --git a/src/styles.css b/src/styles.css index 5b3aff7..bb83499 100644 --- a/src/styles.css +++ b/src/styles.css @@ -324,4 +324,13 @@ .snippet-item:hover .comment-snippet { opacity: 0.8; +} + +.snippet-search { + width: 100%; + padding: 0.5rem; + margin-bottom: 1rem; + border: 1px solid #e0e0e0; + border-radius: 4px; + font-size: 1rem; } \ No newline at end of file