Skip to content
This repository has been archived by the owner on Sep 6, 2021. It is now read-only.

Commit

Permalink
Merge pull request #7301 from SAPlayer/fix-7293
Browse files Browse the repository at this point in the history
Restore the correct selections after "Toggle line comment"
  • Loading branch information
njx committed Mar 28, 2014
2 parents 360e9cc + 350d0a6 commit 2644deb
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/editor/EditorCommandHandlers.js
Original file line number Diff line number Diff line change
Expand Up @@ -563,7 +563,7 @@ define(function (require, exports, module) {
}
if (!edit) {
// Even if we didn't want to do an edit, we still need to track the selection.
edit = {selection: [sel]};
edit = {selection: lineSel.selectionsToTrack};
}
edits.push(edit);
});
Expand Down
56 changes: 56 additions & 0 deletions test/spec/EditorCommandHandlers-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -630,6 +630,62 @@ define(function (require, exports, module) {
expectSelection({start: {line: 1, ch: 0}, end: {line: 4, ch: 0}});
});
});
describe("Line comment in languages with no given line comment prefix", function () {
beforeEach(function () {
setupFullEditor(null, "unknown");
});

it("should properly restore the cursor", function () {
myEditor.setSelection({line: 1, ch: 4}, {line: 1, ch: 4});

CommandManager.execute(Commands.EDIT_LINE_COMMENT, myEditor);

expect(myDocument.getText()).toEqual(defaultContent);
expectSelection({start: {line: 1, ch: 4}, end: {line: 1, ch: 4}});
});

it("should properly restore the range selection", function () {
myEditor.setSelection({line: 1, ch: 4}, {line: 1, ch: 6});

CommandManager.execute(Commands.EDIT_LINE_COMMENT, myEditor);

expect(myDocument.getText()).toEqual(defaultContent);
expectSelection({start: {line: 1, ch: 4}, end: {line: 1, ch: 6}});
});

it("should properly restore the cursors", function () {
myEditor.setSelections([{start: {line: 1, ch: 4}, end: {line: 1, ch: 4}},
{start: {line: 3, ch: 4}, end: {line: 3, ch: 4}}]);

CommandManager.execute(Commands.EDIT_LINE_COMMENT, myEditor);

expect(myDocument.getText()).toEqual(defaultContent);
expect(myEditor.getSelections()).toEqual([{start: {line: 1, ch: 4}, end: {line: 1, ch: 4}, reversed: false, primary: false},
{start: {line: 3, ch: 4}, end: {line: 3, ch: 4}, reversed: false, primary: true}]);
});

it("should properly restore the range selections", function () {
myEditor.setSelections([{start: {line: 1, ch: 4}, end: {line: 1, ch: 6}},
{start: {line: 3, ch: 4}, end: {line: 3, ch: 6}}]);

CommandManager.execute(Commands.EDIT_LINE_COMMENT, myEditor);

expect(myDocument.getText()).toEqual(defaultContent);
expect(myEditor.getSelections()).toEqual([{start: {line: 1, ch: 4}, end: {line: 1, ch: 6}, reversed: false, primary: false},
{start: {line: 3, ch: 4}, end: {line: 3, ch: 6}, reversed: false, primary: true}]);
});

it("should properly restore primary/reversed range selections", function () {
myEditor.setSelections([{start: {line: 1, ch: 4}, end: {line: 1, ch: 4}, primary: true},
{start: {line: 3, ch: 4}, end: {line: 3, ch: 12}, reversed: true}]);

CommandManager.execute(Commands.EDIT_LINE_COMMENT, myEditor);

expect(myDocument.getText()).toEqual(defaultContent);
expect(myEditor.getSelections()).toEqual([{start: {line: 1, ch: 4}, end: {line: 1, ch: 4}, reversed: false, primary: true},
{start: {line: 3, ch: 4}, end: {line: 3, ch: 12}, reversed: true, primary: false}]);
});
});

describe("Block comment/uncomment", function () {
beforeEach(setupFullEditor);
Expand Down

0 comments on commit 2644deb

Please sign in to comment.