diff --git a/spec/text-editor-spec.js b/spec/text-editor-spec.js index eba2c34f7..4a4723da1 100644 --- a/spec/text-editor-spec.js +++ b/spec/text-editor-spec.js @@ -6716,6 +6716,20 @@ describe('TextEditor', () => { const gutter = editor.addGutter(options) expect(editor.getGutters().length).toBe(2) expect(editor.getGutters()[1]).toBe(gutter) + expect(gutter.kind).toBe('decorated') + }) + + it('can add a custom line-number gutter', () => { + expect(editor.getGutters().length).toBe(1) + const options = { + name: 'another-gutter', + priority: 2, + kind: 'line-number' + } + const gutter = editor.addGutter(options) + expect(editor.getGutters().length).toBe(2) + expect(editor.getGutters()[1]).toBe(gutter) + expect(gutter.kind).toBe('line-number') }) it("does not allow a custom gutter with the 'line-number' name.", () => expect(editor.addGutter.bind(editor, {name: 'line-number'})).toThrow()) diff --git a/src/gutter-container.js b/src/gutter-container.js index 3faece073..220d9f017 100644 --- a/src/gutter-container.js +++ b/src/gutter-container.js @@ -97,7 +97,7 @@ module.exports = class GutterContainer { // The public interface is Gutter::decorateMarker or TextEditor::decorateMarker. addGutterDecoration (gutter, marker, options) { - if (gutter.name === 'line-number') { + if (gutter.kind === 'line-number') { options.type = 'line-number' } else { options.type = 'gutter' diff --git a/src/gutter.js b/src/gutter.js index 3bf7a72ea..6835e698a 100644 --- a/src/gutter.js +++ b/src/gutter.js @@ -11,6 +11,8 @@ module.exports = class Gutter { this.name = options && options.name this.priority = (options && options.priority != null) ? options.priority : DefaultPriority this.visible = (options && options.visible != null) ? options.visible : true + this.kind = (options && options.kind != null) ? options.kind : 'decorated' + this.labelFn = options && options.labelFn this.emitter = new Emitter() } diff --git a/src/text-editor.js b/src/text-editor.js index efa7353e0..bcf20651a 100644 --- a/src/text-editor.js +++ b/src/text-editor.js @@ -258,6 +258,7 @@ class TextEditor { this.gutterContainer = new GutterContainer(this) this.lineNumberGutter = this.gutterContainer.addGutter({ name: 'line-number', + kind: 'line-number', priority: 0, visible: params.lineNumberGutterVisible }) @@ -4211,6 +4212,16 @@ class TextEditor { // window. (default: -100) // * `visible` (optional) {Boolean} specifying whether the gutter is visible // initially after being created. (default: true) + // * `type` (optional) {String} specifying the type of gutter to create. `'decorated'` + // gutters are useful as a destination for decorations created with {Gutter::decorateMarker}. + // `'line-number'` gutters + // * `labelFn` (optional) {Function} called by a `'line-number'` gutter to generate the label for each line number + // element. Should return a {String} that will be used to label the corresponding line. + // * `lineData` an {Object} containing information about each line to label. + // * `bufferRow` {Number} indicating the zero-indexed buffer index of this line. + // * `screenRow` {Number} indicating the zero-indexed screen index. + // * `foldable` {Boolean} that is `true` if a fold may be created here. + // * `softWrapped` {Boolean} if this screen row is the soft-wrapped continuation of the same buffer row. // // Returns the newly-created {Gutter}. addGutter (options) {