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
  • Loading branch information
nlujjawal committed Nov 13, 2024
1 parent 74e95d1 commit c381585
Show file tree
Hide file tree
Showing 7 changed files with 65 additions and 26 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
22 changes: 21 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,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;
}
}


Expand Down
2 changes: 1 addition & 1 deletion build
Submodule build updated 46 files
+0 −21 CHANGELOG.md
+0 −2 ace-modules.d.ts
+1 −10 ace.d.ts
+19 −20 demo/kitchen-sink/demo.js
+0 −43 demo/kitchen-sink/docs/basic.bas
+0 −2 esm-resolver.js
+1 −1 package.json
+1 −1 src-min-noconflict/ace.js
+1 −1 src-min-noconflict/ext-inline_autocomplete.js
+1 −1 src-min-noconflict/ext-language_tools.js
+1 −1 src-min-noconflict/ext-modelist.js
+1 −1 src-min-noconflict/ext-options.js
+1 −1 src-min-noconflict/ext-prompt.js
+1 −1 src-min-noconflict/ext-settings_menu.js
+0 −8 src-min-noconflict/mode-basic.js
+0 −8 src-min-noconflict/snippets/basic.js
+1 −1 src-min/ace.js
+1 −1 src-min/ext-inline_autocomplete.js
+1 −1 src-min/ext-language_tools.js
+1 −1 src-min/ext-modelist.js
+1 −1 src-min/ext-options.js
+1 −1 src-min/ext-prompt.js
+1 −1 src-min/ext-settings_menu.js
+0 −8 src-min/mode-basic.js
+0 −8 src-min/snippets/basic.js
+50 −109 src-noconflict/ace.js
+19 −19 src-noconflict/ext-inline_autocomplete.js
+19 −19 src-noconflict/ext-language_tools.js
+0 −1 src-noconflict/ext-modelist.js
+0 −1 src-noconflict/ext-options.js
+19 −20 src-noconflict/ext-prompt.js
+0 −1 src-noconflict/ext-settings_menu.js
+1 −1 src-noconflict/ext-static_highlight.js
+0 −201 src-noconflict/mode-basic.js
+0 −9 src-noconflict/snippets/basic.js
+50 −109 src/ace.js
+19 −19 src/ext-inline_autocomplete.js
+19 −19 src/ext-language_tools.js
+0 −1 src/ext-modelist.js
+0 −1 src/ext-options.js
+19 −20 src/ext-prompt.js
+0 −1 src/ext-settings_menu.js
+1 −1 src/ext-static_highlight.js
+0 −201 src/mode-basic.js
+0 −9 src/snippets/basic.js
+0 −2 webpack-resolver.js
32 changes: 31 additions & 1 deletion 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,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 = [];
Expand Down Expand Up @@ -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
*
Expand Down
9 changes: 3 additions & 6 deletions src/editor.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -1486,22 +1488,17 @@ 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();
}


/**
* Transposes current line.
**/
Expand Down
5 changes: 0 additions & 5 deletions src/ext/code_lens.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
5 changes: 0 additions & 5 deletions src/ext/error_marker.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down

0 comments on commit c381585

Please sign in to comment.