Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 41 additions & 1 deletion GhosttyTabs.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,12 @@
A5007420 /* BrowserPopupWindowController.swift in Sources */ = {isa = PBXBuildFile; fileRef = A5007421 /* BrowserPopupWindowController.swift */; };
A5001420 /* MarkdownPanel.swift in Sources */ = {isa = PBXBuildFile; fileRef = A5001418 /* MarkdownPanel.swift */; };
A5001421 /* MarkdownPanelView.swift in Sources */ = {isa = PBXBuildFile; fileRef = A5001419 /* MarkdownPanelView.swift */; };
A5001422 /* EditorPanel.swift in Sources */ = {isa = PBXBuildFile; fileRef = A500141A /* EditorPanel.swift */; };
A5001423 /* EditorPanelView.swift in Sources */ = {isa = PBXBuildFile; fileRef = A500141B /* EditorPanelView.swift */; };
EXP00001 /* ExplorerSidebarPanel.swift in Sources */ = {isa = PBXBuildFile; fileRef = EXP00011 /* ExplorerSidebarPanel.swift */; };
EXP00002 /* ExplorerSidebarView.swift in Sources */ = {isa = PBXBuildFile; fileRef = EXP00012 /* ExplorerSidebarView.swift */; };
A5001424 /* editor in Resources */ = {isa = PBXBuildFile; fileRef = A500141C /* editor */; };
EXP00003 /* explorer in Resources */ = {isa = PBXBuildFile; fileRef = EXP00013 /* explorer */; };
A5001290 /* MarkdownUI in Frameworks */ = {isa = PBXBuildFile; productRef = A5001291 /* MarkdownUI */; };
A5001405 /* PanelContentView.swift in Sources */ = {isa = PBXBuildFile; fileRef = A5001415 /* PanelContentView.swift */; };
A5001406 /* Workspace.swift in Sources */ = {isa = PBXBuildFile; fileRef = A5001416 /* Workspace.swift */; };
Expand Down Expand Up @@ -123,7 +129,11 @@
CA39C0304FE351A21C372429 /* SidebarWidthPolicyTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = EE0171AF1F49F7547191CEE5 /* SidebarWidthPolicyTests.swift */; };
8C4BBF2DEF6DF93F395A9EE7 /* TerminalControllerSocketSecurityTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 491751CE2321474474F27DCF /* TerminalControllerSocketSecurityTests.swift */; };
2BB56A710BB1FC50367E5BCF /* TabManagerSessionSnapshotTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 10D684CFFB8CDEF89CE2D9E1 /* TabManagerSessionSnapshotTests.swift */; };
/* End PBXBuildFile section */
MWP00001 /* MonacoWebViewPool.swift in Sources */ = {isa = PBXBuildFile; fileRef = MWP00011 /* MonacoWebViewPool.swift */; };
NFE00001 /* NativeFileExplorer.swift in Sources */ = {isa = PBXBuildFile; fileRef = NFE00011 /* NativeFileExplorer.swift */; };
FSV00001 /* FileSearchView.swift in Sources */ = {isa = PBXBuildFile; fileRef = FSV00011 /* FileSearchView.swift */; };
STS00001 /* SidebarTabSelector.swift in Sources */ = {isa = PBXBuildFile; fileRef = STS00011 /* SidebarTabSelector.swift */; };
/* End PBXBuildFile section */

/* Begin PBXCopyFilesBuildPhase section */
A5001020 /* Embed Frameworks */ = {
Expand Down Expand Up @@ -210,6 +220,12 @@
A5001415 /* PanelContentView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Panels/PanelContentView.swift; sourceTree = "<group>"; };
A5001418 /* MarkdownPanel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Panels/MarkdownPanel.swift; sourceTree = "<group>"; };
A5001419 /* MarkdownPanelView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Panels/MarkdownPanelView.swift; sourceTree = "<group>"; };
A500141A /* EditorPanel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Panels/EditorPanel.swift; sourceTree = "<group>"; };
A500141B /* EditorPanelView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Panels/EditorPanelView.swift; sourceTree = "<group>"; };
EXP00011 /* ExplorerSidebarPanel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Panels/ExplorerSidebarPanel.swift; sourceTree = "<group>"; };
EXP00012 /* ExplorerSidebarView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Panels/ExplorerSidebarView.swift; sourceTree = "<group>"; };
A500141C /* editor */ = {isa = PBXFileReference; lastKnownFileType = folder; path = editor; sourceTree = "<group>"; };
EXP00013 /* explorer */ = {isa = PBXFileReference; lastKnownFileType = folder; path = explorer; sourceTree = "<group>"; };
A5001416 /* Workspace.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Workspace.swift; sourceTree = "<group>"; };
A5001417 /* WorkspaceContentView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = WorkspaceContentView.swift; sourceTree = "<group>"; };
A5001090 /* AppDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -292,6 +308,10 @@
EE0171AF1F49F7547191CEE5 /* SidebarWidthPolicyTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SidebarWidthPolicyTests.swift; sourceTree = "<group>"; };
491751CE2321474474F27DCF /* TerminalControllerSocketSecurityTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TerminalControllerSocketSecurityTests.swift; sourceTree = "<group>"; };
10D684CFFB8CDEF89CE2D9E1 /* TabManagerSessionSnapshotTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TabManagerSessionSnapshotTests.swift; sourceTree = "<group>"; };
MWP00011 /* MonacoWebViewPool.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MonacoWebViewPool.swift; sourceTree = "<group>"; };
NFE00011 /* NativeFileExplorer.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NativeFileExplorer.swift; sourceTree = "<group>"; };
FSV00011 /* FileSearchView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = FileSearchView.swift; sourceTree = "<group>"; };
STS00011 /* SidebarTabSelector.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SidebarTabSelector.swift; sourceTree = "<group>"; };
/* End PBXFileReference section */

/* Begin PBXFrameworksBuildPhase section */
Expand Down Expand Up @@ -342,6 +362,8 @@
DA7A10CA710E000000000003 /* Localizable.xcstrings in Resources */,
DA7A10CA710E000000000004 /* InfoPlist.xcstrings in Resources */,
A5001623 /* cmux.sdef in Resources */,
A5001424 /* editor in Resources */,
EXP00003 /* explorer in Resources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Expand Down Expand Up @@ -439,6 +461,10 @@
A5007421 /* BrowserPopupWindowController.swift */,
A5001418 /* MarkdownPanel.swift */,
A5001419 /* MarkdownPanelView.swift */,
A500141A /* EditorPanel.swift */,
A500141B /* EditorPanelView.swift */,
EXP00011 /* ExplorerSidebarPanel.swift */,
EXP00012 /* ExplorerSidebarView.swift */,
A5001510 /* CmuxWebView.swift */,
A5001415 /* PanelContentView.swift */,
A5001211 /* UpdateController.swift */,
Expand All @@ -458,6 +484,10 @@
A5001222 /* WindowAccessor.swift */,
A5001611 /* SessionPersistence.swift */,
A5001641 /* RemoteRelayZshBootstrap.swift */,
MWP00011 /* MonacoWebViewPool.swift */,
NFE00011 /* NativeFileExplorer.swift */,
FSV00011 /* FileSearchView.swift */,
STS00011 /* SidebarTabSelector.swift */,
);
path = Sources;
sourceTree = "<group>";
Expand All @@ -479,6 +509,8 @@
DA7A10CA710E000000000001 /* Localizable.xcstrings */,
DA7A10CA710E000000000002 /* InfoPlist.xcstrings */,
A5001622 /* cmux.sdef */,
A500141C /* editor */,
EXP00013 /* explorer */,
);
path = Resources;
sourceTree = "<group>";
Expand Down Expand Up @@ -734,6 +766,10 @@
A5007420 /* BrowserPopupWindowController.swift in Sources */,
A5001420 /* MarkdownPanel.swift in Sources */,
A5001421 /* MarkdownPanelView.swift in Sources */,
A5001422 /* EditorPanel.swift in Sources */,
A5001423 /* EditorPanelView.swift in Sources */,
EXP00001 /* ExplorerSidebarPanel.swift in Sources */,
EXP00002 /* ExplorerSidebarView.swift in Sources */,
A5001500 /* CmuxWebView.swift in Sources */,
A5001405 /* PanelContentView.swift in Sources */,
A5001201 /* UpdateController.swift in Sources */,
Expand All @@ -753,6 +789,10 @@
A500120C /* WindowAccessor.swift in Sources */,
A5001610 /* SessionPersistence.swift in Sources */,
A5001640 /* RemoteRelayZshBootstrap.swift in Sources */,
MWP00001 /* MonacoWebViewPool.swift in Sources */,
NFE00001 /* NativeFileExplorer.swift in Sources */,
FSV00001 /* FileSearchView.swift in Sources */,
STS00001 /* SidebarTabSelector.swift in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Expand Down
220 changes: 220 additions & 0 deletions Resources/editor/editor.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,220 @@
// cmux Editor — single-file Monaco editor
// Swift injects Monaco paths via window.cmux.initMonaco(vsPath, cssPath)
// Swift injects file content directly via window.cmux.openFileWithContent()

(function () {
'use strict';

let editor = null;
let monacoInstance = null;
let currentFilePath = null;
let originalContent = '';
let isDirty = false;
let requestCounter = 0;
const pendingRequests = new Map();

// ── Swift Bridge ───────────────────────────────────────────────────
window.cmux = {
handleResponse(requestId, data) {
const p = pendingRequests.get(requestId);
if (!p) return;
pendingRequests.delete(requestId);
if (typeof data === 'string') {
try { p.resolve(JSON.parse(data)); } catch { p.resolve(data); }
} else {
p.resolve(data);
}
},
handleError(requestId, message) {
const p = pendingRequests.get(requestId);
if (!p) return;
pendingRequests.delete(requestId);
p.reject(new Error(message));
},
updateMonacoTheme(editorBg, editorFg) {
if (!monacoInstance || !editor) return;
monacoInstance.editor.defineTheme('cmux-dark', {
base: 'vs-dark', inherit: true, rules: [],
colors: {
'editor.background': editorBg,
'editorGutter.background': editorBg,
'editor.lineHighlightBackground': editorBg + '22',
'editorLineNumber.foreground': editorFg + '55',
'editorLineNumber.activeForeground': editorFg + 'cc'
}
});
monacoInstance.editor.setTheme('cmux-dark');
document.documentElement.style.setProperty('--editor-bg', editorBg);
},

// Called from Swift with file content already read — zero bridge round-trips
openFileWithContent(relativePath, fileName, content) {
if (!editor || !monacoInstance) {
window.cmux._pendingOpen = { relativePath, fileName, content };
return;
}
doOpenFileWithContent(relativePath, fileName, content);
},

// Called from Swift when file is too large
showLargeFile(fileName, reason) {
currentFilePath = null;
if (editor) editor.setModel(null);
showLargeFileNotice(fileName, reason);
notifyActive(fileName);
},

// Called from Swift with Monaco paths — triggers init
initMonaco(vsPath, cssHref) {
if (cssHref) {
const link = document.createElement('link');
link.rel = 'stylesheet';
link.href = cssHref;
document.head.appendChild(link);
}
const script = document.createElement('script');
script.onload = function() { bootstrapMonaco(vsPath); };
script.src = vsPath + '/loader.js';
document.head.appendChild(script);
}
};

function showLargeFileNotice(fileName, reason) {
document.getElementById('editor-container').style.display = 'none';
const notice = document.getElementById('large-file-notice');
document.getElementById('large-file-name').textContent = fileName;
document.getElementById('large-file-message').textContent = reason;
notice.classList.add('visible');
}

function hideLargeFileNotice() {
document.getElementById('large-file-notice').classList.remove('visible');
document.getElementById('editor-container').style.display = '';
}

function doOpenFileWithContent(relativePath, fileName, content) {
hideLargeFileNotice();
currentFilePath = relativePath;
originalContent = content;
isDirty = false;
const lang = getLang(fileName);
const model = monacoInstance.editor.createModel(content, lang);
const oldModel = editor.getModel();
editor.setModel(model);
if (oldModel) oldModel.dispose();
model.onDidChangeContent(() => {
const nowDirty = model.getValue() !== originalContent;
if (nowDirty !== isDirty) {
isDirty = nowDirty;
notifyDirty(isDirty);
}
});
notifyActive(fileName);
}

// Bridge for save — writeFile still needs async round-trip
function post(action, params = {}) {
return new Promise((resolve, reject) => {
const requestId = 'r' + (++requestCounter);
pendingRequests.set(requestId, { resolve, reject });
window.webkit.messageHandlers.cmuxEditor.postMessage({ action, requestId, ...params });
});
}

const writeFile = (path, content) => post('writeFile', { path, content });

function notifyDirty(d) {
window.webkit.messageHandlers.cmuxEditor.postMessage({ action: 'dirtyState', isDirty: d });
}
function notifyActive(n) {
window.webkit.messageHandlers.cmuxEditor.postMessage({ action: 'activeFile', fileName: n || null });
}
function notifyReady() {
window.webkit.messageHandlers.cmuxEditor.postMessage({ action: 'editorReady' });
}

function getLang(name) {
const ext = (name || '').split('.').pop().toLowerCase();
const m = {
js:'javascript',jsx:'javascript',mjs:'javascript',cjs:'javascript',
ts:'typescript',tsx:'typescript',
py:'python',rb:'ruby',rs:'rust',go:'go',java:'java',kt:'kotlin',
c:'c',h:'c',cpp:'cpp',hpp:'cpp',cs:'csharp',swift:'swift',
html:'html',htm:'html',css:'css',scss:'scss',less:'less',
json:'json',yaml:'yaml',yml:'yaml',xml:'xml',svg:'xml',
md:'markdown',sh:'shell',bash:'shell',zsh:'shell',fish:'shell',
sql:'sql',toml:'ini',ini:'ini',dockerfile:'dockerfile',
lua:'lua',php:'php',r:'r',zig:'zig'
};
return m[ext] || 'plaintext';
}

async function saveActive() {
if (!currentFilePath || !editor) return;
const content = editor.getModel().getValue();
try {
await writeFile(currentFilePath, content);
originalContent = content;
isDirty = false;
notifyDirty(false);
} catch (err) { console.error('Save failed:', err); }
}

function bootstrapMonaco(vsPath) {
require.config({ paths: { vs: vsPath } });

require(['vs/editor/editor.main'], async function (monaco) {
monacoInstance = monaco;

monaco.editor.defineTheme('cmux-dark', {
base: 'vs-dark', inherit: true, rules: [],
colors: {
'editor.background': '#1f1f1f',
'editorGutter.background': '#1f1f1f',
'editor.lineHighlightBackground': '#2a2d2e',
'editorLineNumber.foreground': '#5a5a5a',
'editorLineNumber.activeForeground': '#c6c6c6'
}
});

editor = monaco.editor.create(document.getElementById('editor-container'), {
theme: 'cmux-dark',
fontSize: 13,
fontFamily: "'SF Mono', 'Menlo', 'Monaco', 'Courier New', monospace",
minimap: { enabled: false },
scrollBeyondLastLine: false,
automaticLayout: true,
wordWrap: 'off',
renderWhitespace: 'selection',
lineNumbers: 'on',
roundedSelection: false,
cursorBlinking: 'smooth',
smoothScrolling: true,
padding: { top: 8, bottom: 8 },
overviewRulerBorder: false,
bracketPairColorization: { enabled: true },
guides: { indentation: true, bracketPairs: true },
stickyScroll: { enabled: true }
});

// Cmd+S — save
editor.addCommand(monaco.KeyMod.CtrlCmd | monaco.KeyCode.KeyS, () => saveActive());

// Disable Monaco shortcuts that conflict with cmux
editor.addCommand(monaco.KeyMod.CtrlCmd | monaco.KeyMod.Shift | monaco.KeyCode.KeyF, () => {});
editor.addCommand(monaco.KeyMod.CtrlCmd | monaco.KeyCode.KeyP, () => {});
editor.addCommand(monaco.KeyMod.CtrlCmd | monaco.KeyMod.Shift | monaco.KeyCode.KeyP, () => {});
editor.addCommand(monaco.KeyMod.CtrlCmd | monaco.KeyCode.KeyN, () => {});
editor.addCommand(monaco.KeyMod.CtrlCmd | monaco.KeyMod.Shift | monaco.KeyCode.KeyN, () => {});

notifyReady();

// Open any file that was queued before Monaco was ready
if (window.cmux._pendingOpen) {
const pending = window.cmux._pendingOpen;
delete window.cmux._pendingOpen;
doOpenFileWithContent(pending.relativePath, pending.fileName, pending.content);
}
});
}
})();
32 changes: 32 additions & 0 deletions Resources/editor/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>cmux Editor</title>
<style>
* { margin: 0; padding: 0; box-sizing: border-box; }
html, body { height: 100%; overflow: hidden; background: var(--editor-bg, #1f1f1f); color: var(--editor-fg, #cccccc); }
:root { --editor-bg: #1f1f1f; --editor-fg: #cccccc; }
#editor-container { width: 100%; height: 100%; }
#large-file-notice {
display: none;
width: 100%; height: 100%;
align-items: center; justify-content: center;
flex-direction: column; gap: 8px;
font-family: -apple-system, BlinkMacSystemFont, 'SF Pro', sans-serif;
}
#large-file-notice.visible { display: flex; }
#large-file-notice .filename { font-style: italic; font-size: 14px; opacity: 0.7; }
#large-file-notice .message { font-size: 13px; opacity: 0.4; }
</style>
</head>
<body>
<div id="editor-container"></div>
<div id="large-file-notice">
<div class="filename" id="large-file-name"></div>
<div class="message" id="large-file-message"></div>
</div>
<script src="editor.js"></script>
</body>
</html>
Loading