Fossil SCM

Add clear-search option to chat search and code-adjacent cleanups.

stephan 2024-07-01 08:54 fts5-chat-search
Commit be01315c86cd2f7d5fab70484ebf6a6d0d7bec2b34ce67fdde92bf2b6571c29b
--- src/fossil.page.chat.js
+++ src/fossil.page.chat.js
@@ -1608,13 +1608,16 @@
16081608
if(!f.spaces){
16091609
f.spaces = /\s+$/;
16101610
f.markdownContinuation = /\\\s+$/;
16111611
f.spaces2 = /\s{3,}$/;
16121612
}
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;
16161619
}
16171620
this.setCurrentView(this.e.viewMessages);
16181621
const fd = new FormData();
16191622
const fallback = {msg: this.inputValue()};
16201623
var msg = fallback.msg;
@@ -1687,14 +1690,16 @@
16871690
//console.debug("Enter key event:", ctrlMode, ev.ctrlKey, ev.shiftKey, ev);
16881691
if(ev.shiftKey){
16891692
const compactMode = Chat.settings.getBool('edit-compact-mode', false);
16901693
ev.preventDefault();
16911694
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
16941697
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)){
16961701
Chat.setCurrentView(Chat.e.viewMessages);
16971702
}else if(!text){
16981703
f.$toggleCompact(compactMode);
16991704
}else if(Chat.settings.getBool('edit-shift-enter-preview', true)){
17001705
Chat.e.btnPreview.click();
@@ -2189,10 +2194,17 @@
21892194
}else{
21902195
Chat.setCurrentView(Chat.e.viewSearch);
21912196
if( msg ) Chat.submitSearch();
21922197
}
21932198
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;
21942206
}, false);
21952207
Chat.e.viewSearch.querySelector('button.action-close').addEventListener('click', function(ev){
21962208
ev.preventDefault();
21972209
ev.stopPropagation();
21982210
Chat.setCurrentView(Chat.e.viewMessages);
@@ -2329,19 +2341,34 @@
23292341
btn.addEventListener('click',()=>loadOldMessages(-1));
23302342
D.append(Chat.e.viewMessages, toolbar);
23312343
toolbar.disabled = true /*will be enabled when msg load finishes */;
23322344
})()/*end history loading widget setup*/;
23332345
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);
23342363
/**
23352364
Submits a history search using the main input field's current
23362365
text. It is assumed that Chat.e.viewSearch===Chat.e.currentView.
23372366
*/
23382367
Chat.submitSearch = function(){
23392368
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);
23432370
if( !term ) return;
23442371
D.append( eMsgTgt, "Searching for ",term," ...");
23452372
F.fetch(
23462373
"chat-query", {
23472374
urlParams: {q: term},
@@ -2368,11 +2395,11 @@
23682395
nextid: 0
23692396
});
23702397
D.append( eMsgTgt, spacer.e.body );
23712398
}else{
23722399
D.append( D.clearElement(eMsgTgt),
2373
- 'No results matching the search term: ',
2400
+ 'No search results found for: ',
23742401
term );
23752402
}
23762403
}
23772404
}
23782405
);
23792406
--- 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
--- src/style.chat.css
+++ src/style.chat.css
@@ -538,13 +538,19 @@
538538
display: flex;
539539
flex-direction: column;
540540
}
541541
body.chat .chat-view .button-bar button {
542542
padding: 0.5em;
543
- flex: 0 1 auto;
543
+ flex: 1 1 auto;
544544
margin: 0.25em 0;
545545
}
546
+
547
+body.chat #chat-search .button-bar {
548
+ flex: 0 1 auto;
549
+ display: flex;
550
+ flex-direction: row;
551
+}
546552
547553
body.chat #chat-user-list-wrapper {
548554
/* Safari can't do fieldsets right, so we emulate one. */
549555
border-radius: 0.5em;
550556
margin: 1em 0 0.2em 0;
551557
--- 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

Keyboard Shortcuts

Open search /
Next entry (timeline) j
Previous entry (timeline) k
Open focused entry Enter
Show this help ?
Toggle theme Top nav button