@jupyterlab/codeeditor 0.17.2 → 0.18.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/lib/editor.d.ts CHANGED
@@ -98,6 +98,23 @@ export declare namespace CodeEditor {
98
98
  */
99
99
  readonly style: ISelectionStyle;
100
100
  }
101
+ /**
102
+ * An interface for a text token, such as a word, keyword, or variable.
103
+ */
104
+ interface IToken {
105
+ /**
106
+ * The value of the token.
107
+ */
108
+ value: string;
109
+ /**
110
+ * The offset of the token in the code editor.
111
+ */
112
+ offset: number;
113
+ /**
114
+ * An optional type for the token.
115
+ */
116
+ type?: string;
117
+ }
101
118
  /**
102
119
  * An interface to manage selections by selection owners.
103
120
  *
@@ -401,6 +418,14 @@ export declare namespace CodeEditor {
401
418
  * Inserts a new line at the cursor position and indents it.
402
419
  */
403
420
  newIndentedLine(): void;
421
+ /**
422
+ * Gets the token at a given position.
423
+ */
424
+ getTokenForPosition(position: IPosition): IToken;
425
+ /**
426
+ * Gets the list of tokens for the editor model.
427
+ */
428
+ getTokens(): IToken[];
404
429
  }
405
430
  /**
406
431
  * A factory used to create a code editor.
package/lib/editor.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"editor.js","sourceRoot":"","sources":["../../../../codeeditor/src/editor.ts"],"names":[],"mappings":";AAAA,0CAA0C;AAC1C,2DAA2D;;AAM3D,mDAAsD;AAItD,yDAOiC;AAEjC;;;;;;;GAOG;AACH,IAAiB,UAAU,CAqoB1B;AAroBD,WAAiB,UAAU;IA+EzB;;OAEG;IACU,gCAAqB,GAAoB;QACpD,SAAS,EAAE,EAAE;QACb,WAAW,EAAE,EAAE;QACf,KAAK,EAAE,OAAO;KACf,CAAC;IAoEF;;OAEG;IACH;QACE;;WAEG;QACH,YAAY,OAAwB;YAyF5B,gBAAW,GAAG,KAAK,CAAC;YACpB,qBAAgB,GAAG,IAAI,kBAAM,CAA6B,IAAI,CAAC,CAAC;YAzFtE,OAAO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ACD,IAAI,CAAC,OAAO,CAAC,QAAQ,CAAC,UAAU,EAAE,QAAQ,CAAC,CAAC;QAC9C,CAAC;QAED;;WAEG;QACH,IAAI,UAAU;YACZ,OAAO,IAAI,CAAC,WAAW,CAAC;QAC1B,CAAC;QAED;;WAEG;QACH,OAAO;YACL,IAAI,IAAI,CAAC,WAAW,EAAE;gBACpB,OAAO;aACR;YACD,IAAI,CAAC,WAAW,GAAG,IAAI,CAAC;YACxB,kBAAM,CAAC,SAAS,CAAC,IAAI,CAAC,CAAC;QACzB,CAAC;QAEO,kBAAkB,CACxB,QAA0B,EAC1B,IAAkC;YAElC,IAAI,CAAC,gBAAgB,CAAC,IAAI,CAAC;gBACzB,IAAI,EAAE,UAAU;gBAChB,QAAQ,EAAE,IAAI,CAAC,QAAkB;gBACjC,QAAQ,EAAE,IAAI,CAAC,QAAkB;aAClC,CAAC,CAAC;QACL,CAAC;KAIF;IA/FY,gBAAK,QA+FjB,CAAA;IAwUD;;OAEG;IACQ,wBAAa,GAAY;QAClC,UAAU,EAAE,IAAI;QAChB,QAAQ,EAAE,IAAI;QACd,UAAU,EAAE,IAAI;QAChB,WAAW,EAAE,KAAK;QAClB,QAAQ,EAAE,IAAI;QACd,cAAc,EAAE,EAAE;QAClB,QAAQ,EAAE,KAAK;QACf,OAAO,EAAE,CAAC;QACV,YAAY,EAAE,IAAI;QAClB,aAAa,EAAE,IAAI;QACnB,mBAAmB,EAAE,IAAI;KAC1B,CAAC;AAkDJ,CAAC,EAroBgB,UAAU,GAAV,kBAAU,KAAV,kBAAU,QAqoB1B","sourcesContent":["// Copyright (c) Jupyter Development Team.\n// Distributed under the terms of the Modified BSD License.\n\nimport { JSONObject } from '@phosphor/coreutils';\n\nimport { IDisposable } from '@phosphor/disposable';\n\nimport { ISignal, Signal } from '@phosphor/signaling';\n\nimport { IChangedArgs } from '@jupyterlab/coreutils';\n\nimport {\n IModelDB,\n ModelDB,\n IObservableValue,\n ObservableValue,\n IObservableMap,\n IObservableString\n} from '@jupyterlab/observables';\n\n/**\n * A namespace for code editors.\n *\n * #### Notes\n * - A code editor is a set of common assumptions which hold for all concrete editors.\n * - Changes in implementations of the code editor should only be caused by changes in concrete editors.\n * - Common JLab services which are based on the code editor should belong to `IEditorServices`.\n */\nexport namespace CodeEditor {\n /**\n * A zero-based position in the editor.\n */\n export interface IPosition extends JSONObject {\n /**\n * The cursor line number.\n */\n readonly line: number;\n\n /**\n * The cursor column number.\n */\n readonly column: number;\n }\n\n /**\n * The dimension of an element.\n */\n export interface IDimension {\n /**\n * The width of an element in pixels.\n */\n readonly width: number;\n\n /**\n * The height of an element in pixels.\n */\n readonly height: number;\n }\n\n /**\n * An interface describing editor state coordinates.\n */\n export interface ICoordinate extends JSONObject, ClientRect {}\n\n /**\n * A range.\n */\n export interface IRange extends JSONObject {\n /**\n * The position of the first character in the current range.\n *\n * #### Notes\n * If this position is greater than [end] then the range is considered\n * to be backward.\n */\n readonly start: IPosition;\n\n /**\n * The position of the last character in the current range.\n *\n * #### Notes\n * If this position is less than [start] then the range is considered\n * to be backward.\n */\n readonly end: IPosition;\n }\n\n /**\n * A selection style.\n */\n export interface ISelectionStyle extends JSONObject {\n /**\n * A class name added to a selection.\n */\n className: string;\n\n /**\n * A display name added to a selection.\n */\n displayName: string;\n\n /**\n * A color for UI elements.\n */\n color: string;\n }\n\n /**\n * The default selection style.\n */\n export const defaultSelectionStyle: ISelectionStyle = {\n className: '',\n displayName: '',\n color: 'black'\n };\n\n /**\n * A text selection.\n */\n export interface ITextSelection extends IRange {\n /**\n * The uuid of the text selection owner.\n */\n readonly uuid: string;\n\n /**\n * The style of this selection.\n */\n readonly style: ISelectionStyle;\n }\n\n /**\n * An interface to manage selections by selection owners.\n *\n * #### Definitions\n * - a user code that has an associated uuid is called a selection owner, see `CodeEditor.ISelectionOwner`\n * - a selection belongs to a selection owner only if it is associated with the owner by an uuid, see `CodeEditor.ITextSelection`\n *\n * #### Read access\n * - any user code can observe any selection\n *\n * #### Write access\n * - if a user code is a selection owner then:\n * - it can change selections belonging to it\n * - but it must not change selections belonging to other selection owners\n * - otherwise it must not change any selection\n */\n\n /**\n * An editor model.\n */\n export interface IModel extends IDisposable {\n /**\n * A signal emitted when a property changes.\n */\n mimeTypeChanged: ISignal<IModel, IChangedArgs<string>>;\n\n /**\n * The text stored in the model.\n */\n readonly value: IObservableString;\n\n /**\n * A mime type of the model.\n *\n * #### Notes\n * It is never `null`, the default mime type is `text/plain`.\n */\n mimeType: string;\n\n /**\n * The currently selected code.\n */\n readonly selections: IObservableMap<ITextSelection[]>;\n\n /**\n * The underlying `IModelDB` instance in which model\n * data is stored.\n */\n readonly modelDB: IModelDB;\n }\n\n /**\n * The default implementation of the editor model.\n */\n export class Model implements IModel {\n /**\n * Construct a new Model.\n */\n constructor(options?: Model.IOptions) {\n options = options || {};\n\n if (options.modelDB) {\n this.modelDB = options.modelDB;\n } else {\n this.modelDB = new ModelDB();\n }\n\n let value = this.modelDB.createString('value');\n value.text = value.text || options.value || '';\n\n let mimeType = this.modelDB.createValue('mimeType');\n mimeType.set(options.mimeType || 'text/plain');\n mimeType.changed.connect(this._onMimeTypeChanged, this);\n\n this.modelDB.createMap('selections');\n }\n\n /**\n * The underlying `IModelDB` instance in which model\n * data is stored.\n */\n readonly modelDB: IModelDB;\n\n /**\n * A signal emitted when a mimetype changes.\n */\n get mimeTypeChanged(): ISignal<this, IChangedArgs<string>> {\n return this._mimeTypeChanged;\n }\n\n /**\n * Get the value of the model.\n */\n get value(): IObservableString {\n return this.modelDB.get('value') as IObservableString;\n }\n\n /**\n * Get the selections for the model.\n */\n get selections(): IObservableMap<ITextSelection[]> {\n return this.modelDB.get('selections') as IObservableMap<ITextSelection[]>;\n }\n\n /**\n * A mime type of the model.\n */\n get mimeType(): string {\n return this.modelDB.getValue('mimeType') as string;\n }\n set mimeType(newValue: string) {\n const oldValue = this.mimeType;\n if (oldValue === newValue) {\n return;\n }\n this.modelDB.setValue('mimeType', newValue);\n }\n\n /**\n * Whether the model is disposed.\n */\n get isDisposed(): boolean {\n return this._isDisposed;\n }\n\n /**\n * Dispose of the resources used by the model.\n */\n dispose(): void {\n if (this._isDisposed) {\n return;\n }\n this._isDisposed = true;\n Signal.clearData(this);\n }\n\n private _onMimeTypeChanged(\n mimeType: IObservableValue,\n args: ObservableValue.IChangedArgs\n ): void {\n this._mimeTypeChanged.emit({\n name: 'mimeType',\n oldValue: args.oldValue as string,\n newValue: args.newValue as string\n });\n }\n\n private _isDisposed = false;\n private _mimeTypeChanged = new Signal<this, IChangedArgs<string>>(this);\n }\n\n /**\n * A selection owner.\n */\n export interface ISelectionOwner {\n /**\n * The uuid of this selection owner.\n */\n uuid: string;\n\n /**\n * Returns the primary position of the cursor, never `null`.\n */\n getCursorPosition(): IPosition;\n\n /**\n * Set the primary position of the cursor.\n *\n * @param position - The new primary position.\n *\n * #### Notes\n * This will remove any secondary cursors.\n */\n setCursorPosition(position: IPosition): void;\n\n /**\n * Returns the primary selection, never `null`.\n */\n getSelection(): IRange;\n\n /**\n * Set the primary selection.\n *\n * @param selection - The desired selection range.\n *\n * #### Notes\n * This will remove any secondary cursors.\n */\n setSelection(selection: IRange): void;\n\n /**\n * Gets the selections for all the cursors, never `null` or empty.\n */\n getSelections(): IRange[];\n\n /**\n * Sets the selections for all the cursors.\n *\n * @param selections - The new selections.\n *\n * #### Notes\n * Cursors will be removed or added, as necessary.\n * Passing an empty array resets a cursor position to the start of a\n * document.\n */\n setSelections(selections: IRange[]): void;\n }\n\n /**\n * A keydown handler type.\n *\n * #### Notes\n * Return `true` to prevent the default handling of the event by the\n * editor.\n */\n export type KeydownHandler = (\n instance: IEditor,\n event: KeyboardEvent\n ) => boolean;\n\n /**\n * The location of requested edges.\n */\n export type EdgeLocation = 'top' | 'bottom';\n\n /**\n * A widget that provides a code editor.\n */\n export interface IEditor extends ISelectionOwner, IDisposable {\n /**\n * A signal emitted when either the top or bottom edge is requested.\n */\n readonly edgeRequested: ISignal<IEditor, EdgeLocation>;\n\n /**\n * The default selection style for the editor.\n */\n selectionStyle: CodeEditor.ISelectionStyle;\n\n /**\n * The DOM node that hosts the editor.\n */\n readonly host: HTMLElement;\n\n /**\n * The model used by the editor.\n */\n readonly model: IModel;\n\n /**\n * The height of a line in the editor in pixels.\n */\n readonly lineHeight: number;\n\n /**\n * The widget of a character in the editor in pixels.\n */\n readonly charWidth: number;\n\n /**\n * Get the number of lines in the eidtor.\n */\n readonly lineCount: number;\n\n /**\n * Get a config option for the editor.\n */\n getOption<K extends keyof IConfig>(option: K): IConfig[K];\n\n /**\n * Set a config option for the editor.\n */\n setOption<K extends keyof IConfig>(option: K, value: IConfig[K]): void;\n\n /**\n * Returns the content for the given line number.\n *\n * @param line - The line of interest.\n *\n * @returns The value of the line.\n *\n * #### Notes\n * Lines are 0-based, and accessing a line out of range returns\n * `undefined`.\n */\n getLine(line: number): string | undefined;\n\n /**\n * Find an offset for the given position.\n *\n * @param position - The position of interest.\n *\n * @returns The offset at the position, clamped to the extent of the\n * editor contents.\n */\n getOffsetAt(position: IPosition): number;\n\n /**\n * Find a position for the given offset.\n *\n * @param offset - The offset of interest.\n *\n * @returns The position at the offset, clamped to the extent of the\n * editor contents.\n */\n getPositionAt(offset: number): IPosition | undefined;\n\n /**\n * Undo one edit (if any undo events are stored).\n */\n undo(): void;\n\n /**\n * Redo one undone edit.\n */\n redo(): void;\n\n /**\n * Clear the undo history.\n */\n clearHistory(): void;\n\n /**\n * Brings browser focus to this editor text.\n */\n focus(): void;\n\n /**\n * Test whether the editor has keyboard focus.\n */\n hasFocus(): boolean;\n\n /**\n * Explicitly blur the editor.\n */\n blur(): void;\n\n /**\n * Repaint the editor.\n *\n * #### Notes\n * A repainted editor should fit to its host node.\n */\n refresh(): void;\n\n /**\n * Resize the editor to fit its host node.\n */\n resizeToFit(): void;\n\n /**\n * Add a keydown handler to the editor.\n *\n * @param handler - A keydown handler.\n *\n * @returns A disposable that can be used to remove the handler.\n */\n addKeydownHandler(handler: KeydownHandler): IDisposable;\n\n /**\n * Set the size of the editor.\n *\n * @param size - The desired size.\n *\n * #### Notes\n * Use `null` if the size is unknown.\n */\n setSize(size: IDimension | null): void;\n\n /**\n * Reveals the given position in the editor.\n *\n * @param position - The desired position to reveal.\n */\n revealPosition(position: IPosition): void;\n\n /**\n * Reveals the given selection in the editor.\n *\n * @param position - The desired selection to reveal.\n */\n revealSelection(selection: IRange): void;\n\n /**\n * Get the window coordinates given a cursor position.\n *\n * @param position - The desired position.\n *\n * @returns The coordinates of the position.\n */\n getCoordinateForPosition(position: IPosition): ICoordinate;\n\n /**\n * Get the cursor position given window coordinates.\n *\n * @param coordinate - The desired coordinate.\n *\n * @returns The position of the coordinates, or null if not\n * contained in the editor.\n */\n getPositionForCoordinate(coordinate: ICoordinate): IPosition | null;\n\n /**\n * Inserts a new line at the cursor position and indents it.\n */\n newIndentedLine(): void;\n }\n\n /**\n * A factory used to create a code editor.\n */\n export type Factory = (options: IOptions) => CodeEditor.IEditor;\n\n /**\n * The configuration options for an editor.\n */\n export interface IConfig {\n /**\n * User preferred font family for text editors.\n */\n fontFamily: string | null;\n\n /**\n * User preferred size in pixel of the font used in text editors.\n */\n fontSize: number | null;\n\n /**\n * User preferred text line height, as a multiplier of font size.\n */\n lineHeight: number | null;\n\n /**\n * Whether line numbers should be displayed.\n */\n lineNumbers: boolean;\n\n /**\n * Control the line wrapping of the editor. Possible values are:\n * - \"off\", lines will never wrap.\n * - \"on\", lines will wrap at the viewport border.\n * - \"wordWrapColumn\", lines will wrap at `wordWrapColumn`.\n * - \"bounded\", lines will wrap at minimum between viewport width and wordWrapColumn.\n */\n lineWrap: 'off' | 'on' | 'wordWrapColumn' | 'bounded';\n\n /**\n * Whether the editor is read-only.\n */\n readOnly: boolean;\n\n /**\n * The number of spaces a tab is equal to.\n */\n tabSize: number;\n\n /**\n * Whether to insert spaces when pressing Tab.\n */\n insertSpaces: boolean;\n\n /**\n * Whether to highlight matching brackets when one of them is selected.\n */\n matchBrackets: boolean;\n\n /**\n * Whether to automatically close brackets after opening them.\n */\n autoClosingBrackets: boolean;\n\n /**\n * The column where to break text line.\n */\n wordWrapColumn: number;\n }\n\n /**\n * The default configuration options for an editor.\n */\n export let defaultConfig: IConfig = {\n fontFamily: null,\n fontSize: null,\n lineHeight: null,\n lineNumbers: false,\n lineWrap: 'on',\n wordWrapColumn: 80,\n readOnly: false,\n tabSize: 4,\n insertSpaces: true,\n matchBrackets: true,\n autoClosingBrackets: true\n };\n\n /**\n * The options used to initialize an editor.\n */\n export interface IOptions {\n /**\n * The host widget used by the editor.\n */\n host: HTMLElement;\n\n /**\n * The model used by the editor.\n */\n model: IModel;\n\n /**\n * The desired uuid for the editor.\n */\n uuid?: string;\n\n /**\n * The default selection style for the editor.\n */\n selectionStyle?: Partial<CodeEditor.ISelectionStyle>;\n\n /**\n * The configuration options for the editor.\n */\n config?: Partial<IConfig>;\n }\n\n export namespace Model {\n export interface IOptions {\n /**\n * The initial value of the model.\n */\n value?: string;\n\n /**\n * The mimetype of the model.\n */\n mimeType?: string;\n\n /**\n * An optional modelDB for storing model state.\n */\n modelDB?: IModelDB;\n }\n }\n}\n"]}
1
+ {"version":3,"file":"editor.js","sourceRoot":"","sources":["../../../../codeeditor/src/editor.ts"],"names":[],"mappings":";AAAA,0CAA0C;AAC1C,2DAA2D;;AAM3D,mDAAsD;AAItD,yDAOiC;AAEjC;;;;;;;GAOG;AACH,IAAiB,UAAU,CAmqB1B;AAnqBD,WAAiB,UAAU;IA+EzB;;OAEG;IACU,gCAAqB,GAAoB;QACpD,SAAS,EAAE,EAAE;QACb,WAAW,EAAE,EAAE;QACf,KAAK,EAAE,OAAO;KACf,CAAC;IAwFF;;OAEG;IACH;QACE;;WAEG;QACH,YAAY,OAAwB;YAyF5B,gBAAW,GAAG,KAAK,CAAC;YACpB,qBAAgB,GAAG,IAAI,kBAAM,CAA6B,IAAI,CAAC,CAAC;YAzFtE,OAAO,GAAG,OAAO,IAAI,EAAE,CAAC;YAExB,IAAI,OAAO,CAAC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AAQ,CAAC,CAAC;QAC9C,CAAC;QAED;;WAEG;QACH,IAAI,UAAU;YACZ,OAAO,IAAI,CAAC,WAAW,CAAC;QAC1B,CAAC;QAED;;WAEG;QACH,OAAO;YACL,IAAI,IAAI,CAAC,WAAW,EAAE;gBACpB,OAAO;aACR;YACD,IAAI,CAAC,WAAW,GAAG,IAAI,CAAC;YACxB,kBAAM,CAAC,SAAS,CAAC,IAAI,CAAC,CAAC;QACzB,CAAC;QAEO,kBAAkB,CACxB,QAA0B,EAC1B,IAAkC;YAElC,IAAI,CAAC,gBAAgB,CAAC,IAAI,CAAC;gBACzB,IAAI,EAAE,UAAU;gBAChB,QAAQ,EAAE,IAAI,CAAC,QAAkB;gBACjC,QAAQ,EAAE,IAAI,CAAC,QAAkB;aAClC,CAAC,CAAC;QACL,CAAC;KAIF;IA/FY,gBAAK,QA+FjB,CAAA;IAkVD;;OAEG;IACQ,wBAAa,GAAY;QAClC,UAAU,EAAE,IAAI;QAChB,QAAQ,EAAE,IAAI;QACd,UAAU,EAAE,IAAI;QAChB,WAAW,EAAE,KAAK;QAClB,QAAQ,EAAE,IAAI;QACd,cAAc,EAAE,EAAE;QAClB,QAAQ,EAAE,KAAK;QACf,OAAO,EAAE,CAAC;QACV,YAAY,EAAE,IAAI;QAClB,aAAa,EAAE,IAAI;QACnB,mBAAmB,EAAE,IAAI;KAC1B,CAAC;AAkDJ,CAAC,EAnqBgB,UAAU,GAAV,kBAAU,KAAV,kBAAU,QAmqB1B","sourcesContent":["// Copyright (c) Jupyter Development Team.\n// Distributed under the terms of the Modified BSD License.\n\nimport { JSONObject } from '@phosphor/coreutils';\n\nimport { IDisposable } from '@phosphor/disposable';\n\nimport { ISignal, Signal } from '@phosphor/signaling';\n\nimport { IChangedArgs } from '@jupyterlab/coreutils';\n\nimport {\n IModelDB,\n ModelDB,\n IObservableValue,\n ObservableValue,\n IObservableMap,\n IObservableString\n} from '@jupyterlab/observables';\n\n/**\n * A namespace for code editors.\n *\n * #### Notes\n * - A code editor is a set of common assumptions which hold for all concrete editors.\n * - Changes in implementations of the code editor should only be caused by changes in concrete editors.\n * - Common JLab services which are based on the code editor should belong to `IEditorServices`.\n */\nexport namespace CodeEditor {\n /**\n * A zero-based position in the editor.\n */\n export interface IPosition extends JSONObject {\n /**\n * The cursor line number.\n */\n readonly line: number;\n\n /**\n * The cursor column number.\n */\n readonly column: number;\n }\n\n /**\n * The dimension of an element.\n */\n export interface IDimension {\n /**\n * The width of an element in pixels.\n */\n readonly width: number;\n\n /**\n * The height of an element in pixels.\n */\n readonly height: number;\n }\n\n /**\n * An interface describing editor state coordinates.\n */\n export interface ICoordinate extends JSONObject, ClientRect {}\n\n /**\n * A range.\n */\n export interface IRange extends JSONObject {\n /**\n * The position of the first character in the current range.\n *\n * #### Notes\n * If this position is greater than [end] then the range is considered\n * to be backward.\n */\n readonly start: IPosition;\n\n /**\n * The position of the last character in the current range.\n *\n * #### Notes\n * If this position is less than [start] then the range is considered\n * to be backward.\n */\n readonly end: IPosition;\n }\n\n /**\n * A selection style.\n */\n export interface ISelectionStyle extends JSONObject {\n /**\n * A class name added to a selection.\n */\n className: string;\n\n /**\n * A display name added to a selection.\n */\n displayName: string;\n\n /**\n * A color for UI elements.\n */\n color: string;\n }\n\n /**\n * The default selection style.\n */\n export const defaultSelectionStyle: ISelectionStyle = {\n className: '',\n displayName: '',\n color: 'black'\n };\n\n /**\n * A text selection.\n */\n export interface ITextSelection extends IRange {\n /**\n * The uuid of the text selection owner.\n */\n readonly uuid: string;\n\n /**\n * The style of this selection.\n */\n readonly style: ISelectionStyle;\n }\n\n /**\n * An interface for a text token, such as a word, keyword, or variable.\n */\n export interface IToken {\n /**\n * The value of the token.\n */\n value: string;\n\n /**\n * The offset of the token in the code editor.\n */\n offset: number;\n\n /**\n * An optional type for the token.\n */\n type?: string;\n }\n\n /**\n * An interface to manage selections by selection owners.\n *\n * #### Definitions\n * - a user code that has an associated uuid is called a selection owner, see `CodeEditor.ISelectionOwner`\n * - a selection belongs to a selection owner only if it is associated with the owner by an uuid, see `CodeEditor.ITextSelection`\n *\n * #### Read access\n * - any user code can observe any selection\n *\n * #### Write access\n * - if a user code is a selection owner then:\n * - it can change selections belonging to it\n * - but it must not change selections belonging to other selection owners\n * - otherwise it must not change any selection\n */\n\n /**\n * An editor model.\n */\n export interface IModel extends IDisposable {\n /**\n * A signal emitted when a property changes.\n */\n mimeTypeChanged: ISignal<IModel, IChangedArgs<string>>;\n\n /**\n * The text stored in the model.\n */\n readonly value: IObservableString;\n\n /**\n * A mime type of the model.\n *\n * #### Notes\n * It is never `null`, the default mime type is `text/plain`.\n */\n mimeType: string;\n\n /**\n * The currently selected code.\n */\n readonly selections: IObservableMap<ITextSelection[]>;\n\n /**\n * The underlying `IModelDB` instance in which model\n * data is stored.\n */\n readonly modelDB: IModelDB;\n }\n\n /**\n * The default implementation of the editor model.\n */\n export class Model implements IModel {\n /**\n * Construct a new Model.\n */\n constructor(options?: Model.IOptions) {\n options = options || {};\n\n if (options.modelDB) {\n this.modelDB = options.modelDB;\n } else {\n this.modelDB = new ModelDB();\n }\n\n let value = this.modelDB.createString('value');\n value.text = value.text || options.value || '';\n\n let mimeType = this.modelDB.createValue('mimeType');\n mimeType.set(options.mimeType || 'text/plain');\n mimeType.changed.connect(this._onMimeTypeChanged, this);\n\n this.modelDB.createMap('selections');\n }\n\n /**\n * The underlying `IModelDB` instance in which model\n * data is stored.\n */\n readonly modelDB: IModelDB;\n\n /**\n * A signal emitted when a mimetype changes.\n */\n get mimeTypeChanged(): ISignal<this, IChangedArgs<string>> {\n return this._mimeTypeChanged;\n }\n\n /**\n * Get the value of the model.\n */\n get value(): IObservableString {\n return this.modelDB.get('value') as IObservableString;\n }\n\n /**\n * Get the selections for the model.\n */\n get selections(): IObservableMap<ITextSelection[]> {\n return this.modelDB.get('selections') as IObservableMap<ITextSelection[]>;\n }\n\n /**\n * A mime type of the model.\n */\n get mimeType(): string {\n return this.modelDB.getValue('mimeType') as string;\n }\n set mimeType(newValue: string) {\n const oldValue = this.mimeType;\n if (oldValue === newValue) {\n return;\n }\n this.modelDB.setValue('mimeType', newValue);\n }\n\n /**\n * Whether the model is disposed.\n */\n get isDisposed(): boolean {\n return this._isDisposed;\n }\n\n /**\n * Dispose of the resources used by the model.\n */\n dispose(): void {\n if (this._isDisposed) {\n return;\n }\n this._isDisposed = true;\n Signal.clearData(this);\n }\n\n private _onMimeTypeChanged(\n mimeType: IObservableValue,\n args: ObservableValue.IChangedArgs\n ): void {\n this._mimeTypeChanged.emit({\n name: 'mimeType',\n oldValue: args.oldValue as string,\n newValue: args.newValue as string\n });\n }\n\n private _isDisposed = false;\n private _mimeTypeChanged = new Signal<this, IChangedArgs<string>>(this);\n }\n\n /**\n * A selection owner.\n */\n export interface ISelectionOwner {\n /**\n * The uuid of this selection owner.\n */\n uuid: string;\n\n /**\n * Returns the primary position of the cursor, never `null`.\n */\n getCursorPosition(): IPosition;\n\n /**\n * Set the primary position of the cursor.\n *\n * @param position - The new primary position.\n *\n * #### Notes\n * This will remove any secondary cursors.\n */\n setCursorPosition(position: IPosition): void;\n\n /**\n * Returns the primary selection, never `null`.\n */\n getSelection(): IRange;\n\n /**\n * Set the primary selection.\n *\n * @param selection - The desired selection range.\n *\n * #### Notes\n * This will remove any secondary cursors.\n */\n setSelection(selection: IRange): void;\n\n /**\n * Gets the selections for all the cursors, never `null` or empty.\n */\n getSelections(): IRange[];\n\n /**\n * Sets the selections for all the cursors.\n *\n * @param selections - The new selections.\n *\n * #### Notes\n * Cursors will be removed or added, as necessary.\n * Passing an empty array resets a cursor position to the start of a\n * document.\n */\n setSelections(selections: IRange[]): void;\n }\n\n /**\n * A keydown handler type.\n *\n * #### Notes\n * Return `true` to prevent the default handling of the event by the\n * editor.\n */\n export type KeydownHandler = (\n instance: IEditor,\n event: KeyboardEvent\n ) => boolean;\n\n /**\n * The location of requested edges.\n */\n export type EdgeLocation = 'top' | 'bottom';\n\n /**\n * A widget that provides a code editor.\n */\n export interface IEditor extends ISelectionOwner, IDisposable {\n /**\n * A signal emitted when either the top or bottom edge is requested.\n */\n readonly edgeRequested: ISignal<IEditor, EdgeLocation>;\n\n /**\n * The default selection style for the editor.\n */\n selectionStyle: CodeEditor.ISelectionStyle;\n\n /**\n * The DOM node that hosts the editor.\n */\n readonly host: HTMLElement;\n\n /**\n * The model used by the editor.\n */\n readonly model: IModel;\n\n /**\n * The height of a line in the editor in pixels.\n */\n readonly lineHeight: number;\n\n /**\n * The widget of a character in the editor in pixels.\n */\n readonly charWidth: number;\n\n /**\n * Get the number of lines in the eidtor.\n */\n readonly lineCount: number;\n\n /**\n * Get a config option for the editor.\n */\n getOption<K extends keyof IConfig>(option: K): IConfig[K];\n\n /**\n * Set a config option for the editor.\n */\n setOption<K extends keyof IConfig>(option: K, value: IConfig[K]): void;\n\n /**\n * Returns the content for the given line number.\n *\n * @param line - The line of interest.\n *\n * @returns The value of the line.\n *\n * #### Notes\n * Lines are 0-based, and accessing a line out of range returns\n * `undefined`.\n */\n getLine(line: number): string | undefined;\n\n /**\n * Find an offset for the given position.\n *\n * @param position - The position of interest.\n *\n * @returns The offset at the position, clamped to the extent of the\n * editor contents.\n */\n getOffsetAt(position: IPosition): number;\n\n /**\n * Find a position for the given offset.\n *\n * @param offset - The offset of interest.\n *\n * @returns The position at the offset, clamped to the extent of the\n * editor contents.\n */\n getPositionAt(offset: number): IPosition | undefined;\n\n /**\n * Undo one edit (if any undo events are stored).\n */\n undo(): void;\n\n /**\n * Redo one undone edit.\n */\n redo(): void;\n\n /**\n * Clear the undo history.\n */\n clearHistory(): void;\n\n /**\n * Brings browser focus to this editor text.\n */\n focus(): void;\n\n /**\n * Test whether the editor has keyboard focus.\n */\n hasFocus(): boolean;\n\n /**\n * Explicitly blur the editor.\n */\n blur(): void;\n\n /**\n * Repaint the editor.\n *\n * #### Notes\n * A repainted editor should fit to its host node.\n */\n refresh(): void;\n\n /**\n * Resize the editor to fit its host node.\n */\n resizeToFit(): void;\n\n /**\n * Add a keydown handler to the editor.\n *\n * @param handler - A keydown handler.\n *\n * @returns A disposable that can be used to remove the handler.\n */\n addKeydownHandler(handler: KeydownHandler): IDisposable;\n\n /**\n * Set the size of the editor.\n *\n * @param size - The desired size.\n *\n * #### Notes\n * Use `null` if the size is unknown.\n */\n setSize(size: IDimension | null): void;\n\n /**\n * Reveals the given position in the editor.\n *\n * @param position - The desired position to reveal.\n */\n revealPosition(position: IPosition): void;\n\n /**\n * Reveals the given selection in the editor.\n *\n * @param position - The desired selection to reveal.\n */\n revealSelection(selection: IRange): void;\n\n /**\n * Get the window coordinates given a cursor position.\n *\n * @param position - The desired position.\n *\n * @returns The coordinates of the position.\n */\n getCoordinateForPosition(position: IPosition): ICoordinate;\n\n /**\n * Get the cursor position given window coordinates.\n *\n * @param coordinate - The desired coordinate.\n *\n * @returns The position of the coordinates, or null if not\n * contained in the editor.\n */\n getPositionForCoordinate(coordinate: ICoordinate): IPosition | null;\n\n /**\n * Inserts a new line at the cursor position and indents it.\n */\n newIndentedLine(): void;\n\n /**\n * Gets the token at a given position.\n */\n getTokenForPosition(position: IPosition): IToken;\n\n /**\n * Gets the list of tokens for the editor model.\n */\n getTokens(): IToken[];\n }\n\n /**\n * A factory used to create a code editor.\n */\n export type Factory = (options: IOptions) => CodeEditor.IEditor;\n\n /**\n * The configuration options for an editor.\n */\n export interface IConfig {\n /**\n * User preferred font family for text editors.\n */\n fontFamily: string | null;\n\n /**\n * User preferred size in pixel of the font used in text editors.\n */\n fontSize: number | null;\n\n /**\n * User preferred text line height, as a multiplier of font size.\n */\n lineHeight: number | null;\n\n /**\n * Whether line numbers should be displayed.\n */\n lineNumbers: boolean;\n\n /**\n * Control the line wrapping of the editor. Possible values are:\n * - \"off\", lines will never wrap.\n * - \"on\", lines will wrap at the viewport border.\n * - \"wordWrapColumn\", lines will wrap at `wordWrapColumn`.\n * - \"bounded\", lines will wrap at minimum between viewport width and wordWrapColumn.\n */\n lineWrap: 'off' | 'on' | 'wordWrapColumn' | 'bounded';\n\n /**\n * Whether the editor is read-only.\n */\n readOnly: boolean;\n\n /**\n * The number of spaces a tab is equal to.\n */\n tabSize: number;\n\n /**\n * Whether to insert spaces when pressing Tab.\n */\n insertSpaces: boolean;\n\n /**\n * Whether to highlight matching brackets when one of them is selected.\n */\n matchBrackets: boolean;\n\n /**\n * Whether to automatically close brackets after opening them.\n */\n autoClosingBrackets: boolean;\n\n /**\n * The column where to break text line.\n */\n wordWrapColumn: number;\n }\n\n /**\n * The default configuration options for an editor.\n */\n export let defaultConfig: IConfig = {\n fontFamily: null,\n fontSize: null,\n lineHeight: null,\n lineNumbers: false,\n lineWrap: 'on',\n wordWrapColumn: 80,\n readOnly: false,\n tabSize: 4,\n insertSpaces: true,\n matchBrackets: true,\n autoClosingBrackets: true\n };\n\n /**\n * The options used to initialize an editor.\n */\n export interface IOptions {\n /**\n * The host widget used by the editor.\n */\n host: HTMLElement;\n\n /**\n * The model used by the editor.\n */\n model: IModel;\n\n /**\n * The desired uuid for the editor.\n */\n uuid?: string;\n\n /**\n * The default selection style for the editor.\n */\n selectionStyle?: Partial<CodeEditor.ISelectionStyle>;\n\n /**\n * The configuration options for the editor.\n */\n config?: Partial<IConfig>;\n }\n\n export namespace Model {\n export interface IOptions {\n /**\n * The initial value of the model.\n */\n value?: string;\n\n /**\n * The mimetype of the model.\n */\n mimeType?: string;\n\n /**\n * An optional modelDB for storing model state.\n */\n modelDB?: IModelDB;\n }\n }\n}\n"]}
package/lib/widget.js CHANGED
@@ -7,6 +7,15 @@ const widgets_1 = require("@phosphor/widgets");
7
7
  * The class name added to an editor widget that has a primary selection.
8
8
  */
9
9
  const HAS_SELECTION_CLASS = 'jp-mod-has-primary-selection';
10
+ /**
11
+ * The class name added to an editor widget that has a cursor/selection
12
+ * within the whitespace at the beginning of a line
13
+ */
14
+ const HAS_IN_LEADING_WHITESPACE_CLASS = 'jp-mod-in-leading-whitespace';
15
+ /**
16
+ * RegExp to test for leading whitespace
17
+ */
18
+ const leadingWhitespaceRe = /^\s+$/;
10
19
  /**
11
20
  * A widget which hosts a code editor.
12
21
  */
@@ -85,10 +94,22 @@ class CodeEditorWrapper extends widgets_1.Widget {
85
94
  _onSelectionsChanged() {
86
95
  const { start, end } = this.editor.getSelection();
87
96
  if (start.column !== end.column || start.line !== end.line) {
97
+ // a selection was made
88
98
  this.addClass(HAS_SELECTION_CLASS);
99
+ this.removeClass(HAS_IN_LEADING_WHITESPACE_CLASS);
89
100
  }
90
101
  else {
102
+ // the cursor was placed
91
103
  this.removeClass(HAS_SELECTION_CLASS);
104
+ if (this.editor
105
+ .getLine(end.line)
106
+ .slice(0, end.column)
107
+ .match(leadingWhitespaceRe)) {
108
+ this.addClass(HAS_IN_LEADING_WHITESPACE_CLASS);
109
+ }
110
+ else {
111
+ this.removeClass(HAS_IN_LEADING_WHITESPACE_CLASS);
112
+ }
92
113
  }
93
114
  }
94
115
  }
package/lib/widget.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"widget.js","sourceRoot":"","sources":["../../../../codeeditor/src/widget.ts"],"names":[],"mappings":";AAAA,0CAA0C;AAC1C,2DAA2D;;AAI3D,+CAA2C;AAI3C;;GAEG;AACH,MAAM,mBAAmB,GAAG,8BAA8B,CAAC;AAE3D;;GAEG;AACH,uBAA+B,SAAQ,gBAAM;IAC3C;;OAEG;IACH,YAAY,OAAmC;QAC7C,KAAK,EAAE,CAAC;QACR,MAAM,MAAM,GAAG,CAAC,IAAI,CAAC,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC;YAC5C,IAAI,EAAE,IAAI,CAAC,IAAI;YACf,KAAK,EAAE,OAAO,CAAC,KAAK;YACpB,IAAI,EAAE,OAAO,CAAC,IAAI;YAClB,MAAM,EAAE,OAAO,CAAC,MAAM;YACtB,cAAc,EAAE,OAAO,CAAC,cAAc;SACvC,CAAC,CAAC,CAAC;QACJ,MAAM,CAAC,KAAK,CAAC,UAAU,CAAC,OAAO,CAAC,OAAO,CAAC,IAAI,CAAC,oBAAoB,EAA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,GAAG,CAAC,IAAI,EAAE;YAC1D,IAAI,CAAC,QAAQ,CAAC,mBAAmB,CAAC,CAAC;SACpC;aAAM;YACL,IAAI,CAAC,WAAW,CAAC,mBAAmB,CAAC,CAAC;SACvC;IACH,CAAC;CACF;AA7FD,8CA6FC","sourcesContent":["// Copyright (c) Jupyter Development Team.\n// Distributed under the terms of the Modified BSD License.\n\nimport { Message } from '@phosphor/messaging';\n\nimport { Widget } from '@phosphor/widgets';\n\nimport { CodeEditor } from './';\n\n/**\n * The class name added to an editor widget that has a primary selection.\n */\nconst HAS_SELECTION_CLASS = 'jp-mod-has-primary-selection';\n\n/**\n * A widget which hosts a code editor.\n */\nexport class CodeEditorWrapper extends Widget {\n /**\n * Construct a new code editor widget.\n */\n constructor(options: CodeEditorWrapper.IOptions) {\n super();\n const editor = (this.editor = options.factory({\n host: this.node,\n model: options.model,\n uuid: options.uuid,\n config: options.config,\n selectionStyle: options.selectionStyle\n }));\n editor.model.selections.changed.connect(this._onSelectionsChanged, this);\n }\n\n /**\n * Get the editor wrapped by the widget.\n */\n readonly editor: CodeEditor.IEditor;\n\n /**\n * Get the model used by the widget.\n */\n get model(): CodeEditor.IModel {\n return this.editor.model;\n }\n\n /**\n * Dispose of the resources held by the widget.\n */\n dispose() {\n if (this.isDisposed) {\n return;\n }\n super.dispose();\n this.editor.dispose();\n }\n\n /**\n * Handle `'activate-request'` messages.\n */\n protected onActivateRequest(msg: Message): void {\n this.editor.focus();\n }\n\n /**\n * A message handler invoked on an `'after-attach'` message.\n */\n protected onAfterAttach(msg: Message): void {\n super.onAfterAttach(msg);\n if (this.isVisible) {\n this.update();\n }\n }\n\n /**\n * A message handler invoked on an `'after-show'` message.\n */\n protected onAfterShow(msg: Message): void {\n this.update();\n }\n\n /**\n * A message handler invoked on a `'resize'` message.\n */\n protected onResize(msg: Widget.ResizeMessage): void {\n if (msg.width >= 0 && msg.height >= 0) {\n this.editor.setSize(msg);\n } else if (this.isVisible) {\n this.editor.resizeToFit();\n }\n }\n\n /**\n * A message handler invoked on an `'update-request'` message.\n */\n protected onUpdateRequest(msg: Message): void {\n this.editor.refresh();\n }\n\n /**\n * Handle a change in model selections.\n */\n private _onSelectionsChanged(): void {\n const { start, end } = this.editor.getSelection();\n\n if (start.column !== end.column || start.line !== end.line) {\n this.addClass(HAS_SELECTION_CLASS);\n } else {\n this.removeClass(HAS_SELECTION_CLASS);\n }\n }\n}\n\n/**\n * The namespace for the `CodeEditorWrapper` statics.\n */\nexport namespace CodeEditorWrapper {\n /**\n * The options used to initialize a code editor widget.\n */\n export interface IOptions {\n /**\n * A code editor factory.\n *\n * #### Notes\n * The widget needs a factory and a model instead of a `CodeEditor.IEditor`\n * object because it needs to provide its own node as the host.\n */\n factory: CodeEditor.Factory;\n\n /**\n * The model used to initialize the code editor.\n */\n model: CodeEditor.IModel;\n\n /**\n * The desired uuid for the editor.\n */\n uuid?: string;\n\n /**\n * The configuration options for the editor.\n */\n config?: Partial<CodeEditor.IConfig>;\n\n /**\n * The default selection style for the editor.\n */\n selectionStyle?: CodeEditor.ISelectionStyle;\n }\n}\n"]}
1
+ {"version":3,"file":"widget.js","sourceRoot":"","sources":["../../../../codeeditor/src/widget.ts"],"names":[],"mappings":";AAAA,0CAA0C;AAC1C,2DAA2D;;AAI3D,+CAA2C;AAI3C;;GAEG;AACH,MAAM,mBAAmB,GAAG,8BAA8B,CAAC;AAE3D;;;GAGG;AACH,MAAM,+BAA+B,GAAG,8BAA8B,CAAC;AAEvE;;GAEG;AACH,MAAM,mBAAmB,GAAG,OAAO,CAAC;AAEpC;;GAEG;AACH,uBAA+B,SAAQ,gBAAM;IAC3C;;OAEG;IACH,YAAY,OAAmC;QAC7C,KAAK,EAAE,CAAC;QACR,MAAM,MAAM,GAAG,CAAC,IAAI,CAAC,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC;YAC5C,IAAI,EAAE,IAAI,CAAC,IAAI;YACf,KAAK,EAAE,OAAO,CAAC,KAAK;YACpB,IAAI,EAAE,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AAC;IAED;;OAEG;IACK,oBAAoB;QAC1B,MAAM,EAAE,KAAK,EAAE,GAAG,EAAE,GAAG,IAAI,CAAC,MAAM,CAAC,YAAY,EAAE,CAAC;QAElD,IAAI,KAAK,CAAC,MAAM,KAAK,GAAG,CAAC,MAAM,IAAI,KAAK,CAAC,IAAI,KAAK,GAAG,CAAC,IAAI,EAAE;YAC1D,uBAAuB;YACvB,IAAI,CAAC,QAAQ,CAAC,mBAAmB,CAAC,CAAC;YACnC,IAAI,CAAC,WAAW,CAAC,+BAA+B,CAAC,CAAC;SACnD;aAAM;YACL,wBAAwB;YACxB,IAAI,CAAC,WAAW,CAAC,mBAAmB,CAAC,CAAC;YAEtC,IACE,IAAI,CAAC,MAAM;iBACR,OAAO,CAAC,GAAG,CAAC,IAAI,CAAC;iBACjB,KAAK,CAAC,CAAC,EAAE,GAAG,CAAC,MAAM,CAAC;iBACpB,KAAK,CAAC,mBAAmB,CAAC,EAC7B;gBACA,IAAI,CAAC,QAAQ,CAAC,+BAA+B,CAAC,CAAC;aAChD;iBAAM;gBACL,IAAI,CAAC,WAAW,CAAC,+BAA+B,CAAC,CAAC;aACnD;SACF;IACH,CAAC;CACF;AA3GD,8CA2GC","sourcesContent":["// Copyright (c) Jupyter Development Team.\n// Distributed under the terms of the Modified BSD License.\n\nimport { Message } from '@phosphor/messaging';\n\nimport { Widget } from '@phosphor/widgets';\n\nimport { CodeEditor } from './';\n\n/**\n * The class name added to an editor widget that has a primary selection.\n */\nconst HAS_SELECTION_CLASS = 'jp-mod-has-primary-selection';\n\n/**\n * The class name added to an editor widget that has a cursor/selection\n * within the whitespace at the beginning of a line\n */\nconst HAS_IN_LEADING_WHITESPACE_CLASS = 'jp-mod-in-leading-whitespace';\n\n/**\n * RegExp to test for leading whitespace\n */\nconst leadingWhitespaceRe = /^\\s+$/;\n\n/**\n * A widget which hosts a code editor.\n */\nexport class CodeEditorWrapper extends Widget {\n /**\n * Construct a new code editor widget.\n */\n constructor(options: CodeEditorWrapper.IOptions) {\n super();\n const editor = (this.editor = options.factory({\n host: this.node,\n model: options.model,\n uuid: options.uuid,\n config: options.config,\n selectionStyle: options.selectionStyle\n }));\n editor.model.selections.changed.connect(this._onSelectionsChanged, this);\n }\n\n /**\n * Get the editor wrapped by the widget.\n */\n readonly editor: CodeEditor.IEditor;\n\n /**\n * Get the model used by the widget.\n */\n get model(): CodeEditor.IModel {\n return this.editor.model;\n }\n\n /**\n * Dispose of the resources held by the widget.\n */\n dispose() {\n if (this.isDisposed) {\n return;\n }\n super.dispose();\n this.editor.dispose();\n }\n\n /**\n * Handle `'activate-request'` messages.\n */\n protected onActivateRequest(msg: Message): void {\n this.editor.focus();\n }\n\n /**\n * A message handler invoked on an `'after-attach'` message.\n */\n protected onAfterAttach(msg: Message): void {\n super.onAfterAttach(msg);\n if (this.isVisible) {\n this.update();\n }\n }\n\n /**\n * A message handler invoked on an `'after-show'` message.\n */\n protected onAfterShow(msg: Message): void {\n this.update();\n }\n\n /**\n * A message handler invoked on a `'resize'` message.\n */\n protected onResize(msg: Widget.ResizeMessage): void {\n if (msg.width >= 0 && msg.height >= 0) {\n this.editor.setSize(msg);\n } else if (this.isVisible) {\n this.editor.resizeToFit();\n }\n }\n\n /**\n * A message handler invoked on an `'update-request'` message.\n */\n protected onUpdateRequest(msg: Message): void {\n this.editor.refresh();\n }\n\n /**\n * Handle a change in model selections.\n */\n private _onSelectionsChanged(): void {\n const { start, end } = this.editor.getSelection();\n\n if (start.column !== end.column || start.line !== end.line) {\n // a selection was made\n this.addClass(HAS_SELECTION_CLASS);\n this.removeClass(HAS_IN_LEADING_WHITESPACE_CLASS);\n } else {\n // the cursor was placed\n this.removeClass(HAS_SELECTION_CLASS);\n\n if (\n this.editor\n .getLine(end.line)\n .slice(0, end.column)\n .match(leadingWhitespaceRe)\n ) {\n this.addClass(HAS_IN_LEADING_WHITESPACE_CLASS);\n } else {\n this.removeClass(HAS_IN_LEADING_WHITESPACE_CLASS);\n }\n }\n }\n}\n\n/**\n * The namespace for the `CodeEditorWrapper` statics.\n */\nexport namespace CodeEditorWrapper {\n /**\n * The options used to initialize a code editor widget.\n */\n export interface IOptions {\n /**\n * A code editor factory.\n *\n * #### Notes\n * The widget needs a factory and a model instead of a `CodeEditor.IEditor`\n * object because it needs to provide its own node as the host.\n */\n factory: CodeEditor.Factory;\n\n /**\n * The model used to initialize the code editor.\n */\n model: CodeEditor.IModel;\n\n /**\n * The desired uuid for the editor.\n */\n uuid?: string;\n\n /**\n * The configuration options for the editor.\n */\n config?: Partial<CodeEditor.IConfig>;\n\n /**\n * The default selection style for the editor.\n */\n selectionStyle?: CodeEditor.ISelectionStyle;\n }\n}\n"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@jupyterlab/codeeditor",
3
- "version": "0.17.2",
3
+ "version": "0.18.4",
4
4
  "description": "JupyterLab - Abstract Code Editor",
5
5
  "homepage": "https://github.com/jupyterlab/jupyterlab",
6
6
  "bugs": {
@@ -30,8 +30,8 @@
30
30
  "watch": "tsc -w --listEmittedFiles"
31
31
  },
32
32
  "dependencies": {
33
- "@jupyterlab/coreutils": "^2.0.2",
34
- "@jupyterlab/observables": "^2.0.2",
33
+ "@jupyterlab/coreutils": "^2.1.4",
34
+ "@jupyterlab/observables": "^2.0.7",
35
35
  "@phosphor/coreutils": "^1.3.0",
36
36
  "@phosphor/disposable": "^1.1.2",
37
37
  "@phosphor/messaging": "^1.2.2",