Fossil SCM
Add clear-search option to chat search and code-adjacent cleanups.
Commit
be01315c86cd2f7d5fab70484ebf6a6d0d7bec2b34ce67fdde92bf2b6571c29b
Parent
39496a32e64e6c0…
2 files changed
+37
-10
+7
-1
+37
-10
| --- src/fossil.page.chat.js | ||
| +++ src/fossil.page.chat.js | ||
| @@ -1608,13 +1608,16 @@ | ||
| 1608 | 1608 | if(!f.spaces){ |
| 1609 | 1609 | f.spaces = /\s+$/; |
| 1610 | 1610 | f.markdownContinuation = /\\\s+$/; |
| 1611 | 1611 | f.spaces2 = /\s{3,}$/; |
| 1612 | 1612 | } |
| 1613 | - if( this.e.currentView===this.e.viewSearch ){ | |
| 1614 | - this.submitSearch(); | |
| 1615 | - return; | |
| 1613 | + switch( this.e.currentView ){ | |
| 1614 | + case this.e.viewSearch: this.submitSearch(); | |
| 1615 | + return; | |
| 1616 | + case this.e.viewPreview: this.e.btnPreview.click(); | |
| 1617 | + return; | |
| 1618 | + default: break; | |
| 1616 | 1619 | } |
| 1617 | 1620 | this.setCurrentView(this.e.viewMessages); |
| 1618 | 1621 | const fd = new FormData(); |
| 1619 | 1622 | const fallback = {msg: this.inputValue()}; |
| 1620 | 1623 | var msg = fallback.msg; |
| @@ -1687,14 +1690,16 @@ | ||
| 1687 | 1690 | //console.debug("Enter key event:", ctrlMode, ev.ctrlKey, ev.shiftKey, ev); |
| 1688 | 1691 | if(ev.shiftKey){ |
| 1689 | 1692 | const compactMode = Chat.settings.getBool('edit-compact-mode', false); |
| 1690 | 1693 | ev.preventDefault(); |
| 1691 | 1694 | ev.stopPropagation(); |
| 1692 | - /* Shift-enter will run preview mode UNLESS preview mode is | |
| 1693 | - active AND the input field is empty, in which case it will | |
| 1695 | + /* Shift-enter will run preview mode UNLESS the input field is empty | |
| 1696 | + AND (preview or search mode) is active, in which cases it will | |
| 1694 | 1697 | switch back to message view. */ |
| 1695 | - if(Chat.e.currentView===Chat.e.viewPreview && !text){ | |
| 1698 | + if(!text && | |
| 1699 | + (Chat.e.currentView===Chat.e.viewPreview | |
| 1700 | + | Chat.e.currentView===Chat.e.viewSearch)){ | |
| 1696 | 1701 | Chat.setCurrentView(Chat.e.viewMessages); |
| 1697 | 1702 | }else if(!text){ |
| 1698 | 1703 | f.$toggleCompact(compactMode); |
| 1699 | 1704 | }else if(Chat.settings.getBool('edit-shift-enter-preview', true)){ |
| 1700 | 1705 | Chat.e.btnPreview.click(); |
| @@ -2189,10 +2194,17 @@ | ||
| 2189 | 2194 | }else{ |
| 2190 | 2195 | Chat.setCurrentView(Chat.e.viewSearch); |
| 2191 | 2196 | if( msg ) Chat.submitSearch(); |
| 2192 | 2197 | } |
| 2193 | 2198 | return false; |
| 2199 | + }, false); | |
| 2200 | + Chat.e.viewSearch.querySelector('button.action-clear').addEventListener('click', function(ev){ | |
| 2201 | + ev.preventDefault(); | |
| 2202 | + ev.stopPropagation(); | |
| 2203 | + Chat.clearSearch(true); | |
| 2204 | + Chat.setCurrentView(Chat.e.viewMessages); | |
| 2205 | + return false; | |
| 2194 | 2206 | }, false); |
| 2195 | 2207 | Chat.e.viewSearch.querySelector('button.action-close').addEventListener('click', function(ev){ |
| 2196 | 2208 | ev.preventDefault(); |
| 2197 | 2209 | ev.stopPropagation(); |
| 2198 | 2210 | Chat.setCurrentView(Chat.e.viewMessages); |
| @@ -2329,19 +2341,34 @@ | ||
| 2329 | 2341 | btn.addEventListener('click',()=>loadOldMessages(-1)); |
| 2330 | 2342 | D.append(Chat.e.viewMessages, toolbar); |
| 2331 | 2343 | toolbar.disabled = true /*will be enabled when msg load finishes */; |
| 2332 | 2344 | })()/*end history loading widget setup*/; |
| 2333 | 2345 | |
| 2346 | + /** | |
| 2347 | + Clears the search result view. If addInstructions is true it adds | |
| 2348 | + text to that view instructing the user to enter their query into | |
| 2349 | + the message-entry widget (noting that that widget has text | |
| 2350 | + implying that it's only for submitting a message, which isn't | |
| 2351 | + exactly true when the search view is active). | |
| 2352 | + */ | |
| 2353 | + Chat.clearSearch = function(addInstructions=false){ | |
| 2354 | + const e = D.clearElement( | |
| 2355 | + this.e.viewSearch.querySelector('.message-widget-content') | |
| 2356 | + ); | |
| 2357 | + if(addInstructions){ | |
| 2358 | + D.append(e, "Enter search terms in the message field."); | |
| 2359 | + } | |
| 2360 | + return e; | |
| 2361 | + }; | |
| 2362 | + Chat.clearSearch(true); | |
| 2334 | 2363 | /** |
| 2335 | 2364 | Submits a history search using the main input field's current |
| 2336 | 2365 | text. It is assumed that Chat.e.viewSearch===Chat.e.currentView. |
| 2337 | 2366 | */ |
| 2338 | 2367 | Chat.submitSearch = function(){ |
| 2339 | 2368 | const term = this.inputValue(true); |
| 2340 | - const eMsgTgt = D.clearElement( | |
| 2341 | - this.e.viewSearch.querySelector('.message-widget-content') | |
| 2342 | - ) | |
| 2369 | + const eMsgTgt = this.clearSearch(true); | |
| 2343 | 2370 | if( !term ) return; |
| 2344 | 2371 | D.append( eMsgTgt, "Searching for ",term," ..."); |
| 2345 | 2372 | F.fetch( |
| 2346 | 2373 | "chat-query", { |
| 2347 | 2374 | urlParams: {q: term}, |
| @@ -2368,11 +2395,11 @@ | ||
| 2368 | 2395 | nextid: 0 |
| 2369 | 2396 | }); |
| 2370 | 2397 | D.append( eMsgTgt, spacer.e.body ); |
| 2371 | 2398 | }else{ |
| 2372 | 2399 | D.append( D.clearElement(eMsgTgt), |
| 2373 | - 'No results matching the search term: ', | |
| 2400 | + 'No search results found for: ', | |
| 2374 | 2401 | term ); |
| 2375 | 2402 | } |
| 2376 | 2403 | } |
| 2377 | 2404 | } |
| 2378 | 2405 | ); |
| 2379 | 2406 |
| --- src/fossil.page.chat.js | |
| +++ src/fossil.page.chat.js | |
| @@ -1608,13 +1608,16 @@ | |
| 1608 | if(!f.spaces){ |
| 1609 | f.spaces = /\s+$/; |
| 1610 | f.markdownContinuation = /\\\s+$/; |
| 1611 | f.spaces2 = /\s{3,}$/; |
| 1612 | } |
| 1613 | if( this.e.currentView===this.e.viewSearch ){ |
| 1614 | this.submitSearch(); |
| 1615 | return; |
| 1616 | } |
| 1617 | this.setCurrentView(this.e.viewMessages); |
| 1618 | const fd = new FormData(); |
| 1619 | const fallback = {msg: this.inputValue()}; |
| 1620 | var msg = fallback.msg; |
| @@ -1687,14 +1690,16 @@ | |
| 1687 | //console.debug("Enter key event:", ctrlMode, ev.ctrlKey, ev.shiftKey, ev); |
| 1688 | if(ev.shiftKey){ |
| 1689 | const compactMode = Chat.settings.getBool('edit-compact-mode', false); |
| 1690 | ev.preventDefault(); |
| 1691 | ev.stopPropagation(); |
| 1692 | /* Shift-enter will run preview mode UNLESS preview mode is |
| 1693 | active AND the input field is empty, in which case it will |
| 1694 | switch back to message view. */ |
| 1695 | if(Chat.e.currentView===Chat.e.viewPreview && !text){ |
| 1696 | Chat.setCurrentView(Chat.e.viewMessages); |
| 1697 | }else if(!text){ |
| 1698 | f.$toggleCompact(compactMode); |
| 1699 | }else if(Chat.settings.getBool('edit-shift-enter-preview', true)){ |
| 1700 | Chat.e.btnPreview.click(); |
| @@ -2189,10 +2194,17 @@ | |
| 2189 | }else{ |
| 2190 | Chat.setCurrentView(Chat.e.viewSearch); |
| 2191 | if( msg ) Chat.submitSearch(); |
| 2192 | } |
| 2193 | return false; |
| 2194 | }, false); |
| 2195 | Chat.e.viewSearch.querySelector('button.action-close').addEventListener('click', function(ev){ |
| 2196 | ev.preventDefault(); |
| 2197 | ev.stopPropagation(); |
| 2198 | Chat.setCurrentView(Chat.e.viewMessages); |
| @@ -2329,19 +2341,34 @@ | |
| 2329 | btn.addEventListener('click',()=>loadOldMessages(-1)); |
| 2330 | D.append(Chat.e.viewMessages, toolbar); |
| 2331 | toolbar.disabled = true /*will be enabled when msg load finishes */; |
| 2332 | })()/*end history loading widget setup*/; |
| 2333 | |
| 2334 | /** |
| 2335 | Submits a history search using the main input field's current |
| 2336 | text. It is assumed that Chat.e.viewSearch===Chat.e.currentView. |
| 2337 | */ |
| 2338 | Chat.submitSearch = function(){ |
| 2339 | const term = this.inputValue(true); |
| 2340 | const eMsgTgt = D.clearElement( |
| 2341 | this.e.viewSearch.querySelector('.message-widget-content') |
| 2342 | ) |
| 2343 | if( !term ) return; |
| 2344 | D.append( eMsgTgt, "Searching for ",term," ..."); |
| 2345 | F.fetch( |
| 2346 | "chat-query", { |
| 2347 | urlParams: {q: term}, |
| @@ -2368,11 +2395,11 @@ | |
| 2368 | nextid: 0 |
| 2369 | }); |
| 2370 | D.append( eMsgTgt, spacer.e.body ); |
| 2371 | }else{ |
| 2372 | D.append( D.clearElement(eMsgTgt), |
| 2373 | 'No results matching the search term: ', |
| 2374 | term ); |
| 2375 | } |
| 2376 | } |
| 2377 | } |
| 2378 | ); |
| 2379 |
| --- src/fossil.page.chat.js | |
| +++ src/fossil.page.chat.js | |
| @@ -1608,13 +1608,16 @@ | |
| 1608 | if(!f.spaces){ |
| 1609 | f.spaces = /\s+$/; |
| 1610 | f.markdownContinuation = /\\\s+$/; |
| 1611 | f.spaces2 = /\s{3,}$/; |
| 1612 | } |
| 1613 | switch( this.e.currentView ){ |
| 1614 | case this.e.viewSearch: this.submitSearch(); |
| 1615 | return; |
| 1616 | case this.e.viewPreview: this.e.btnPreview.click(); |
| 1617 | return; |
| 1618 | default: break; |
| 1619 | } |
| 1620 | this.setCurrentView(this.e.viewMessages); |
| 1621 | const fd = new FormData(); |
| 1622 | const fallback = {msg: this.inputValue()}; |
| 1623 | var msg = fallback.msg; |
| @@ -1687,14 +1690,16 @@ | |
| 1690 | //console.debug("Enter key event:", ctrlMode, ev.ctrlKey, ev.shiftKey, ev); |
| 1691 | if(ev.shiftKey){ |
| 1692 | const compactMode = Chat.settings.getBool('edit-compact-mode', false); |
| 1693 | ev.preventDefault(); |
| 1694 | ev.stopPropagation(); |
| 1695 | /* Shift-enter will run preview mode UNLESS the input field is empty |
| 1696 | AND (preview or search mode) is active, in which cases it will |
| 1697 | switch back to message view. */ |
| 1698 | if(!text && |
| 1699 | (Chat.e.currentView===Chat.e.viewPreview |
| 1700 | | Chat.e.currentView===Chat.e.viewSearch)){ |
| 1701 | Chat.setCurrentView(Chat.e.viewMessages); |
| 1702 | }else if(!text){ |
| 1703 | f.$toggleCompact(compactMode); |
| 1704 | }else if(Chat.settings.getBool('edit-shift-enter-preview', true)){ |
| 1705 | Chat.e.btnPreview.click(); |
| @@ -2189,10 +2194,17 @@ | |
| 2194 | }else{ |
| 2195 | Chat.setCurrentView(Chat.e.viewSearch); |
| 2196 | if( msg ) Chat.submitSearch(); |
| 2197 | } |
| 2198 | return false; |
| 2199 | }, false); |
| 2200 | Chat.e.viewSearch.querySelector('button.action-clear').addEventListener('click', function(ev){ |
| 2201 | ev.preventDefault(); |
| 2202 | ev.stopPropagation(); |
| 2203 | Chat.clearSearch(true); |
| 2204 | Chat.setCurrentView(Chat.e.viewMessages); |
| 2205 | return false; |
| 2206 | }, false); |
| 2207 | Chat.e.viewSearch.querySelector('button.action-close').addEventListener('click', function(ev){ |
| 2208 | ev.preventDefault(); |
| 2209 | ev.stopPropagation(); |
| 2210 | Chat.setCurrentView(Chat.e.viewMessages); |
| @@ -2329,19 +2341,34 @@ | |
| 2341 | btn.addEventListener('click',()=>loadOldMessages(-1)); |
| 2342 | D.append(Chat.e.viewMessages, toolbar); |
| 2343 | toolbar.disabled = true /*will be enabled when msg load finishes */; |
| 2344 | })()/*end history loading widget setup*/; |
| 2345 | |
| 2346 | /** |
| 2347 | Clears the search result view. If addInstructions is true it adds |
| 2348 | text to that view instructing the user to enter their query into |
| 2349 | the message-entry widget (noting that that widget has text |
| 2350 | implying that it's only for submitting a message, which isn't |
| 2351 | exactly true when the search view is active). |
| 2352 | */ |
| 2353 | Chat.clearSearch = function(addInstructions=false){ |
| 2354 | const e = D.clearElement( |
| 2355 | this.e.viewSearch.querySelector('.message-widget-content') |
| 2356 | ); |
| 2357 | if(addInstructions){ |
| 2358 | D.append(e, "Enter search terms in the message field."); |
| 2359 | } |
| 2360 | return e; |
| 2361 | }; |
| 2362 | Chat.clearSearch(true); |
| 2363 | /** |
| 2364 | Submits a history search using the main input field's current |
| 2365 | text. It is assumed that Chat.e.viewSearch===Chat.e.currentView. |
| 2366 | */ |
| 2367 | Chat.submitSearch = function(){ |
| 2368 | const term = this.inputValue(true); |
| 2369 | const eMsgTgt = this.clearSearch(true); |
| 2370 | if( !term ) return; |
| 2371 | D.append( eMsgTgt, "Searching for ",term," ..."); |
| 2372 | F.fetch( |
| 2373 | "chat-query", { |
| 2374 | urlParams: {q: term}, |
| @@ -2368,11 +2395,11 @@ | |
| 2395 | nextid: 0 |
| 2396 | }); |
| 2397 | D.append( eMsgTgt, spacer.e.body ); |
| 2398 | }else{ |
| 2399 | D.append( D.clearElement(eMsgTgt), |
| 2400 | 'No search results found for: ', |
| 2401 | term ); |
| 2402 | } |
| 2403 | } |
| 2404 | } |
| 2405 | ); |
| 2406 |
+7
-1
| --- src/style.chat.css | ||
| +++ src/style.chat.css | ||
| @@ -538,13 +538,19 @@ | ||
| 538 | 538 | display: flex; |
| 539 | 539 | flex-direction: column; |
| 540 | 540 | } |
| 541 | 541 | body.chat .chat-view .button-bar button { |
| 542 | 542 | padding: 0.5em; |
| 543 | - flex: 0 1 auto; | |
| 543 | + flex: 1 1 auto; | |
| 544 | 544 | margin: 0.25em 0; |
| 545 | 545 | } |
| 546 | + | |
| 547 | +body.chat #chat-search .button-bar { | |
| 548 | + flex: 0 1 auto; | |
| 549 | + display: flex; | |
| 550 | + flex-direction: row; | |
| 551 | +} | |
| 546 | 552 | |
| 547 | 553 | body.chat #chat-user-list-wrapper { |
| 548 | 554 | /* Safari can't do fieldsets right, so we emulate one. */ |
| 549 | 555 | border-radius: 0.5em; |
| 550 | 556 | margin: 1em 0 0.2em 0; |
| 551 | 557 |
| --- src/style.chat.css | |
| +++ src/style.chat.css | |
| @@ -538,13 +538,19 @@ | |
| 538 | display: flex; |
| 539 | flex-direction: column; |
| 540 | } |
| 541 | body.chat .chat-view .button-bar button { |
| 542 | padding: 0.5em; |
| 543 | flex: 0 1 auto; |
| 544 | margin: 0.25em 0; |
| 545 | } |
| 546 | |
| 547 | body.chat #chat-user-list-wrapper { |
| 548 | /* Safari can't do fieldsets right, so we emulate one. */ |
| 549 | border-radius: 0.5em; |
| 550 | margin: 1em 0 0.2em 0; |
| 551 |
| --- src/style.chat.css | |
| +++ src/style.chat.css | |
| @@ -538,13 +538,19 @@ | |
| 538 | display: flex; |
| 539 | flex-direction: column; |
| 540 | } |
| 541 | body.chat .chat-view .button-bar button { |
| 542 | padding: 0.5em; |
| 543 | flex: 1 1 auto; |
| 544 | margin: 0.25em 0; |
| 545 | } |
| 546 | |
| 547 | body.chat #chat-search .button-bar { |
| 548 | flex: 0 1 auto; |
| 549 | display: flex; |
| 550 | flex-direction: row; |
| 551 | } |
| 552 | |
| 553 | body.chat #chat-user-list-wrapper { |
| 554 | /* Safari can't do fieldsets right, so we emulate one. */ |
| 555 | border-radius: 0.5em; |
| 556 | margin: 1em 0 0.2em 0; |
| 557 |