Skip to content

Commit a783878

Browse files
committed
deploy: 851cfff
1 parent 46b0d32 commit a783878

File tree

21 files changed

+150
-18
lines changed

21 files changed

+150
-18
lines changed

assets/default-project/en.zip

0 Bytes
Binary file not shown.

assets/sample-projects/HTML5.zip

0 Bytes
Binary file not shown.
0 Bytes
Binary file not shown.
0 Bytes
Binary file not shown.

assets/sample-projects/explore.zip

0 Bytes
Binary file not shown.
0 Bytes
Binary file not shown.

editor/Editor.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1147,6 +1147,13 @@ define(function (require, exports, module) {
11471147
className: "editor-text-fragment-hover"
11481148
}, MARK_OPTION_MATCHING_REFS = {
11491149
className: "editor-text-fragment-matching-refs"
1150+
}, MARK_OPTION_RENAME_OUTLINE ={
1151+
className: "editor-text-rename-outline",
1152+
startStyle: "editor-text-rename-outline-left",
1153+
endStyle: "editor-text-rename-outline-right",
1154+
clearWhenEmpty: false,
1155+
inclusiveLeft: true,
1156+
inclusiveRight: true
11501157
};
11511158

11521159
/**
@@ -2390,6 +2397,7 @@ define(function (require, exports, module) {
23902397
Editor.MARK_OPTION_UNDERLINE_SPELLCHECK = MARK_OPTION_UNDERLINE_SPELLCHECK;
23912398
Editor.MARK_OPTION_HYPERLINK_TEXT = MARK_OPTION_HYPERLINK_TEXT;
23922399
Editor.MARK_OPTION_MATCHING_REFS = MARK_OPTION_MATCHING_REFS;
2400+
Editor.MARK_OPTION_RENAME_OUTLINE = MARK_OPTION_RENAME_OUTLINE;
23932401

23942402
/**
23952403
* Each Editor instance object dispatches the following events:

extensions/default/JavaScriptRefactoring/RenameIdentifier.js

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,17 +22,20 @@
2222
define(function (require, exports, module) {
2323

2424

25-
let EditorManager = brackets.getModule("editor/EditorManager"),
25+
const EditorManager = brackets.getModule("editor/EditorManager"),
2626
ScopeManager = brackets.getModule("JSUtils/ScopeManager"),
2727
Session = brackets.getModule("JSUtils/Session"),
2828
MessageIds = JSON.parse(brackets.getModule("text!JSUtils/MessageIds.json")),
2929
TokenUtils = brackets.getModule("utils/TokenUtils"),
3030
Strings = brackets.getModule("strings"),
31-
ProjectManager = brackets.getModule("project/ProjectManager");
31+
Editor = brackets.getModule("editor/Editor").Editor,
32+
ProjectManager = brackets.getModule("project/ProjectManager");
3233

3334
let session = null, // object that encapsulates the current session state
3435
keywords = ["define", "alert", "exports", "require", "module", "arguments"];
3536

37+
const MARK_TYPE_RENAME = "renameVar";
38+
3639
//Create new session
3740
function initializeSession(editor) {
3841
session = new Session(editor);
@@ -120,6 +123,21 @@ define(function (require, exports, module) {
120123
// references properly. This sadly needs refactoring the current tern integration heavily
121124
}
122125

126+
function _outlineText(currentEditor) {
127+
let selections = currentEditor.getSelections();
128+
if(selections.length > 1 ){
129+
let primary = currentEditor.getSelection();
130+
currentEditor.markText(MARK_TYPE_RENAME, primary.start, primary.end, Editor.MARK_OPTION_RENAME_OUTLINE);
131+
currentEditor.off(Editor.EVENT_BEFORE_SELECTION_CHANGE + ".renameVar");
132+
currentEditor.on(Editor.EVENT_BEFORE_SELECTION_CHANGE + ".renameVar", function (_evt, newSelections) {
133+
if(newSelections.ranges && newSelections.ranges.length === 1) {
134+
currentEditor.clearAllMarks(MARK_TYPE_RENAME);
135+
currentEditor.off(Editor.EVENT_BEFORE_SELECTION_CHANGE + ".renameVar");
136+
}
137+
});
138+
}
139+
}
140+
123141
/**
124142
* Check if references are in this file only
125143
* If yes then select all references
@@ -165,6 +183,7 @@ define(function (require, exports, module) {
165183
primaryRef.primary = true;
166184

167185
editor.setSelections(refsArray);
186+
_outlineText(editor);
168187
}
169188

170189
/**
@@ -189,5 +208,9 @@ define(function (require, exports, module) {
189208
return result.promise();
190209
}
191210

211+
// for tests
212+
exports._MARK_TYPE_RENAME = MARK_TYPE_RENAME;
213+
214+
// public api
192215
exports.handleRename = handleRename;
193216
});

extensions/default/JavaScriptRefactoring/unittests.js

Lines changed: 31 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@ define(function (require, exports, module) {
3434
ProjectManager = brackets.getModule("project/ProjectManager"),
3535
FileSystem = brackets.getModule("filesystem/FileSystem"),
3636
ExtractToFunction = require("ExtractToFunction"),
37-
TokenUtils = brackets.getModule("utils/TokenUtils"),
3837
WrapSelection = require("WrapSelection"),
3938
RenameIdentifier = require("RenameIdentifier"),
4039
HighLightReferences = require("HighLightReferences");
@@ -616,9 +615,7 @@ define(function (require, exports, module) {
616615

617616

618617
await _waitForRename(selections.length, function() {
619-
var selections = testEditor.getSelections(),
620-
token1 = TokenUtils.getTokenAt(testEditor._codeMirror, {line: 132, ch: 14}, {line: 132, ch: 14}),
621-
token2 = TokenUtils.getTokenAt(testEditor._codeMirror, {line: 140, ch: 17}, {line: 140, ch: 17});
618+
let selections = testEditor.getSelections();
622619

623620
expect(selections[0].start.line).toEqual(132);
624621
expect(selections[1].start.line).toEqual(140);
@@ -634,14 +631,41 @@ define(function (require, exports, module) {
634631

635632

636633
await _waitForRename(selections.length, function() {
637-
var selections = testEditor.getSelections(),
638-
token1 = TokenUtils.getTokenAt(testEditor._codeMirror, {line: 149, ch: 6}, {line: 149, ch: 6}),
639-
token2 = TokenUtils.getTokenAt(testEditor._codeMirror, {line: 150, ch: 13}, {line: 150, ch: 13});
634+
let selections = testEditor.getSelections();
640635

641636
expect(selections[0].start.line).toEqual(165);
642637
expect(selections[1].start.line).toEqual(168);
643638
});
644639
});
640+
641+
it("should highlight border on renamed variable if there is more than one reference", async function() {
642+
testEditor.setSelection({line: 165, ch: 6}, {line: 165, ch: 6});
643+
644+
var selections = testEditor.getSelections();
645+
646+
RenameIdentifier.handleRename();
647+
648+
649+
await _waitForRename(selections.length, function() {
650+
let marks = testEditor.getAllMarks(RenameIdentifier._MARK_TYPE_RENAME);
651+
expect(marks.length).toBe(1);
652+
});
653+
654+
// now change the selection so that rename outline is removed.
655+
testEditor.setCursorPos(0, 0);
656+
let marks = testEditor.getAllMarks(RenameIdentifier._MARK_TYPE_RENAME);
657+
expect(marks.length).toBe(0);
658+
}, 10000);
659+
660+
it("should not highlight border on renamed variable if there is only one reference", async function() {
661+
testEditor.setSelection({line: 162, ch: 11}, {line: 162, ch: 11});
662+
663+
RenameIdentifier.handleRename();
664+
665+
await awaits(1000); // wait for rename to give some time. This is not a good way to do this
666+
let marks = testEditor.getAllMarks(RenameIdentifier._MARK_TYPE_RENAME);
667+
expect(marks.length).toBe(0);
668+
}, 5000);
645669
});
646670

647671
describe("Highlight References", function () {

src/assets/default-project/en.zip

0 Bytes
Binary file not shown.

0 commit comments

Comments
 (0)