Fossil SCM
Minor restructuring and docs in the enter/ctrl-enter handling. Trying to get ctrl-enter to add newlines when in enter-sends mode, but it's not working for reasons beyond my ken.
Commit
ab9fef759ea3db1e94f0c2c34aecab923ba5fd811d4aba4d6e11989e03a5ea60
Parent
cbc7f117e6292f0…
1 file changed
+41
-28
+41
-28
| --- src/fossil.page.chat.js | ||
| +++ src/fossil.page.chat.js | ||
| @@ -1211,38 +1211,51 @@ | ||
| 1211 | 1211 | f.$toggleCompact = function(currentMode){ |
| 1212 | 1212 | currentMode = !currentMode; |
| 1213 | 1213 | Chat.settings.set('edit-compact-mode', currentMode); |
| 1214 | 1214 | }; |
| 1215 | 1215 | } |
| 1216 | - if(13 === ev.keyCode){ | |
| 1217 | - const ctrlMode = Chat.settings.getBool('edit-ctrl-send', false); | |
| 1218 | - if(ev.shiftKey){ | |
| 1219 | - const compactMode = Chat.settings.getBool('edit-compact-mode', false); | |
| 1220 | - ev.preventDefault(); | |
| 1221 | - ev.stopPropagation(); | |
| 1222 | - /* Shift-enter will run preview mode UNLESS preview mode is | |
| 1223 | - active AND the input field is empty, in which case it will | |
| 1224 | - switch back to message view. */ | |
| 1225 | - const text = Chat.inputValue().trim(); | |
| 1226 | - if(Chat.e.currentView===Chat.e.viewPreview && !text){ | |
| 1227 | - Chat.setCurrentView(Chat.e.viewMessages); | |
| 1228 | - } | |
| 1229 | - else if(!text){ | |
| 1230 | - f.$toggleCompact(compactMode); | |
| 1231 | - } | |
| 1232 | - else Chat.e.btnPreview.click(); | |
| 1233 | - return false; | |
| 1234 | - }else if(!ctrlMode || (ev.ctrlKey && ctrlMode)){ | |
| 1235 | - /* ^^^ note that it is intended that both ctrl-enter and enter | |
| 1236 | - work for compact input mode. */ | |
| 1237 | - ev.preventDefault(); | |
| 1238 | - ev.stopPropagation(); | |
| 1239 | - const text = Chat.inputValue().trim(); | |
| 1240 | - if(!text) f.$toggleCtrl(ctrlMode); | |
| 1241 | - else Chat.submitMessage(); | |
| 1242 | - return false; | |
| 1243 | - } | |
| 1216 | + //console.debug("Enter key event:", ev.keyCode, ev.ctrlKey, ev.shiftKey, ev); | |
| 1217 | + if(13 !== ev.keyCode) return; | |
| 1218 | + const ctrlMode = Chat.settings.getBool('edit-ctrl-send', false); | |
| 1219 | + //console.debug("Enter key event:", ctrlMode, ev.ctrlKey, ev.shiftKey, ev); | |
| 1220 | + const text = Chat.inputValue().trim(); | |
| 1221 | + if(ev.shiftKey){ | |
| 1222 | + const compactMode = Chat.settings.getBool('edit-compact-mode', false); | |
| 1223 | + ev.preventDefault(); | |
| 1224 | + ev.stopPropagation(); | |
| 1225 | + /* Shift-enter will run preview mode UNLESS preview mode is | |
| 1226 | + active AND the input field is empty, in which case it will | |
| 1227 | + switch back to message view. */ | |
| 1228 | + if(Chat.e.currentView===Chat.e.viewPreview && !text){ | |
| 1229 | + Chat.setCurrentView(Chat.e.viewMessages); | |
| 1230 | + }else if(!text){ | |
| 1231 | + f.$toggleCompact(compactMode); | |
| 1232 | + }else{ | |
| 1233 | + Chat.e.btnPreview.click(); | |
| 1234 | + } | |
| 1235 | + return false; | |
| 1236 | + } | |
| 1237 | + if(0 && (!ctrlMode && ev.ctrlKey && text)){ | |
| 1238 | + /* Ctrl-enter in Enter-sends mode SHOULD, with this logic add a | |
| 1239 | + newline, but that is not happening, for reasons i don't | |
| 1240 | + understand. Forcibly appending a newline do the input area | |
| 1241 | + does not work, also for unknown reasons. | |
| 1242 | + */ | |
| 1243 | + return; | |
| 1244 | + } | |
| 1245 | + if(ev.ctrlKey && !text){ | |
| 1246 | + /* Ctrl-enter on an empty field toggles Enter/Ctrl-enter mode */ | |
| 1247 | + ev.preventDefault(); | |
| 1248 | + ev.stopPropagation(); | |
| 1249 | + f.$toggleCtrl(ctrlMode); | |
| 1250 | + return false; | |
| 1251 | + }else if((!ctrlMode && !ev.ctrlKey) || (ev.ctrlKey && ctrlMode)){ | |
| 1252 | + /* Ship it! */ | |
| 1253 | + ev.preventDefault(); | |
| 1254 | + ev.stopPropagation(); | |
| 1255 | + Chat.submitMessage(); | |
| 1256 | + return false; | |
| 1244 | 1257 | } |
| 1245 | 1258 | }; |
| 1246 | 1259 | Chat.e.inputField.addEventListener('keydown', inputWidgetKeydown, false); |
| 1247 | 1260 | Chat.e.btnSubmit.addEventListener('click',(e)=>{ |
| 1248 | 1261 | e.preventDefault(); |
| 1249 | 1262 |
| --- src/fossil.page.chat.js | |
| +++ src/fossil.page.chat.js | |
| @@ -1211,38 +1211,51 @@ | |
| 1211 | f.$toggleCompact = function(currentMode){ |
| 1212 | currentMode = !currentMode; |
| 1213 | Chat.settings.set('edit-compact-mode', currentMode); |
| 1214 | }; |
| 1215 | } |
| 1216 | if(13 === ev.keyCode){ |
| 1217 | const ctrlMode = Chat.settings.getBool('edit-ctrl-send', false); |
| 1218 | if(ev.shiftKey){ |
| 1219 | const compactMode = Chat.settings.getBool('edit-compact-mode', false); |
| 1220 | ev.preventDefault(); |
| 1221 | ev.stopPropagation(); |
| 1222 | /* Shift-enter will run preview mode UNLESS preview mode is |
| 1223 | active AND the input field is empty, in which case it will |
| 1224 | switch back to message view. */ |
| 1225 | const text = Chat.inputValue().trim(); |
| 1226 | if(Chat.e.currentView===Chat.e.viewPreview && !text){ |
| 1227 | Chat.setCurrentView(Chat.e.viewMessages); |
| 1228 | } |
| 1229 | else if(!text){ |
| 1230 | f.$toggleCompact(compactMode); |
| 1231 | } |
| 1232 | else Chat.e.btnPreview.click(); |
| 1233 | return false; |
| 1234 | }else if(!ctrlMode || (ev.ctrlKey && ctrlMode)){ |
| 1235 | /* ^^^ note that it is intended that both ctrl-enter and enter |
| 1236 | work for compact input mode. */ |
| 1237 | ev.preventDefault(); |
| 1238 | ev.stopPropagation(); |
| 1239 | const text = Chat.inputValue().trim(); |
| 1240 | if(!text) f.$toggleCtrl(ctrlMode); |
| 1241 | else Chat.submitMessage(); |
| 1242 | return false; |
| 1243 | } |
| 1244 | } |
| 1245 | }; |
| 1246 | Chat.e.inputField.addEventListener('keydown', inputWidgetKeydown, false); |
| 1247 | Chat.e.btnSubmit.addEventListener('click',(e)=>{ |
| 1248 | e.preventDefault(); |
| 1249 |
| --- src/fossil.page.chat.js | |
| +++ src/fossil.page.chat.js | |
| @@ -1211,38 +1211,51 @@ | |
| 1211 | f.$toggleCompact = function(currentMode){ |
| 1212 | currentMode = !currentMode; |
| 1213 | Chat.settings.set('edit-compact-mode', currentMode); |
| 1214 | }; |
| 1215 | } |
| 1216 | //console.debug("Enter key event:", ev.keyCode, ev.ctrlKey, ev.shiftKey, ev); |
| 1217 | if(13 !== ev.keyCode) return; |
| 1218 | const ctrlMode = Chat.settings.getBool('edit-ctrl-send', false); |
| 1219 | //console.debug("Enter key event:", ctrlMode, ev.ctrlKey, ev.shiftKey, ev); |
| 1220 | const text = Chat.inputValue().trim(); |
| 1221 | if(ev.shiftKey){ |
| 1222 | const compactMode = Chat.settings.getBool('edit-compact-mode', false); |
| 1223 | ev.preventDefault(); |
| 1224 | ev.stopPropagation(); |
| 1225 | /* Shift-enter will run preview mode UNLESS preview mode is |
| 1226 | active AND the input field is empty, in which case it will |
| 1227 | switch back to message view. */ |
| 1228 | if(Chat.e.currentView===Chat.e.viewPreview && !text){ |
| 1229 | Chat.setCurrentView(Chat.e.viewMessages); |
| 1230 | }else if(!text){ |
| 1231 | f.$toggleCompact(compactMode); |
| 1232 | }else{ |
| 1233 | Chat.e.btnPreview.click(); |
| 1234 | } |
| 1235 | return false; |
| 1236 | } |
| 1237 | if(0 && (!ctrlMode && ev.ctrlKey && text)){ |
| 1238 | /* Ctrl-enter in Enter-sends mode SHOULD, with this logic add a |
| 1239 | newline, but that is not happening, for reasons i don't |
| 1240 | understand. Forcibly appending a newline do the input area |
| 1241 | does not work, also for unknown reasons. |
| 1242 | */ |
| 1243 | return; |
| 1244 | } |
| 1245 | if(ev.ctrlKey && !text){ |
| 1246 | /* Ctrl-enter on an empty field toggles Enter/Ctrl-enter mode */ |
| 1247 | ev.preventDefault(); |
| 1248 | ev.stopPropagation(); |
| 1249 | f.$toggleCtrl(ctrlMode); |
| 1250 | return false; |
| 1251 | }else if((!ctrlMode && !ev.ctrlKey) || (ev.ctrlKey && ctrlMode)){ |
| 1252 | /* Ship it! */ |
| 1253 | ev.preventDefault(); |
| 1254 | ev.stopPropagation(); |
| 1255 | Chat.submitMessage(); |
| 1256 | return false; |
| 1257 | } |
| 1258 | }; |
| 1259 | Chat.e.inputField.addEventListener('keydown', inputWidgetKeydown, false); |
| 1260 | Chat.e.btnSubmit.addEventListener('click',(e)=>{ |
| 1261 | e.preventDefault(); |
| 1262 |