experiments in a post-browser web
10
fork

Configure Feed

Select the types of activity you want to include in your feed.

support opening urls directly in the cmd bar

+60 -3
+60 -3
app/cmd/panel.js
··· 130 130 131 131 // Enter key - execute command 132 132 if (e.key === 'Enter' && !hasModifier(e)) { 133 + // Check if the typed text is a URL - if so, use the "open" command 134 + const trimmedText = commandInput.value.trim(); 135 + const urlResult = getValidURL(trimmedText); 136 + if (urlResult.valid && state.commands['open']) { 137 + debug && console.log('Detected URL, using open command:', urlResult.url); 138 + state.lastExecuted = 'open'; 139 + updateMatchCount('open'); 140 + updateAdaptiveFeedback(trimmedText.split(' ')[0], 'open'); 141 + 142 + // Execute open command with the URL 143 + execute('open', 'open ' + trimmedText); 144 + 145 + // Clear input and UI 146 + commandInput.value = ''; 147 + state.typed = ''; 148 + updateCommandUI(); 149 + updateResultsUI(); 150 + return; 151 + } 152 + 153 + // Otherwise, execute the matched command 133 154 const name = state.matches[state.matchIndex]; 134 155 if (name && Object.keys(state.commands).indexOf(name) > -1) { 135 156 // Preserve any parameters when executing 136 157 const typedText = commandInput.value; 137 - 158 + 138 159 // Store command name for history and adaptive feedback 139 160 const commandPart = typedText.split(' ')[0]; 140 161 state.lastExecuted = name; 141 162 updateMatchCount(name); 142 163 updateAdaptiveFeedback(commandPart, name); 143 - 164 + 144 165 // Execute with full typed text 145 166 execute(name, typedText); 146 - 167 + 147 168 // Clear input and UI 148 169 commandInput.value = ''; 149 170 state.typed = ''; ··· 496 517 function isModifier(e) { 497 518 return ['Alt', 'Control', 'Shift', 'Meta'].indexOf(e.key) !== -1; 498 519 } 520 + 521 + /** 522 + * Checks if a string is a valid URL (with or without protocol) 523 + * @param {string} str - The string to check 524 + * @returns {Object} - Object with valid flag and normalized URL 525 + */ 526 + function getValidURL(str) { 527 + if (!str) return { valid: false }; 528 + 529 + // Check if it starts with a valid protocol 530 + const hasValidProtocol = /^(https?|ftp|file):\/\//.test(str); 531 + 532 + if (!hasValidProtocol) { 533 + // Check if it looks like a domain (e.g., "example.com" or "localhost") 534 + const isDomainPattern = /^([a-zA-Z0-9]([a-zA-Z0-9\-]{0,61}[a-zA-Z0-9])?\.)+[a-zA-Z]{2,}(\/.*)?$/.test(str); 535 + const isLocalhost = /^localhost(:\d+)?(\/.*)?$/.test(str); 536 + 537 + if (isDomainPattern || isLocalhost) { 538 + const urlWithProtocol = 'https://' + str; 539 + try { 540 + new URL(urlWithProtocol); 541 + return { valid: true, url: urlWithProtocol }; 542 + } catch (e) { 543 + return { valid: false }; 544 + } 545 + } 546 + return { valid: false }; 547 + } 548 + 549 + try { 550 + new URL(str); 551 + return { valid: true, url: str }; 552 + } catch (e) { 553 + return { valid: false }; 554 + } 555 + }