Skip to content

Commit e253c53

Browse files
committed
fix: clicking on color gutter didnt bring up editor
1 parent 18a7578 commit e253c53

File tree

2 files changed

+20
-11
lines changed

2 files changed

+20
-11
lines changed

src/editor/Editor.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1130,6 +1130,17 @@ define(function (require, exports, module) {
11301130
return cm.getRange(pos, { line: pos.line, ch: pos.ch + 1 });
11311131
};
11321132

1133+
/**
1134+
* Retrieves a single line text
1135+
* @param {number} lineNumber - The lineNumber to extract text from
1136+
* @returns {string|null} The text at the given position if within bounds,
1137+
* otherwise `null` if the position is out of range.
1138+
*/
1139+
Editor.prototype.getLine = function (lineNumber) {
1140+
const retrievedText = this._codeMirror.getLine(lineNumber);
1141+
return retrievedText === undefined ? null : retrievedText;
1142+
};
1143+
11331144
/**
11341145
* Retrieves a single character previous to the specified position in the editor in the same line if possible.
11351146
* x|y where `|` is the cursor, will return x

src/extensionsIntegrated/CSSColorPreview/main.js

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -62,13 +62,12 @@ define(function (require, exports, module) {
6262
*/
6363
function _getAllColorsAndLineNums(editor) {
6464

65-
const cm = editor._codeMirror;
66-
const nLen = cm.lineCount();
65+
const nLen = editor.lineCount();
6766
const aColors = [];
6867

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

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

148147
/**
149148
* To move the cursor to the color text and display the color quick edit
150-
* @param {Editor} codem the codemirror instance
149+
* @param {CodeMirror} codeMirror the codemirror instance
151150
* @param {Number} lineNumber the line number that is clicked
152151
* @param {String} gutter the gutter name
153152
*/
154-
function colorIconClicked(codem, lineNumber, gutter) {
153+
function colorIconClicked(codeMirror, lineNumber, gutter) {
155154
const editor = EditorManager.getActiveEditor();
156-
const cm = editor._codeMirror;
157155

158-
if(gutter === 'CodeMirror-linenumbers') {
156+
if(gutter === GUTTER_NAME) {
159157

160158
let colorValue;
161159

162-
for(let i of codem.colorGutters) {
160+
for(let i of codeMirror.colorGutters) {
163161
if(i.lineNumber === lineNumber) {
164162
colorValue = i.colorValues[0];
165163
}
166164
}
167165

168-
const lineText = cm.getLine(lineNumber);
166+
const lineText = editor.getLine(lineNumber);
169167
const colorIndex = lineText.indexOf(colorValue);
170168

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

199-
cm.on("gutterClick", (codem, lineNumber, gutter) => {
200-
colorIconClicked(codem, lineNumber, gutter);
197+
cm.on("gutterClick", (codeMirror, lineNumber, gutter) => {
198+
colorIconClicked(codeMirror, lineNumber, gutter);
201199
});
202200

203201
// Only add markers if enabled

0 commit comments

Comments
 (0)