Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions src/editor/Editor.js
Original file line number Diff line number Diff line change
Expand Up @@ -1130,6 +1130,17 @@ define(function (require, exports, module) {
return cm.getRange(pos, { line: pos.line, ch: pos.ch + 1 });
};

/**
* Retrieves a single line text
* @param {number} lineNumber - The lineNumber to extract text from
* @returns {string|null} The text at the given position if within bounds,
* otherwise `null` if the position is out of range.
*/
Editor.prototype.getLine = function (lineNumber) {
const retrievedText = this._codeMirror.getLine(lineNumber);
return retrievedText === undefined ? null : retrievedText;
};

/**
* Retrieves a single character previous to the specified position in the editor in the same line if possible.
* x|y where `|` is the cursor, will return x
Expand Down
20 changes: 9 additions & 11 deletions src/extensionsIntegrated/CSSColorPreview/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,13 +62,12 @@ define(function (require, exports, module) {
*/
function _getAllColorsAndLineNums(editor) {

const cm = editor._codeMirror;
const nLen = cm.lineCount();
const nLen = editor.lineCount();
const aColors = [];

// match colors and push into an array
for (let i = 0; i < nLen; i++) {
let lineText = cm.getLine(i);
let lineText = editor.getLine(i);

if ((lineText.indexOf('/*') !== -1) || (lineText.indexOf('*/') !== -1)) {
continue;
Expand Down Expand Up @@ -147,25 +146,24 @@ define(function (require, exports, module) {

/**
* To move the cursor to the color text and display the color quick edit
* @param {Editor} codem the codemirror instance
* @param {CodeMirror} codeMirror the codemirror instance
* @param {Number} lineNumber the line number that is clicked
* @param {String} gutter the gutter name
*/
function colorIconClicked(codem, lineNumber, gutter) {
function colorIconClicked(codeMirror, lineNumber, gutter) {
const editor = EditorManager.getActiveEditor();
const cm = editor._codeMirror;

if(gutter === 'CodeMirror-linenumbers') {
if(gutter === GUTTER_NAME) {

let colorValue;

for(let i of codem.colorGutters) {
for(let i of codeMirror.colorGutters) {
if(i.lineNumber === lineNumber) {
colorValue = i.colorValues[0];
}
}

const lineText = cm.getLine(lineNumber);
const lineText = editor.getLine(lineNumber);
const colorIndex = lineText.indexOf(colorValue);

if (colorIndex !== -1) {
Expand Down Expand Up @@ -196,8 +194,8 @@ define(function (require, exports, module) {
editor.clearGutter(GUTTER_NAME); // clear color markers
_addDummyGutterMarkerIfNotExist(editor, editor.getCursorPos().line);

cm.on("gutterClick", (codem, lineNumber, gutter) => {
colorIconClicked(codem, lineNumber, gutter);
cm.on("gutterClick", (codeMirror, lineNumber, gutter) => {
colorIconClicked(codeMirror, lineNumber, gutter);
});

// Only add markers if enabled
Expand Down
8 changes: 7 additions & 1 deletion test/spec/Editor-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -449,7 +449,13 @@ define(function (require, exports, module) {
});
});

describe("getCursorPos", function () {
describe("getCursorPos and getLine", function () {
it("should getLine work correctly", function () {
expect(myEditor.getLine(0)).toEqual("this is line 0");
expect(myEditor.getLine(10000)).toEqual(null);
expect(myEditor.getLine(-1)).toEqual(null);
});

it("should return a single cursor", function () {
myEditor._codeMirror.setCursor(0, 2);
expect(myEditor.getCursorPos().line).toEqual(0);
Expand Down
Loading