Skip to content

Commit 0a6a251

Browse files
committed
fix: copy problem button not working when clicking on the icon
1 parent 3eecd2d commit 0a6a251

2 files changed

Lines changed: 30 additions & 4 deletions

File tree

src/language/CodeInspection.js

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -512,9 +512,9 @@ define(function (require, exports, module) {
512512
const $lineElement = $problemsPanelTable.find('td.line-number[data-line="' + lineNumber + '"]');
513513
if ($lineElement.length) {
514514
$lineElement[0].scrollIntoView({ behavior: 'instant', block: 'start' });
515-
return true;
515+
return $($lineElement[0]).parent();
516516
}
517-
return false;
517+
return null;
518518
}
519519

520520

@@ -1136,7 +1136,10 @@ define(function (require, exports, module) {
11361136
.on("click", "tr", function (e) {
11371137
if ($(e.target).hasClass('ph-copy-problem')) {
11381138
// Retrieve the message from the data attribute of the clicked element
1139-
const message = $(e.target).parent().parent().find(".line-text").text();
1139+
let message = $(e.target).parent().parent().find(".line-text").text();
1140+
if(!message){
1141+
message = $(e.target).parent().parent().parent().find(".line-text").text();
1142+
}
11401143
message && Phoenix.app.copyToClipboard(message);
11411144
e.preventDefault();
11421145
e.stopPropagation();

test/spec/CodeInspection-integ-test.js

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,8 @@ define(function (require, exports, module) {
115115
}
116116
}
117117

118+
let savedCopyFn;
119+
118120
beforeAll(async function () {
119121
testWindow = await SpecRunnerUtils.createTestWindowAndRun({forceReload: true});
120122
// Load module instances from brackets.test
@@ -127,20 +129,22 @@ define(function (require, exports, module) {
127129
CodeInspection = brackets.test.CodeInspection;
128130
PreferencesManager = brackets.test.PreferencesManager;
129131
CodeInspection.toggleEnabled(true);
130-
131132
await SpecRunnerUtils.loadProjectInTestWindow(testFolder);
133+
savedCopyFn = testWindow.Phoenix.app.copyToClipboard;
132134
}, 30000);
133135

134136
beforeEach(function () {
135137
// this is to make the tests run faster
136138
prefs.set(CodeInspection._PREF_ASYNC_TIMEOUT, 500);
139+
testWindow.Phoenix.app.copyToClipboard = savedCopyFn;
137140
});
138141

139142
afterEach(function () {
140143
testWindow.closeAllFiles();
141144
});
142145

143146
afterAll(async function () {
147+
testWindow.Phoenix.app.copyToClipboard = savedCopyFn;
144148
testWindow = null;
145149
$ = null;
146150
brackets = null;
@@ -1079,6 +1083,25 @@ define(function (require, exports, module) {
10791083
expect(fixPos(EditorManager.getActiveEditor().getCursorPos())).toEqual(fixPos({line: 1, ch: 3}));
10801084
});
10811085

1086+
it("should be able to copy problem message", async function () {
1087+
const codeInspector = createCodeInspector("javascript linter", failLintResult());
1088+
CodeInspection.register("javascript", codeInspector);
1089+
1090+
await awaitsForDone(SpecRunnerUtils.openProjectFiles(["errors.js"]), "open test file");
1091+
1092+
const $problemLine = CodeInspection.scrollToProblem(1);
1093+
let copiedVal;
1094+
testWindow.Phoenix.app.copyToClipboard = function (val) {
1095+
copiedVal = val;
1096+
};
1097+
const $copyBtnElems = $problemLine.find(".ph-copy-problem");
1098+
for(let i=0; i<$copyBtnElems.length; i++) {
1099+
copiedVal = null;
1100+
$copyBtnElems[i].click();
1101+
expect(copiedVal).toBe("Some errors here and there");
1102+
}
1103+
});
1104+
10821105
it("should Go to First Error with errors from two providers", async function () {
10831106
var codeInspector1 = createCodeInspector("javascript linter 1", {
10841107
errors: [

0 commit comments

Comments
 (0)