Fossil SCM
Add the shift-enter toggle config option to /chat, sharing the same persistent config key as /wikiedit and /fileedit.
Commit
895ecf9e4d17d07992c75277cf8ea758f02a2df026e7a451c3a14972bb649ef5
Parent
8c1c4fa985780a3…
1 file changed
+17
-4
+17
-4
| --- src/fossil.page.chat.js | ||
| +++ src/fossil.page.chat.js | ||
| @@ -1,16 +1,17 @@ | ||
| 1 | 1 | /** |
| 2 | 2 | This file contains the client-side implementation of fossil's /chat |
| 3 | - application. | |
| 3 | + application. | |
| 4 | 4 | */ |
| 5 | 5 | window.fossil.onPageLoad(function(){ |
| 6 | 6 | const F = window.fossil, D = F.dom; |
| 7 | 7 | const E1 = function(selector){ |
| 8 | 8 | const e = document.querySelector(selector); |
| 9 | 9 | if(!e) throw new Error("missing required DOM element: "+selector); |
| 10 | 10 | return e; |
| 11 | 11 | }; |
| 12 | + | |
| 12 | 13 | /** |
| 13 | 14 | Returns true if e is entirely within the bounds of the window's viewport. |
| 14 | 15 | */ |
| 15 | 16 | const isEntirelyInViewport = function(e) { |
| 16 | 17 | const rect = e.getBoundingClientRect(); |
| @@ -396,10 +397,15 @@ | ||
| 396 | 397 | /* When on, the edit field starts as a single line and |
| 397 | 398 | expands as the user types, and the relevant buttons are |
| 398 | 399 | laid out in a compact form. When off, the edit field and |
| 399 | 400 | buttons are larger. */ |
| 400 | 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), | |
| 401 | 407 | /* When on, sets the font-family on messages and the edit |
| 402 | 408 | field to monospace. */ |
| 403 | 409 | "monospace-messages": false, |
| 404 | 410 | /* When on, non-chat UI elements (page header/footer) are |
| 405 | 411 | hidden */ |
| @@ -1499,11 +1505,11 @@ | ||
| 1499 | 1505 | switch back to message view. */ |
| 1500 | 1506 | if(Chat.e.currentView===Chat.e.viewPreview && !text){ |
| 1501 | 1507 | Chat.setCurrentView(Chat.e.viewMessages); |
| 1502 | 1508 | }else if(!text){ |
| 1503 | 1509 | f.$toggleCompact(compactMode); |
| 1504 | - }else{ | |
| 1510 | + }else if(Chat.settings.getBool('edit-shift-enter-preview', true)){ | |
| 1505 | 1511 | Chat.e.btnPreview.click(); |
| 1506 | 1512 | } |
| 1507 | 1513 | return false; |
| 1508 | 1514 | } |
| 1509 | 1515 | if(ev.ctrlKey && !text && !BlobXferState.blob){ |
| @@ -1515,11 +1521,11 @@ | ||
| 1515 | 1521 | } |
| 1516 | 1522 | if(!ctrlMode && ev.ctrlKey && text){ |
| 1517 | 1523 | //console.debug("!ctrlMode && ev.ctrlKey && text."); |
| 1518 | 1524 | /* Ctrl-enter in Enter-sends mode SHOULD, with this logic add a |
| 1519 | 1525 | 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 | |
| 1521 | 1527 | instead of a textarea). Forcibly appending a newline do the |
| 1522 | 1528 | input area does not work, also for unknown reasons, and would |
| 1523 | 1529 | only be suitable when we're at the end of the input. |
| 1524 | 1530 | |
| 1525 | 1531 | Strangely, this approach DOES work for shift-enter, but we |
| @@ -1533,11 +1539,11 @@ | ||
| 1533 | 1539 | ev.preventDefault(); |
| 1534 | 1540 | ev.stopPropagation(); |
| 1535 | 1541 | Chat.submitMessage(); |
| 1536 | 1542 | return false; |
| 1537 | 1543 | } |
| 1538 | - }; | |
| 1544 | + }; | |
| 1539 | 1545 | Chat.e.inputFields.forEach( |
| 1540 | 1546 | (e)=>e.addEventListener('keydown', inputWidgetKeydown, false) |
| 1541 | 1547 | ); |
| 1542 | 1548 | Chat.e.btnSubmit.addEventListener('click',(e)=>{ |
| 1543 | 1549 | e.preventDefault(); |
| @@ -1667,10 +1673,17 @@ | ||
| 1667 | 1673 | "When enabled, chat input uses a so-called 'contenteditable' ", |
| 1668 | 1674 | "field. Though generally more comfortable and modern than ", |
| 1669 | 1675 | "plain-text input fields, browser-specific quirks and bugs ", |
| 1670 | 1676 | "may lead to frustration. Ideal for mobile devices." |
| 1671 | 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' | |
| 1672 | 1685 | }] |
| 1673 | 1686 | },{ |
| 1674 | 1687 | label: "Appearance Options...", |
| 1675 | 1688 | children:[{ |
| 1676 | 1689 | label: "Left-align my posts", |
| 1677 | 1690 |
| --- 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 |