Skip to content

Commit

Permalink
Feat: exposing getter setter for widget manager created using line wi…
Browse files Browse the repository at this point in the history
…dgets (#5673)


* Feat: exposing getter setter for widget manager from edit_session created using line widgets
  • Loading branch information
nlujjawal authored Nov 14, 2024
1 parent 5e1e524 commit f5d0c19
Show file tree
Hide file tree
Showing 6 changed files with 66 additions and 27 deletions.
16 changes: 9 additions & 7 deletions ace-internal.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
24 changes: 23 additions & 1 deletion ace.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -513,7 +513,7 @@ export namespace Ace {
name?: string;
};
};

widgetManager:WidgetManager;
// TODO: define BackgroundTokenizer

on(name: 'changeFold',
Expand Down Expand Up @@ -1107,6 +1107,28 @@ 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;
}
}


Expand Down
32 changes: 32 additions & 0 deletions src/edit_session.js
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand All @@ -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;
Expand Down Expand Up @@ -45,6 +47,7 @@ class EditSession {
this.$backMarkers = {};
this.$markerId = 1;
this.$undoSelect = true;
this.$editor = null;
this.prevOp = {};

/** @type {FoldLine[]} */
Expand Down Expand Up @@ -187,6 +190,35 @@ class EditSession {
return this.doc;
}

/**
* Get "widgetManager" from EditSession
*
* @returns {LineWidgets} object
*/
get widgetManager() {
const widgetManager = new LineWidgets(this);
// todo remove the widgetManger assignement from lineWidgets constructor when introducing breaking changes
this.widgetManager = widgetManager;

if (this.$editor)
widgetManager.attach(this.$editor);

return widgetManager;
}

/**
* Set "widgetManager" in EditSession
*
* @returns void
*/
set widgetManager(value) {
Object.defineProperty(this, "widgetManager", {
writable: true,
enumerable: true,
configurable: true,
value: value,
});
}
/**
* @param {Number} docRow The row to work with
*
Expand Down
9 changes: 2 additions & 7 deletions src/editor.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -357,7 +356,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();
Expand Down Expand Up @@ -1486,19 +1487,13 @@ 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);
}

/**
* Removes "ghost" text currently displayed in the editor.
*/
removeGhostText() {
if (!this.session.widgetManager) return;

this.renderer.removeGhostText();
}

Expand Down
6 changes: 0 additions & 6 deletions src/ext/code_lens.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
* @typedef {import("../virtual_renderer").VirtualRenderer & {$textLayer: import("../layer/text").Text &{$lenses: any}}} VirtualRenderer
*/

var LineWidgets = require("../line_widgets").LineWidgets;
var event = require("../lib/event");
var lang = require("../lib/lang");
var dom = require("../lib/dom");
Expand Down Expand Up @@ -157,11 +156,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) {
Expand Down
6 changes: 0 additions & 6 deletions src/ext/error_marker.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
"use strict";
var LineWidgets = require("../line_widgets").LineWidgets;
var dom = require("../lib/dom");
var Range = require("../range").Range;
var nls = require("../config").nls;
Expand Down Expand Up @@ -70,11 +69,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) {
Expand Down

0 comments on commit f5d0c19

Please sign in to comment.