Skip to content

Commit d122e4d

Browse files
committed
Fix connection form: guard against undefined user/pass + add Edit menu for CMD+A/C/V
- textfieldGetString returns undefined for untouched fields; encodeURIComponent(undefined) produced "undefined" in the URI. Now check encoded result for "undef" before including auth. - Add Edit menu with standard macOS actions (Undo/Redo/Cut/Copy/Paste/Select All) via menuAddStandardAction so keyboard shortcuts work in text fields. - Add Tab navigation between connection form fields via textfieldSetNextKeyView.
1 parent 6ee57d8 commit d122e4d

1 file changed

Lines changed: 28 additions & 9 deletions

File tree

src/app.ts

Lines changed: 28 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import {
1212
scrollviewSetChild,
1313
textfieldSetString, textfieldGetString, textfieldSetNextKeyView,
1414
textareaSetString, textareaGetString,
15-
menuCreate, menuAddItem, menuAddSeparator, menuAddSubmenu,
15+
menuCreate, menuAddItem, menuAddSeparator, menuAddSubmenu, menuAddStandardAction,
1616
menuBarCreate, menuBarAddMenu, menuBarAttach,
1717
Window,
1818
} from 'perry/ui';
@@ -587,7 +587,6 @@ function refreshConnectionList(): void {
587587
connecting = true;
588588
buttonSetTitle(connectBtn, t('Connecting...'));
589589
const uri = connectionUris[connIdx] || `mongodb://${connectionHosts[connIdx]}:${connectionPorts[connIdx]}`;
590-
showStatus('Connecting to: ' + uri, false);
591590
const ok = await connectToMongo(uri);
592591
if (ok) {
593592
widgetSetHidden(statusText, 1);
@@ -712,17 +711,26 @@ function showConnectionForm(): void {
712711

713712
const saveBtn = Button('Save Connection', () => {
714713
try {
715-
const name = textfieldGetString(nameField) || formName || t('Untitled');
716-
const host = textfieldGetString(hostField) || formHost || 'localhost';
717-
const port = textfieldGetString(portField) || formPort || '27017';
718-
const user = textfieldGetString(userField) || formUser;
719-
const pass = textfieldGetString(passField) || formPass;
720-
const rawUri = textfieldGetString(uriField) || formUri;
714+
const nameRaw = textfieldGetString(nameField);
715+
const name = (typeof nameRaw === 'string' && nameRaw.length > 0) ? nameRaw : (formName || t('Untitled'));
716+
const hostRaw = textfieldGetString(hostField);
717+
const host = (typeof hostRaw === 'string' && hostRaw.length > 0) ? hostRaw : (formHost || 'localhost');
718+
const portRaw = textfieldGetString(portField);
719+
const port = (typeof portRaw === 'string' && portRaw.length > 0) ? portRaw : (formPort || '27017');
720+
const user = textfieldGetString(userField) || '';
721+
const pass = textfieldGetString(passField) || '';
722+
const rawUri = textfieldGetString(uriField) || '';
721723

722724
// Build URI from fields if no explicit URI provided
723725
let uri = rawUri;
724726
if (!uri) {
725-
if (user && pass) {
727+
// Only include auth if BOTH user and pass are non-empty real strings
728+
let hasAuth = false;
729+
if (user) {
730+
const uTest = encodeURIComponent(user);
731+
if (uTest.indexOf('undef') < 0 && uTest.length > 0) hasAuth = true;
732+
}
733+
if (hasAuth && pass) {
726734
uri = 'mongodb://' + encodeURIComponent(user) + ':' + encodeURIComponent(pass) + '@' + host + ':' + port;
727735
} else {
728736
uri = 'mongodb://' + host + ':' + port;
@@ -1770,8 +1778,19 @@ if (!mobile) {
17701778
const appMenu = menuCreate();
17711779
menuAddItem(appMenu, 'About Mango', () => { aboutWindow.show(); });
17721780

1781+
// Edit menu — standard actions routed to first responder for CMD+A/C/V/X
1782+
const editMenu = menuCreate();
1783+
menuAddStandardAction(editMenu, 'Undo', 'undo:', 'z');
1784+
menuAddStandardAction(editMenu, 'Redo', 'redo:', 'Cmd+Shift+z');
1785+
menuAddSeparator(editMenu);
1786+
menuAddStandardAction(editMenu, 'Cut', 'cut:', 'x');
1787+
menuAddStandardAction(editMenu, 'Copy', 'copy:', 'c');
1788+
menuAddStandardAction(editMenu, 'Paste', 'paste:', 'v');
1789+
menuAddStandardAction(editMenu, 'Select All', 'selectAll:', 'a');
1790+
17731791
const menuBar = menuBarCreate();
17741792
menuBarAddMenu(menuBar, 'Mango', appMenu);
1793+
menuBarAddMenu(menuBar, 'Edit', editMenu);
17751794
menuBarAttach(menuBar);
17761795
}
17771796

0 commit comments

Comments
 (0)