Skip to content

Commit f8311d0

Browse files
authored
feat: add editor and UI zoom commands (#2058)
1 parent 773d572 commit f8311d0

39 files changed

Lines changed: 240 additions & 74 deletions

src/cm/commandRegistry.js

Lines changed: 33 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -503,17 +503,31 @@ function registerCoreCommands() {
503503
return true;
504504
},
505505
});
506+
addCommand({
507+
name: "increaseUiZoom",
508+
description: "Increase UI zoom",
509+
readOnly: true,
510+
requiresView: false,
511+
run: () => adjustUiZoom(10),
512+
});
513+
addCommand({
514+
name: "decreaseUiZoom",
515+
description: "Decrease UI zoom",
516+
readOnly: true,
517+
requiresView: false,
518+
run: () => adjustUiZoom(-10),
519+
});
506520
addCommand({
507521
name: "increaseFontSize",
508-
description: "Increase font size",
509-
readOnly: false,
522+
description: "Increase editor font size",
523+
readOnly: true,
510524
requiresView: false,
511525
run: () => adjustFontSize(1),
512526
});
513527
addCommand({
514528
name: "decreaseFontSize",
515-
description: "Decrease font size",
516-
readOnly: false,
529+
description: "Decrease editor font size",
530+
readOnly: true,
517531
requiresView: false,
518532
run: () => adjustFontSize(-1),
519533
});
@@ -1307,12 +1321,20 @@ async function openInAppBrowserCommand() {
13071321
function adjustFontSize(delta) {
13081322
const current = settings?.value?.fontSize || "12px";
13091323
const numeric = Number.parseInt(current, 10) || 12;
1310-
const next = Math.max(1, numeric + delta);
1324+
const next = Math.min(72, Math.max(6, numeric + delta));
13111325
settings.value.fontSize = `${next}px`;
13121326
settings.update(false);
13131327
return true;
13141328
}
13151329

1330+
function adjustUiZoom(delta) {
1331+
const current = Number(settings?.value?.uiZoom) || 100;
1332+
const next = Math.min(160, Math.max(70, current + delta));
1333+
settings.value.uiZoom = next;
1334+
settings.update(false);
1335+
return true;
1336+
}
1337+
13161338
function parseKeyString(keyString) {
13171339
if (!keyString) return [];
13181340
return String(keyString)
@@ -1356,10 +1378,12 @@ function buildResolvedKeyBindingsSnapshot() {
13561378

13571379
function toCodeMirrorKey(combo) {
13581380
if (!combo) return null;
1359-
const parts = combo
1360-
.split("-")
1361-
.map((part) => part.trim())
1362-
.filter(Boolean);
1381+
const parts = combo.endsWith("-")
1382+
? [...combo.slice(0, -1).split("-").filter(Boolean), "-"]
1383+
: combo
1384+
.split("-")
1385+
.map((part) => part.trim())
1386+
.filter(Boolean);
13631387
const modifiers = [];
13641388
let key = null;
13651389

src/components/terminal/terminal.js

Lines changed: 27 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import { WebLinksAddon } from "@xterm/addon-web-links";
1212
import { WebglAddon } from "@xterm/addon-webgl";
1313
import { Terminal as Xterm } from "@xterm/xterm";
1414
import {
15+
executeCommand,
1516
getResolvedKeyBindings,
1617
getResolvedKeyBindingsVersion,
1718
} from "cm/commandRegistry";
@@ -347,7 +348,7 @@ export default class TerminalComponent {
347348

348349
const parsedBindings = [];
349350

350-
Object.values(getResolvedKeyBindings()).forEach((binding) => {
351+
Object.entries(getResolvedKeyBindings()).forEach(([name, binding]) => {
351352
if (!binding.key) return;
352353

353354
// Skip editor-only keybindings in terminal
@@ -357,8 +358,11 @@ export default class TerminalComponent {
357358
const keys = binding.key.split("|");
358359

359360
keys.forEach((keyCombo) => {
360-
const parts = keyCombo.split("-");
361+
const parts = keyCombo.endsWith("-")
362+
? [...keyCombo.slice(0, -1).split("-").filter(Boolean), "-"]
363+
: keyCombo.split("-");
361364
const parsed = {
365+
name,
362366
ctrl: false,
363367
shift: false,
364368
alt: false,
@@ -414,62 +418,54 @@ export default class TerminalComponent {
414418
return false;
415419
}
416420

417-
// Check for Ctrl+= or Ctrl++ (increase font size)
418-
if (event.ctrlKey && (event.key === "+" || event.key === "=")) {
421+
// Keep terminal font zoom local. Shift variants are handled by app keybindings below.
422+
if (
423+
event.ctrlKey &&
424+
!event.shiftKey &&
425+
!event.altKey &&
426+
!event.metaKey &&
427+
(event.key === "+" || event.key === "=")
428+
) {
419429
event.preventDefault();
420430
this.increaseFontSize();
421431
return false;
422432
}
423433

424-
// Check for Ctrl+- (decrease font size)
425-
if (event.ctrlKey && event.key === "-") {
434+
if (
435+
event.ctrlKey &&
436+
!event.shiftKey &&
437+
!event.altKey &&
438+
!event.metaKey &&
439+
event.key === "-"
440+
) {
426441
event.preventDefault();
427442
this.decreaseFontSize();
428443
return false;
429444
}
430445

431-
// Only intercept specific app-wide keybindings, let terminal handle the rest
432446
if (event.ctrlKey || event.altKey || event.metaKey) {
433-
// Skip modifier-only keys
434447
if (["Control", "Alt", "Meta", "Shift"].includes(event.key)) {
435448
return true;
436449
}
437450

438-
// Get parsed app keybindings
439451
const appKeybindings = this.parseAppKeybindings();
440-
441-
// Check if this is an app-specific keybinding
442-
const isAppKeybinding = appKeybindings.some(
452+
const eventKey = event.key === "_" ? "-" : event.key.toLowerCase();
453+
const binding = appKeybindings.find(
443454
(binding) =>
444455
binding.ctrl === event.ctrlKey &&
445456
binding.shift === event.shiftKey &&
446457
binding.alt === event.altKey &&
447458
binding.meta === event.metaKey &&
448-
binding.key === event.key.toLowerCase(),
459+
binding.key === eventKey,
449460
);
450461

451-
if (isAppKeybinding) {
452-
const appEvent = new KeyboardEvent("keydown", {
453-
key: event.key,
454-
ctrlKey: event.ctrlKey,
455-
shiftKey: event.shiftKey,
456-
altKey: event.altKey,
457-
metaKey: event.metaKey,
458-
bubbles: true,
459-
cancelable: true,
460-
});
461-
462-
// Dispatch to document so it gets picked up by the app's keyboard handler
463-
document.dispatchEvent(appEvent);
464-
465-
// Return false to prevent terminal from processing this key
462+
if (binding && executeCommand(binding.name)) {
466463
return false;
467464
}
468-
469-
// For all other modifier combinations, let the terminal handle them
470-
return true;
471465
}
472466

467+
if (event.ctrlKey || event.altKey || event.metaKey) return true;
468+
473469
// Return true to allow normal processing for other keys
474470
return true;
475471
});

src/lang/ar-ye.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -723,5 +723,7 @@
723723
"close tabs to left": "Close Left",
724724
"close other tabs": "Close Others",
725725
"auto close tags": "Auto close tags",
726-
"settings-info-editor-auto-close-tags": "Automatically insert closing tags in HTML, XML, Vue, Angular, and PHP template files."
726+
"settings-info-editor-auto-close-tags": "Automatically insert closing tags in HTML, XML, Vue, Angular, and PHP template files.",
727+
"ui zoom": "UI zoom",
728+
"settings-info-app-ui-zoom": "Scale text across the Acode interface."
727729
}

src/lang/be-by.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -725,5 +725,7 @@
725725
"close tabs to left": "Close Left",
726726
"close other tabs": "Close Others",
727727
"auto close tags": "Auto close tags",
728-
"settings-info-editor-auto-close-tags": "Automatically insert closing tags in HTML, XML, Vue, Angular, and PHP template files."
728+
"settings-info-editor-auto-close-tags": "Automatically insert closing tags in HTML, XML, Vue, Angular, and PHP template files.",
729+
"ui zoom": "UI zoom",
730+
"settings-info-app-ui-zoom": "Scale text across the Acode interface."
729731
}

src/lang/bn-bd.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -724,5 +724,7 @@
724724
"close tabs to left": "Close Left",
725725
"close other tabs": "Close Others",
726726
"auto close tags": "Auto close tags",
727-
"settings-info-editor-auto-close-tags": "Automatically insert closing tags in HTML, XML, Vue, Angular, and PHP template files."
727+
"settings-info-editor-auto-close-tags": "Automatically insert closing tags in HTML, XML, Vue, Angular, and PHP template files.",
728+
"ui zoom": "UI zoom",
729+
"settings-info-app-ui-zoom": "Scale text across the Acode interface."
728730
}

src/lang/cs-cz.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -724,5 +724,7 @@
724724
"close tabs to left": "Close Left",
725725
"close other tabs": "Close Others",
726726
"auto close tags": "Auto close tags",
727-
"settings-info-editor-auto-close-tags": "Automatically insert closing tags in HTML, XML, Vue, Angular, and PHP template files."
727+
"settings-info-editor-auto-close-tags": "Automatically insert closing tags in HTML, XML, Vue, Angular, and PHP template files.",
728+
"ui zoom": "UI zoom",
729+
"settings-info-app-ui-zoom": "Scale text across the Acode interface."
728730
}

src/lang/de-de.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -724,5 +724,7 @@
724724
"close tabs to left": "Close Left",
725725
"close other tabs": "Close Others",
726726
"auto close tags": "Auto close tags",
727-
"settings-info-editor-auto-close-tags": "Automatically insert closing tags in HTML, XML, Vue, Angular, and PHP template files."
727+
"settings-info-editor-auto-close-tags": "Automatically insert closing tags in HTML, XML, Vue, Angular, and PHP template files.",
728+
"ui zoom": "UI zoom",
729+
"settings-info-app-ui-zoom": "Scale text across the Acode interface."
728730
}

src/lang/en-us.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,7 @@
8888
"tab size": "Tab size",
8989
"text wrap": "Text wrap / Word wrap",
9090
"theme": "Theme",
91+
"ui zoom": "UI zoom",
9192
"unable to delete file": "unable to delete file",
9293
"unable to open file": "Sorry, unable to open file",
9394
"unable to open folder": "Sorry, unable to open folder",
@@ -650,6 +651,7 @@
650651
"settings-info-app-side-buttons": "Show extra action buttons beside the editor.",
651652
"settings-info-app-sponsor-sidebar": "Show the sponsor entry in the sidebar.",
652653
"settings-info-app-touch-move-threshold": "Minimum movement before a touch drag is detected.",
654+
"settings-info-app-ui-zoom": "Scale text across the Acode interface.",
653655
"settings-info-app-vibrate-on-tap": "Enable haptic feedback for taps and controls.",
654656
"settings-info-editor-autosave": "Save changes automatically after a delay.",
655657
"settings-info-editor-color-preview": "Preview color values inline in the editor.",

src/lang/es-sv.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -724,5 +724,7 @@
724724
"close tabs to left": "Close Left",
725725
"close other tabs": "Close Others",
726726
"auto close tags": "Auto close tags",
727-
"settings-info-editor-auto-close-tags": "Automatically insert closing tags in HTML, XML, Vue, Angular, and PHP template files."
727+
"settings-info-editor-auto-close-tags": "Automatically insert closing tags in HTML, XML, Vue, Angular, and PHP template files.",
728+
"ui zoom": "UI zoom",
729+
"settings-info-app-ui-zoom": "Scale text across the Acode interface."
728730
}

src/lang/fr-fr.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -724,5 +724,7 @@
724724
"close tabs to left": "Close Left",
725725
"close other tabs": "Close Others",
726726
"auto close tags": "Auto close tags",
727-
"settings-info-editor-auto-close-tags": "Automatically insert closing tags in HTML, XML, Vue, Angular, and PHP template files."
727+
"settings-info-editor-auto-close-tags": "Automatically insert closing tags in HTML, XML, Vue, Angular, and PHP template files.",
728+
"ui zoom": "UI zoom",
729+
"settings-info-app-ui-zoom": "Scale text across the Acode interface."
728730
}

0 commit comments

Comments
 (0)