-
Notifications
You must be signed in to change notification settings - Fork 2.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add secondary window support for text editors #13493
Merged
tsmaeder
merged 10 commits into
eclipse-theia:master
from
tsmaeder:13163_extractable_editors
Mar 27, 2024
Merged
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
8978f43
Add secondary window support for text editors
tsmaeder 7ba1fcc
Patch monaco to make sashes work in secondary windows.
tsmaeder 001d5b5
Reworked patching mechanism
tsmaeder bbed807
Use full path of patch-package script
tsmaeder b7947e3
Add executable flags to theia-patch.js
tsmaeder c104dc6
Make the linter happy.
tsmaeder 1606a23
Fix bogus context menu patch
tsmaeder 3ca8d00
Address review comments
tsmaeder cbfc698
Addressing more review comments.
tsmaeder 21ded4e
Add changelog entry
tsmaeder File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
#!/usr/bin/env node | ||
|
||
// ***************************************************************************** | ||
// Copyright (C) 2024 STMicroelectronics and others. | ||
// | ||
// This program and the accompanying materials are made available under the | ||
// terms of the Eclipse Public License v. 2.0 which is available at | ||
// http://www.eclipse.org/legal/epl-2.0. | ||
// | ||
// This Source Code may also be made available under the following Secondary | ||
// Licenses when the conditions for such availability set forth in the Eclipse | ||
// Public License v. 2.0 are satisfied: GNU General Public License, version 2 | ||
// with the GNU Classpath Exception which is available at | ||
// https://www.gnu.org/software/classpath/license.html. | ||
// | ||
// SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-only WITH Classpath-exception-2.0 | ||
// ***************************************************************************** | ||
// @ts-check | ||
const path = require('path'); | ||
const cp = require('child_process'); | ||
|
||
const patchPackage= require.resolve('patch-package'); | ||
console.log(`patch-package = ${patchPackage}`); | ||
|
||
const patchesDir = path.join('.', 'node_modules', '@theia', 'cli', 'patches'); | ||
|
||
console.log(`patchesdir = ${patchesDir}`); | ||
|
||
const env = Object.assign({}, process.env); | ||
|
||
const scriptProcess = cp.exec(`node ${patchPackage} --patch-dir "${patchesDir}"`, { | ||
cwd: process.cwd(), | ||
env, | ||
|
||
}); | ||
|
||
scriptProcess.stdout.pipe(process.stdout); | ||
scriptProcess.stderr.pipe(process.stderr); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,157 @@ | ||
diff --git a/node_modules/@phosphor/widgets/lib/menu.d.ts b/node_modules/@phosphor/widgets/lib/menu.d.ts | ||
index 5d5053c..7802167 100644 | ||
--- a/node_modules/@phosphor/widgets/lib/menu.d.ts | ||
+++ b/node_modules/@phosphor/widgets/lib/menu.d.ts | ||
@@ -195,7 +195,7 @@ export declare class Menu extends Widget { | ||
* | ||
* This is a no-op if the menu is already attached to the DOM. | ||
*/ | ||
- open(x: number, y: number, options?: Menu.IOpenOptions): void; | ||
+ open(x: number, y: number, options?: Menu.IOpenOptions, anchor?: HTMLElement): void; | ||
/** | ||
* Handle the DOM events for the menu. | ||
* | ||
diff --git a/node_modules/@phosphor/widgets/lib/menu.js b/node_modules/@phosphor/widgets/lib/menu.js | ||
index de23022..a8b15b1 100644 | ||
--- a/node_modules/@phosphor/widgets/lib/menu.js | ||
+++ b/node_modules/@phosphor/widgets/lib/menu.js | ||
@@ -13,7 +13,7 @@ var __extends = (this && this.__extends) || (function () { | ||
}; | ||
})(); | ||
var __assign = (this && this.__assign) || function () { | ||
- __assign = Object.assign || function(t) { | ||
+ __assign = Object.assign || function (t) { | ||
for (var s, i = 1, n = arguments.length; i < n; i++) { | ||
s = arguments[i]; | ||
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) | ||
@@ -424,7 +424,7 @@ var Menu = /** @class */ (function (_super) { | ||
* | ||
* This is a no-op if the menu is already attached to the DOM. | ||
*/ | ||
- Menu.prototype.open = function (x, y, options) { | ||
+ Menu.prototype.open = function (x, y, options, node) { | ||
if (options === void 0) { options = {}; } | ||
// Bail early if the menu is already attached. | ||
if (this.isAttached) { | ||
@@ -434,7 +434,7 @@ var Menu = /** @class */ (function (_super) { | ||
var forceX = options.forceX || false; | ||
var forceY = options.forceY || false; | ||
// Open the menu as a root menu. | ||
- Private.openRootMenu(this, x, y, forceX, forceY); | ||
+ Private.openRootMenu(this, x, y, forceX, forceY, node); | ||
// Activate the menu to accept keyboard input. | ||
this.activate(); | ||
}; | ||
@@ -484,8 +484,16 @@ var Menu = /** @class */ (function (_super) { | ||
this.node.addEventListener('mouseenter', this); | ||
this.node.addEventListener('mouseleave', this); | ||
this.node.addEventListener('contextmenu', this); | ||
- document.addEventListener('mousedown', this, true); | ||
}; | ||
+ | ||
+ Menu.prototype.onAfterAttach = function (msg) { | ||
+ this.node.ownerDocument.addEventListener('mousedown', this, true); | ||
+ } | ||
+ | ||
+ Menu.prototype.onBeforeDetach = function (msg) { | ||
+ this.node.ownerDocument.removeEventListener('mousedown', this, true); | ||
+ } | ||
+ | ||
/** | ||
* A message handler invoked on an `'after-detach'` message. | ||
*/ | ||
@@ -496,7 +504,6 @@ var Menu = /** @class */ (function (_super) { | ||
this.node.removeEventListener('mouseenter', this); | ||
this.node.removeEventListener('mouseleave', this); | ||
this.node.removeEventListener('contextmenu', this); | ||
- document.removeEventListener('mousedown', this, true); | ||
}; | ||
/** | ||
* A message handler invoked on an `'activate-request'` message. | ||
@@ -1124,14 +1131,15 @@ var Private; | ||
/** | ||
* Open a menu as a root menu at the target location. | ||
*/ | ||
- function openRootMenu(menu, x, y, forceX, forceY) { | ||
+ function openRootMenu(menu, x, y, forceX, forceY, element) { | ||
// Ensure the menu is updated before attaching and measuring. | ||
messaging_1.MessageLoop.sendMessage(menu, widget_1.Widget.Msg.UpdateRequest); | ||
// Get the current position and size of the main viewport. | ||
+ var doc = element ? element.ownerDocument : document; | ||
var px = window.pageXOffset; | ||
var py = window.pageYOffset; | ||
- var cw = document.documentElement.clientWidth; | ||
- var ch = document.documentElement.clientHeight; | ||
+ var cw = doc.documentElement.clientWidth; | ||
+ var ch = doc.documentElement.clientHeight; | ||
// Compute the maximum allowed height for the menu. | ||
var maxHeight = ch - (forceY ? y : 0); | ||
// Fetch common variables. | ||
@@ -1145,7 +1153,7 @@ var Private; | ||
style.visibility = 'hidden'; | ||
style.maxHeight = maxHeight + "px"; | ||
// Attach the menu to the document. | ||
- widget_1.Widget.attach(menu, document.body); | ||
+ widget_1.Widget.attach(menu, doc.body); | ||
// Measure the size of the menu. | ||
var _a = node.getBoundingClientRect(), width = _a.width, height = _a.height; | ||
// Adjust the X position of the menu to fit on-screen. | ||
@@ -1177,8 +1185,8 @@ var Private; | ||
// Get the current position and size of the main viewport. | ||
var px = window.pageXOffset; | ||
var py = window.pageYOffset; | ||
- var cw = document.documentElement.clientWidth; | ||
- var ch = document.documentElement.clientHeight; | ||
+ var cw = itemNode.ownerDocument.documentElement.clientWidth; | ||
+ var ch = itemNode.ownerDocument.documentElement.clientHeight; | ||
// Compute the maximum allowed height for the menu. | ||
var maxHeight = ch; | ||
// Fetch common variables. | ||
@@ -1192,7 +1200,7 @@ var Private; | ||
style.visibility = 'hidden'; | ||
style.maxHeight = maxHeight + "px"; | ||
// Attach the menu to the document. | ||
- widget_1.Widget.attach(submenu, document.body); | ||
+ widget_1.Widget.attach(submenu, itemNode.ownerDocument.body); | ||
// Measure the size of the menu. | ||
var _a = node.getBoundingClientRect(), width = _a.width, height = _a.height; | ||
// Compute the box sizing for the menu. | ||
diff --git a/node_modules/@phosphor/widgets/lib/menubar.js b/node_modules/@phosphor/widgets/lib/menubar.js | ||
index a8e10f4..da2ee82 100644 | ||
--- a/node_modules/@phosphor/widgets/lib/menubar.js | ||
+++ b/node_modules/@phosphor/widgets/lib/menubar.js | ||
@@ -521,7 +521,7 @@ var MenuBar = /** @class */ (function (_super) { | ||
// Get the positioning data for the new menu. | ||
var _a = itemNode.getBoundingClientRect(), left = _a.left, bottom = _a.bottom; | ||
// Open the new menu at the computed location. | ||
- newMenu.open(left, bottom, { forceX: true, forceY: true }); | ||
+ newMenu.open(left, bottom, { forceX: true, forceY: true }, this.node); | ||
}; | ||
/** | ||
* Close the child menu immediately. | ||
diff --git a/node_modules/@phosphor/widgets/lib/widget.js b/node_modules/@phosphor/widgets/lib/widget.js | ||
index 01241fa..62da27c 100644 | ||
--- a/node_modules/@phosphor/widgets/lib/widget.js | ||
+++ b/node_modules/@phosphor/widgets/lib/widget.js | ||
@@ -906,10 +906,10 @@ exports.Widget = Widget; | ||
if (widget.parent) { | ||
throw new Error('Cannot attach a child widget.'); | ||
} | ||
- if (widget.isAttached || document.body.contains(widget.node)) { | ||
+ if (widget.isAttached || widget.node.ownerDocument.body.contains(widget.node)) { | ||
throw new Error('Widget is already attached.'); | ||
} | ||
- if (!document.body.contains(host)) { | ||
+ if (!host.ownerDocument.body.contains(host)) { | ||
throw new Error('Host is not attached.'); | ||
} | ||
messaging_1.MessageLoop.sendMessage(widget, Widget.Msg.BeforeAttach); | ||
@@ -930,7 +930,7 @@ exports.Widget = Widget; | ||
if (widget.parent) { | ||
throw new Error('Cannot detach a child widget.'); | ||
} | ||
- if (!widget.isAttached || !document.body.contains(widget.node)) { | ||
+ if (!widget.isAttached || !widget.node.ownerDocument.body.contains(widget.node)) { | ||
throw new Error('Widget is not attached.'); | ||
} | ||
messaging_1.MessageLoop.sendMessage(widget, Widget.Msg.BeforeDetach); |
32 changes: 32 additions & 0 deletions
32
dev-packages/cli/patches/@theia+monaco-editor-core+1.83.101.patch
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
diff --git a/node_modules/@theia/monaco-editor-core/esm/vs/base/browser/ui/sash/sash.js b/node_modules/@theia/monaco-editor-core/esm/vs/base/browser/ui/sash/sash.js | ||
index 111dec4..b196066 100644 | ||
--- a/node_modules/@theia/monaco-editor-core/esm/vs/base/browser/ui/sash/sash.js | ||
+++ b/node_modules/@theia/monaco-editor-core/esm/vs/base/browser/ui/sash/sash.js | ||
@@ -47,14 +47,15 @@ function setGlobalHoverDelay(size) { | ||
} | ||
exports.setGlobalHoverDelay = setGlobalHoverDelay; | ||
class MouseEventFactory { | ||
- constructor() { | ||
+ constructor(el) { | ||
+ this.el = el; | ||
this.disposables = new lifecycle_1.DisposableStore(); | ||
} | ||
get onPointerMove() { | ||
- return this.disposables.add(new event_1.DomEmitter(window, 'mousemove')).event; | ||
+ return this.disposables.add(new event_1.DomEmitter(this.el.ownerDocument.defaultView, 'mousemove')).event; | ||
} | ||
get onPointerUp() { | ||
- return this.disposables.add(new event_1.DomEmitter(window, 'mouseup')).event; | ||
+ return this.disposables.add(new event_1.DomEmitter(this.el.ownerDocument.defaultView, 'mouseup')).event; | ||
} | ||
dispose() { | ||
this.disposables.dispose(); | ||
@@ -243,7 +244,7 @@ class Sash extends lifecycle_1.Disposable { | ||
this.el.classList.add('mac'); | ||
} | ||
const onMouseDown = this._register(new event_1.DomEmitter(this.el, 'mousedown')).event; | ||
- this._register(onMouseDown(e => this.onPointerStart(e, new MouseEventFactory()), this)); | ||
+ this._register(onMouseDown(e => this.onPointerStart(e, new MouseEventFactory(this.el)), this)); | ||
const onMouseDoubleClick = this._register(new event_1.DomEmitter(this.el, 'dblclick')).event; | ||
this._register(onMouseDoubleClick(this.onPointerDoublePress, this)); | ||
const onMouseEnter = this._register(new event_1.DomEmitter(this.el, 'mouseenter')).event; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -213,4 +213,4 @@ | |
"nyc": { | ||
"extends": "../../configs/nyc.json" | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why is this change required?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If I recall correctly, the monaco editor uses wasm for tokenizing and the wasm files were not included in the bundle.