-
Notifications
You must be signed in to change notification settings - Fork 5.3k
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
Feat: exposing getter setter for widget manager created using line widgets #5673
Conversation
One of the public type files has been updated, plase make sure there are no backwards incompatible changes done in the PR. |
src/editor.js
Outdated
* Set "widgetManager" in editor.session | ||
* @returns void | ||
*/ | ||
setWidgetManager() { |
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.
calling this setWidgetManager
might lead to the assumption that it accepts a parameter which gets set, maybe something like attachWidgetManager
makes sense?
ace.d.ts
Outdated
@@ -953,6 +953,8 @@ export namespace Ace { | |||
splitLine(): void; | |||
setGhostText(text: string, position: Point): void; | |||
removeGhostText(): void; | |||
setWidgetManager(): void; |
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.
Do we need to expose this function? consumers will want to access the widget manager (which they can do through getWidgetManager
) and when it's not defined yet that will be handled by this getter. Do you see an use-case where someone wants to attach a widget manager but not use it afterwards?
ace.d.ts
Outdated
@@ -953,6 +953,8 @@ export namespace Ace { | |||
splitLine(): void; | |||
setGhostText(text: string, position: Point): void; | |||
removeGhostText(): void; | |||
setWidgetManager(): void; | |||
getWidgetManager(): Ace.LineWidgets; |
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.
Ace.LineWidgets
is only exported from the internal type declaration file at the moment right? we should include it in this declaration file as well if we're exposing this function. (this is probably also what's breaking the CI build atm)
We also use the widget manager for the ghost text here, does it make sense to convert this instance as well to the new functions? |
The reason widgetManager was not defined here, was that initially we wanted to keep lineWidgets as an optional feature that could be excluded from the bundle. Since we have added import of lineWidgets to the editor itself, i'd suggest to convert session.widgetManager to a getter, so that diff --git a/src/edit_session.js b/src/edit_session.js
index 718105762..af93087e5 100644
--- a/src/edit_session.js
+++ b/src/edit_session.js
@@ -12,6 +12,7 @@ var oop = require("./lib/oop");
var lang = require("./lib/lang");
var BidiHandler = require("./bidihandler").BidiHandler;
var config = require("./config");
+var { LineWidgets } = require("./line_widgets");
var EventEmitter = require("./lib/event_emitter").EventEmitter;
var Selection = require("./selection").Selection;
var TextMode = require("./mode/text").Mode;
@@ -2386,6 +2387,23 @@ class EditSession {
return currentLine[pos.column - 1];
}
+ get widgetManager() {
+ var widgetManager = new LineWidgets(this);
+
+ if (this.$editor)
+ widgetManager.attach(this.$editor);
+
+ return widgetManager;
+ }
+ set widgetManager(value) {
+ Object.defineProperty(this, "widgetManager", {
+ writable: true,
+ enumerable: true,
+ configurable: true,
+ value: value,
+ });
+ }
+
destroy() {
if (!this.destroyed) {
this.bgTokenizer.setDocument(null);
diff --git a/src/editor.js b/src/editor.js
index c9d2bf7a6..c9df18860 100644
--- a/src/editor.js
+++ b/src/editor.js
@@ -23,7 +23,6 @@ var CommandManager = require("./commands/command_manager").CommandManager;
var defaultCommands = require("./commands/default_commands").commands;
var config = require("./config");
var TokenIterator = require("./token_iterator").TokenIterator;
-var LineWidgets = require("./line_widgets").LineWidgets;
var GutterKeyboardHandler = require("./keyboard/gutter_handler").GutterKeyboardHandler;
var nls = require("./config").nls;
@@ -372,7 +371,9 @@ class Editor {
this.curOp = null;
oldSession && oldSession._signal("changeEditor", {oldEditor: this});
+ if (oldSession) oldSession.$editor = null;
session && session._signal("changeEditor", {editor: this});
+ if (session) session.$editor = this;
if (session && !session.destroyed)
session.bgTokenizer.scheduleStart();
@@ -1502,10 +1503,6 @@ class Editor {
* @param {Point} [position] Position to insert text to
*/
setGhostText(text, position) {
- if (!this.session.widgetManager) {
- this.session.widgetManager = new LineWidgets(this.session);
- this.session.widgetManager.attach(this);
- }
this.renderer.setGhostText(text, position);
}
@@ -1513,8 +1510,6 @@ class Editor {
* Removes "ghost" text currently displayed in the editor.
*/
removeGhostText() {
- if (!this.session.widgetManager) return;
-
this.renderer.removeGhostText();
}
|
ec97825
to
c381585
Compare
One of the public type files has been updated, plase make sure there are no backwards incompatible changes done in the PR. |
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## master #5673 +/- ##
==========================================
- Coverage 87.01% 87.01% -0.01%
==========================================
Files 598 598
Lines 43681 43680 -1
Branches 7205 7204 -1
==========================================
- Hits 38010 38009 -1
Misses 5671 5671
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. |
c381585
to
52436cd
Compare
One of the public type files has been updated, plase make sure there are no backwards incompatible changes done in the PR. |
52436cd
to
f0bed9b
Compare
One of the public type files has been updated, plase make sure there are no backwards incompatible changes done in the PR. |
f0bed9b
to
c08b103
Compare
One of the public type files has been updated, plase make sure there are no backwards incompatible changes done in the PR. |
c08b103
to
fdc468c
Compare
One of the public type files has been updated, plase make sure there are no backwards incompatible changes done in the PR. |
…ated using line widgets
One of the public type files has been updated, plase make sure there are no backwards incompatible changes done in the PR. |
* @returns {LineWidgets} object | ||
*/ | ||
get widgetManager() { | ||
const widgetManager = new LineWidgets(this); |
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.
how does this work when both consumers want to use editor.widgetManager
and we want to use it internally? Doesn't this mean that when a consumer calls the widgetManager all the existing widgets currently in the editor get deleted?
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.
nice catch. Will be adding the check to only create widgetManager if it doesn't exists.
One of the public type files has been updated, plase make sure there are no backwards incompatible changes done in the PR. |
/** | ||
* Get "widgetManager" from EditSession | ||
* | ||
* @returns {LineWidgets} object |
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.
This gives session.widgetManager
the LineWidgets
type, which I think means that session.widgetManager.addLineWidget(...)
will result in a typescript error right? Should this return type be WidgetManager
?
One of the public type files has been updated, plase make sure there are no backwards incompatible changes done in the PR. |
Description of changes:
Exposing getter and setter for widget manager created using line widgets.
So now ace consumers can use the getter to access the widgetManager which can be used to create line widgets.
setWidgetManager
andgetWidgetManager
methods in Editor type.By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.
Pull Request Checklist:
ace.d.ts
) and its references: