Fossil SCM

Add the shift-enter toggle config option to /chat, sharing the same persistent config key as /wikiedit and /fileedit.

stephan 2023-12-16 01:39 shift-enter-preview
Commit 895ecf9e4d17d07992c75277cf8ea758f02a2df026e7a451c3a14972bb649ef5
1 file changed +17 -4
--- src/fossil.page.chat.js
+++ src/fossil.page.chat.js
@@ -1,16 +1,17 @@
11
/**
22
This file contains the client-side implementation of fossil's /chat
3
- application.
3
+ application.
44
*/
55
window.fossil.onPageLoad(function(){
66
const F = window.fossil, D = F.dom;
77
const E1 = function(selector){
88
const e = document.querySelector(selector);
99
if(!e) throw new Error("missing required DOM element: "+selector);
1010
return e;
1111
};
12
+
1213
/**
1314
Returns true if e is entirely within the bounds of the window's viewport.
1415
*/
1516
const isEntirelyInViewport = function(e) {
1617
const rect = e.getBoundingClientRect();
@@ -396,10 +397,15 @@
396397
/* When on, the edit field starts as a single line and
397398
expands as the user types, and the relevant buttons are
398399
laid out in a compact form. When off, the edit field and
399400
buttons are larger. */
400401
"edit-compact-mode": true,
402
+ /* See notes for this setting in fossil.page.wikiedit.js.
403
+ Both /wikiedit and /fileedit share this persistent config
404
+ option under the same storage key. */
405
+ "edit-shift-enter-preview":
406
+ F.storage.getBool('edit-shift-enter-preview', true),
401407
/* When on, sets the font-family on messages and the edit
402408
field to monospace. */
403409
"monospace-messages": false,
404410
/* When on, non-chat UI elements (page header/footer) are
405411
hidden */
@@ -1499,11 +1505,11 @@
14991505
switch back to message view. */
15001506
if(Chat.e.currentView===Chat.e.viewPreview && !text){
15011507
Chat.setCurrentView(Chat.e.viewMessages);
15021508
}else if(!text){
15031509
f.$toggleCompact(compactMode);
1504
- }else{
1510
+ }else if(Chat.settings.getBool('edit-shift-enter-preview', true)){
15051511
Chat.e.btnPreview.click();
15061512
}
15071513
return false;
15081514
}
15091515
if(ev.ctrlKey && !text && !BlobXferState.blob){
@@ -1515,11 +1521,11 @@
15151521
}
15161522
if(!ctrlMode && ev.ctrlKey && text){
15171523
//console.debug("!ctrlMode && ev.ctrlKey && text.");
15181524
/* Ctrl-enter in Enter-sends mode SHOULD, with this logic add a
15191525
newline, but that is not happening, for unknown reasons
1520
- (possibly related to this element being a conteneditable DIV
1526
+ (possibly related to this element being a contenteditable DIV
15211527
instead of a textarea). Forcibly appending a newline do the
15221528
input area does not work, also for unknown reasons, and would
15231529
only be suitable when we're at the end of the input.
15241530
15251531
Strangely, this approach DOES work for shift-enter, but we
@@ -1533,11 +1539,11 @@
15331539
ev.preventDefault();
15341540
ev.stopPropagation();
15351541
Chat.submitMessage();
15361542
return false;
15371543
}
1538
- };
1544
+ };
15391545
Chat.e.inputFields.forEach(
15401546
(e)=>e.addEventListener('keydown', inputWidgetKeydown, false)
15411547
);
15421548
Chat.e.btnSubmit.addEventListener('click',(e)=>{
15431549
e.preventDefault();
@@ -1667,10 +1673,17 @@
16671673
"When enabled, chat input uses a so-called 'contenteditable' ",
16681674
"field. Though generally more comfortable and modern than ",
16691675
"plain-text input fields, browser-specific quirks and bugs ",
16701676
"may lead to frustration. Ideal for mobile devices."
16711677
].join('')
1678
+ },{
1679
+ label: "Shift-enter to preview",
1680
+ hint: ["Use shift-enter to preview being-edited messages. ",
1681
+ "This is normally desirable but some software-mode ",
1682
+ "keyboards misinteract with this, in which cases it can be ",
1683
+ "disabled."],
1684
+ boolValue: 'edit-shift-enter-preview'
16721685
}]
16731686
},{
16741687
label: "Appearance Options...",
16751688
children:[{
16761689
label: "Left-align my posts",
16771690
--- src/fossil.page.chat.js
+++ src/fossil.page.chat.js
@@ -1,16 +1,17 @@
1 /**
2 This file contains the client-side implementation of fossil's /chat
3 application.
4 */
5 window.fossil.onPageLoad(function(){
6 const F = window.fossil, D = F.dom;
7 const E1 = function(selector){
8 const e = document.querySelector(selector);
9 if(!e) throw new Error("missing required DOM element: "+selector);
10 return e;
11 };
 
12 /**
13 Returns true if e is entirely within the bounds of the window's viewport.
14 */
15 const isEntirelyInViewport = function(e) {
16 const rect = e.getBoundingClientRect();
@@ -396,10 +397,15 @@
396 /* When on, the edit field starts as a single line and
397 expands as the user types, and the relevant buttons are
398 laid out in a compact form. When off, the edit field and
399 buttons are larger. */
400 "edit-compact-mode": true,
 
 
 
 
 
401 /* When on, sets the font-family on messages and the edit
402 field to monospace. */
403 "monospace-messages": false,
404 /* When on, non-chat UI elements (page header/footer) are
405 hidden */
@@ -1499,11 +1505,11 @@
1499 switch back to message view. */
1500 if(Chat.e.currentView===Chat.e.viewPreview && !text){
1501 Chat.setCurrentView(Chat.e.viewMessages);
1502 }else if(!text){
1503 f.$toggleCompact(compactMode);
1504 }else{
1505 Chat.e.btnPreview.click();
1506 }
1507 return false;
1508 }
1509 if(ev.ctrlKey && !text && !BlobXferState.blob){
@@ -1515,11 +1521,11 @@
1515 }
1516 if(!ctrlMode && ev.ctrlKey && text){
1517 //console.debug("!ctrlMode && ev.ctrlKey && text.");
1518 /* Ctrl-enter in Enter-sends mode SHOULD, with this logic add a
1519 newline, but that is not happening, for unknown reasons
1520 (possibly related to this element being a conteneditable DIV
1521 instead of a textarea). Forcibly appending a newline do the
1522 input area does not work, also for unknown reasons, and would
1523 only be suitable when we're at the end of the input.
1524
1525 Strangely, this approach DOES work for shift-enter, but we
@@ -1533,11 +1539,11 @@
1533 ev.preventDefault();
1534 ev.stopPropagation();
1535 Chat.submitMessage();
1536 return false;
1537 }
1538 };
1539 Chat.e.inputFields.forEach(
1540 (e)=>e.addEventListener('keydown', inputWidgetKeydown, false)
1541 );
1542 Chat.e.btnSubmit.addEventListener('click',(e)=>{
1543 e.preventDefault();
@@ -1667,10 +1673,17 @@
1667 "When enabled, chat input uses a so-called 'contenteditable' ",
1668 "field. Though generally more comfortable and modern than ",
1669 "plain-text input fields, browser-specific quirks and bugs ",
1670 "may lead to frustration. Ideal for mobile devices."
1671 ].join('')
 
 
 
 
 
 
 
1672 }]
1673 },{
1674 label: "Appearance Options...",
1675 children:[{
1676 label: "Left-align my posts",
1677
--- src/fossil.page.chat.js
+++ src/fossil.page.chat.js
@@ -1,16 +1,17 @@
1 /**
2 This file contains the client-side implementation of fossil's /chat
3 application.
4 */
5 window.fossil.onPageLoad(function(){
6 const F = window.fossil, D = F.dom;
7 const E1 = function(selector){
8 const e = document.querySelector(selector);
9 if(!e) throw new Error("missing required DOM element: "+selector);
10 return e;
11 };
12
13 /**
14 Returns true if e is entirely within the bounds of the window's viewport.
15 */
16 const isEntirelyInViewport = function(e) {
17 const rect = e.getBoundingClientRect();
@@ -396,10 +397,15 @@
397 /* When on, the edit field starts as a single line and
398 expands as the user types, and the relevant buttons are
399 laid out in a compact form. When off, the edit field and
400 buttons are larger. */
401 "edit-compact-mode": true,
402 /* See notes for this setting in fossil.page.wikiedit.js.
403 Both /wikiedit and /fileedit share this persistent config
404 option under the same storage key. */
405 "edit-shift-enter-preview":
406 F.storage.getBool('edit-shift-enter-preview', true),
407 /* When on, sets the font-family on messages and the edit
408 field to monospace. */
409 "monospace-messages": false,
410 /* When on, non-chat UI elements (page header/footer) are
411 hidden */
@@ -1499,11 +1505,11 @@
1505 switch back to message view. */
1506 if(Chat.e.currentView===Chat.e.viewPreview && !text){
1507 Chat.setCurrentView(Chat.e.viewMessages);
1508 }else if(!text){
1509 f.$toggleCompact(compactMode);
1510 }else if(Chat.settings.getBool('edit-shift-enter-preview', true)){
1511 Chat.e.btnPreview.click();
1512 }
1513 return false;
1514 }
1515 if(ev.ctrlKey && !text && !BlobXferState.blob){
@@ -1515,11 +1521,11 @@
1521 }
1522 if(!ctrlMode && ev.ctrlKey && text){
1523 //console.debug("!ctrlMode && ev.ctrlKey && text.");
1524 /* Ctrl-enter in Enter-sends mode SHOULD, with this logic add a
1525 newline, but that is not happening, for unknown reasons
1526 (possibly related to this element being a contenteditable DIV
1527 instead of a textarea). Forcibly appending a newline do the
1528 input area does not work, also for unknown reasons, and would
1529 only be suitable when we're at the end of the input.
1530
1531 Strangely, this approach DOES work for shift-enter, but we
@@ -1533,11 +1539,11 @@
1539 ev.preventDefault();
1540 ev.stopPropagation();
1541 Chat.submitMessage();
1542 return false;
1543 }
1544 };
1545 Chat.e.inputFields.forEach(
1546 (e)=>e.addEventListener('keydown', inputWidgetKeydown, false)
1547 );
1548 Chat.e.btnSubmit.addEventListener('click',(e)=>{
1549 e.preventDefault();
@@ -1667,10 +1673,17 @@
1673 "When enabled, chat input uses a so-called 'contenteditable' ",
1674 "field. Though generally more comfortable and modern than ",
1675 "plain-text input fields, browser-specific quirks and bugs ",
1676 "may lead to frustration. Ideal for mobile devices."
1677 ].join('')
1678 },{
1679 label: "Shift-enter to preview",
1680 hint: ["Use shift-enter to preview being-edited messages. ",
1681 "This is normally desirable but some software-mode ",
1682 "keyboards misinteract with this, in which cases it can be ",
1683 "disabled."],
1684 boolValue: 'edit-shift-enter-preview'
1685 }]
1686 },{
1687 label: "Appearance Options...",
1688 children:[{
1689 label: "Left-align my posts",
1690

Keyboard Shortcuts

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