Skip to content
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

Investigating setting edit context on new window #229923

Closed
wants to merge 2 commits into from
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
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import { Position } from '../../../../common/core/position.js';
import { IVisibleRangeProvider } from '../textArea/textAreaEditContext.js';
import { PositionOffsetTransformer } from '../../../../common/core/positionToOffset.js';
import { CodeWindow } from '../../../../../base/browser/window.js';

// Corresponds to classes in nativeEditContext.css
enum CompositionClassName {
Expand All @@ -51,6 +52,7 @@

constructor(
context: ViewContext,
ownerWindow: CodeWindow,
viewController: ViewController,
private readonly _visibleRangeProvider: IVisibleRangeProvider,
@IInstantiationService instantiationService: IInstantiationService,
Expand All @@ -64,7 +66,12 @@

this._focusTracker = this._register(new FocusTracker(this.domNode.domNode, (newFocusValue: boolean) => this._context.viewModel.setHasFocus(newFocusValue)));

this._editContext = new EditContext();
const doesEditContextExist = 'EditContext' in ownerWindow;
console.log('doesEditContextExist : ', doesEditContextExist);
this._editContext = new ownerWindow.EditContext();

Check failure on line 71 in src/vs/editor/browser/controller/editContext/native/nativeEditContext.ts

View workflow job for this annotation

GitHub Actions / Monaco Editor checks

Property 'EditContext' does not exist on type 'CodeWindow'.
console.log('after creating edit context');
console.log('this._editContext : ', this._editContext);
console.log('this.domNode.domNode : ', this.domNode.domNode);
this.domNode.domNode.editContext = this._editContext;

this._screenReaderSupport = instantiationService.createInstance(ScreenReaderSupport, this.domNode, context);
Expand Down Expand Up @@ -96,16 +103,19 @@
this._register(editContextAddDisposableListener(this._editContext, 'textformatupdate', (e) => this._handleTextFormatUpdate(e)));
this._register(editContextAddDisposableListener(this._editContext, 'characterboundsupdate', (e) => this._updateCharacterBounds(e)));
this._register(editContextAddDisposableListener(this._editContext, 'textupdate', (e) => {
console.log('text update : ', e);
this._emitTypeEvent(viewController, e);
}));
this._register(editContextAddDisposableListener(this._editContext, 'compositionstart', (e) => {
console.log('composition start : ', e);
// Utlimately fires onDidCompositionStart() on the editor to notify for example suggest model of composition state
// Updates the composition state of the cursor controller which determines behavior of typing with interceptors
viewController.compositionStart();
// Emits ViewCompositionStartEvent which can be depended on by ViewEventHandlers
this._context.viewModel.onCompositionStart();
}));
this._register(editContextAddDisposableListener(this._editContext, 'compositionend', (e) => {
console.log('composition end : ', e);
// Utlimately fires compositionEnd() on the editor to notify for example suggest model of composition state
// Updates the composition state of the cursor controller which determines behavior of typing with interceptors
viewController.compositionEnd();
Expand Down
31 changes: 21 additions & 10 deletions src/vs/editor/browser/view.ts
Original file line number Diff line number Diff line change
Expand Up @@ -134,30 +134,31 @@ export class View extends ViewEventHandler {

this._viewParts = [];

this.domNode = createFastDomNode(document.createElement('div'));
this.domNode.setAttribute('role', 'code');

this._overflowGuardContainer = createFastDomNode(document.createElement('div'));
PartFingerprints.write(this._overflowGuardContainer, PartFingerprint.OverflowGuard);
this._overflowGuardContainer.setClassName('overflow-guard');

// Keyboard handler
this._experimentalEditContextEnabled = this._context.configuration.options.get(EditorOption.experimentalEditContextEnabled);
this._editContext = this._instantiateEditContext(this._experimentalEditContextEnabled);

this.domNode.setClassName(this._getEditorClassName());
// Set role 'code' for better screen reader support https://github.com/microsoft/vscode/issues/93438

this._viewParts.push(this._editContext);

// These two dom nodes must be constructed up front, since references are needed in the layout provider (scrolling & co.)
this._linesContent = createFastDomNode(document.createElement('div'));
this._linesContent.setClassName('lines-content' + ' monaco-editor-background');
this._linesContent.setPosition('absolute');

this.domNode = createFastDomNode(document.createElement('div'));
this.domNode.setClassName(this._getEditorClassName());
// Set role 'code' for better screen reader support https://github.com/microsoft/vscode/issues/93438
this.domNode.setAttribute('role', 'code');

if (this._context.configuration.options.get(EditorOption.experimentalGpuAcceleration) === 'on') {
this._viewGpuContext = this._instantiationService.createInstance(ViewGpuContext, this._context);
}

this._overflowGuardContainer = createFastDomNode(document.createElement('div'));
PartFingerprints.write(this._overflowGuardContainer, PartFingerprint.OverflowGuard);
this._overflowGuardContainer.setClassName('overflow-guard');

this._scrollbar = new EditorScrollbar(this._context, this._linesContent, this.domNode, this._overflowGuardContainer);
this._viewParts.push(this._scrollbar);

Expand Down Expand Up @@ -268,7 +269,17 @@ export class View extends ViewEventHandler {
}

private _instantiateEditContext(experimentalEditContextEnabled: boolean): AbstractEditContext {
return this._instantiationService.createInstance(experimentalEditContextEnabled ? NativeEditContext : TextAreaEditContext, this._context, this._viewController, this._createTextAreaHandlerHelper());
if (experimentalEditContextEnabled) {
const ownerWindow = dom.getWindow(this.domNode.domNode);
const document = ownerWindow.document;
console.log('this.domNode.domNode : ', this.domNode.domNode);
console.log('this._overflowGuardContainer : ', this._overflowGuardContainer);
console.log('ownerWindow : ', ownerWindow);
console.log('document : ', document);
return this._instantiationService.createInstance(NativeEditContext, this._context, ownerWindow, this._viewController, this._createTextAreaHandlerHelper());
} else {
return this._instantiationService.createInstance(TextAreaEditContext, this._context, this._viewController, this._createTextAreaHandlerHelper());
}
}

private _updateEditContext(): void {
Expand Down
Loading