diff --git a/ace-internal.d.ts b/ace-internal.d.ts index 96d51a66eb..65783e456d 100644 --- a/ace-internal.d.ts +++ b/ace-internal.d.ts @@ -293,21 +293,23 @@ export namespace Ace { } interface LineWidget { - el: HTMLElement; - rowCount: number; - hidden: boolean; - _inDocument: boolean; + editor?: Editor, + el?: HTMLElement; + rowCount?: number; + hidden?: boolean; + _inDocument?: boolean; column?: number; - row?: number; + row: number; $oldWidget?: LineWidget, - session: EditSession, + session?: EditSession, html?: string, text?: string, className?: string, coverGutter?: boolean, pixelHeight?: number, $fold?: Fold, - editor: Editor, + type?:any, + destroy?:()=>void; coverLine?: boolean, fixedWidth?: boolean, fullWidth?: boolean, diff --git a/ace.d.ts b/ace.d.ts index 88560068eb..d9a3f5c672 100644 --- a/ace.d.ts +++ b/ace.d.ts @@ -513,7 +513,7 @@ export namespace Ace { name?: string; }; }; - + widgetManager:WidgetManager; // TODO: define BackgroundTokenizer on(name: 'changeFold', @@ -1107,6 +1107,26 @@ export namespace Ace { tryShow(pos: Point, lineHeight: number, anchor: "top" | "bottom" | undefined, forceShow?: boolean): boolean; goTo(where: AcePopupNavigation): void; } + export interface LineWidget { + el: HTMLElement; + row: number; + rowCount?: number; + hidden: boolean; + editor: Editor, + session: EditSession, + column?: number; + className?: string, + coverGutter?: boolean, + pixelHeight?: number, + fixedWidth?: boolean, + fullWidth?: boolean, + screenWidth?: number, +} + export class WidgetManager { + constructor(session: EditSession); + addLineWidget(w: LineWidget): LineWidget; + removeLineWidget(w: LineWidget): void; + } } diff --git a/build b/build index af770649d7..68e4d6e6a9 160000 --- a/build +++ b/build @@ -1 +1 @@ -Subproject commit af770649d71c0604f21cd972f23f5ab9d99702bc +Subproject commit 68e4d6e6a9b867c20927bcc31e39330e3f94bc7d diff --git a/src/edit_session.js b/src/edit_session.js index 7fef86d933..b706acaf41 100644 --- a/src/edit_session.js +++ b/src/edit_session.js @@ -6,6 +6,7 @@ * @typedef {import("../ace-internal").Ace.Delta} Delta * @typedef {import("../ace-internal").Ace.IRange} IRange * @typedef {import("../ace-internal").Ace.SyntaxMode} SyntaxMode + * @typedef {import("../ace-internal").Ace.LineWidget} LineWidget */ var oop = require("./lib/oop"); @@ -16,6 +17,7 @@ var EventEmitter = require("./lib/event_emitter").EventEmitter; var Selection = require("./selection").Selection; var TextMode = require("./mode/text").Mode; var Range = require("./range").Range; +var LineWidgets = require("./line_widgets").LineWidgets; var Document = require("./document").Document; var BackgroundTokenizer = require("./background_tokenizer").BackgroundTokenizer; var SearchHighlight = require("./search_highlight").SearchHighlight; @@ -45,7 +47,9 @@ class EditSession { this.$backMarkers = {}; this.$markerId = 1; this.$undoSelect = true; + this.$editor = null; this.prevOp = {}; + this.$widgetManager =null; /** @type {FoldLine[]} */ this.$foldData = []; @@ -186,7 +190,33 @@ class EditSession { getDocument() { return this.doc; } - + /** + * Get "widgetManager" from editor.session + * + * @returns {LineWidgets} object + */ + get widgetManager() { + if(!this.$widgetManager){ + this.$widgetManager = new LineWidgets(this); + + if (this.$editor) + this.$widgetManager.attach(this.$editor); + } + return this.$widgetManager; + } + /** + * Set "widgetManager" in editor.session + * @returns void + */ + set widgetManager(value) { + Object.defineProperty(this, "widgetManager", { + writable: true, + enumerable: true, + configurable: true, + value: value, + }); + this.$widgetManager = value; + } /** * @param {Number} docRow The row to work with * diff --git a/src/editor.js b/src/editor.js index 2ad6199af4..93e842b3a5 100644 --- a/src/editor.js +++ b/src/editor.js @@ -357,7 +357,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(); @@ -1486,10 +1488,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); } @@ -1497,11 +1495,10 @@ class Editor { * Removes "ghost" text currently displayed in the editor. */ removeGhostText() { - if (!this.session.widgetManager) return; - this.renderer.removeGhostText(); } + /** * Transposes current line. **/ diff --git a/src/ext/code_lens.js b/src/ext/code_lens.js index 7098c1e998..faa15c3b28 100644 --- a/src/ext/code_lens.js +++ b/src/ext/code_lens.js @@ -157,11 +157,6 @@ function attachToEditor(editor) { var session = editor.session; if (!session) return; - if (!session.widgetManager) { - session.widgetManager = new LineWidgets(session); - session.widgetManager.attach(editor); - } - var providersToWaitNum = editor.codeLensProviders.length; var lenses = []; editor.codeLensProviders.forEach(function(provider) { diff --git a/src/ext/error_marker.js b/src/ext/error_marker.js index 1c4bc5aa7e..7ce798578c 100644 --- a/src/ext/error_marker.js +++ b/src/ext/error_marker.js @@ -70,11 +70,6 @@ function findAnnotations(session, row, dir) { */ exports.showErrorMarker = function(editor, dir) { var session = editor.session; - if (!session.widgetManager) { - session.widgetManager = new LineWidgets(session); - session.widgetManager.attach(editor); - } - var pos = editor.getCursorPosition(); var row = pos.row; var oldWidget = session.widgetManager.getWidgetsAtRow(row).filter(function(w) {