This repository was archived by the owner on Sep 6, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 7.6k
Fix #3130: Move line up/down has incorrect behavior in edge cases in inline editor #3233
Merged
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
f96be45
Adding special cases when moving lines up or down at the last lines o…
TomMalbran bb3919b
Merge remote-tracking branch 'upstream/master' into tom/fix-issue-3130
TomMalbran e2ba221
Tests for the new special cases in inline editors
TomMalbran ac079bc
Tests fixes after first review
TomMalbran d91ee51
Merge remote-tracking branch 'upstream/master' into tom/fix-issue-3130
TomMalbran e59dccc
Close all documents after each test and open them before each test.
TomMalbran File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
.testClass { | ||
color: red; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
<!doctype html> | ||
<html> | ||
<head> | ||
<title>Simple Test</title> | ||
<link rel="stylesheet" href="test.css"> | ||
</head> | ||
|
||
<body> | ||
<p class="testClass">Brackets is awesome!</p> | ||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -22,12 +22,13 @@ | |
*/ | ||
|
||
/*jslint vars: true, plusplus: true, devel: true, nomen: true, indent: 4, maxerr: 50 */ | ||
/*global define, describe, it, expect, beforeEach, afterEach, waitsFor, waits, runs, $ */ | ||
/*global define, describe, it, expect, beforeEach, afterEach, waitsFor, waits, runs, $, waitsForDone */ | ||
|
||
define(function (require, exports, module) { | ||
'use strict'; | ||
|
||
var Editor = require("editor/Editor").Editor, | ||
EditorManager = require("editor/EditorManager"), | ||
EditorCommandHandlers = require("editor/EditorCommandHandlers"), | ||
Commands = require("command/Commands"), | ||
CommandManager = require("command/CommandManager"), | ||
|
@@ -59,19 +60,23 @@ define(function (require, exports, module) { | |
myEditor.focus(); | ||
} | ||
|
||
function makeEditorWithRange(range) { | ||
function makeEditorWithRange(range, content) { | ||
content = content || defaultContent; | ||
|
||
// create editor with a visible range | ||
var mocks = SpecRunnerUtils.createMockEditor(defaultContent, "javascript", range); | ||
var mocks = SpecRunnerUtils.createMockEditor(content, "javascript", range); | ||
myDocument = mocks.doc; | ||
myEditor = mocks.editor; | ||
|
||
myEditor.focus(); | ||
} | ||
|
||
afterEach(function () { | ||
SpecRunnerUtils.destroyMockEditor(myDocument); | ||
myEditor = null; | ||
myDocument = null; | ||
if (myDocument) { | ||
SpecRunnerUtils.destroyMockEditor(myDocument); | ||
myEditor = null; | ||
myDocument = null; | ||
} | ||
}); | ||
|
||
|
||
|
@@ -2065,6 +2070,119 @@ define(function (require, exports, module) { | |
}); | ||
|
||
|
||
describe("Move Lines Up/Down - inline editor", function () { | ||
this.category = "integration"; | ||
|
||
var testWindow, promise, editor; | ||
var testPath = SpecRunnerUtils.getTestPath("/spec/EditorCommandHandlers-test-files"); | ||
|
||
var moveContent = ".testClass {\n" + | ||
" color: red;\n" + | ||
"}"; | ||
|
||
beforeEach(function () { | ||
if (!testWindow) { | ||
SpecRunnerUtils.createTestWindowAndRun(this, function (w) { | ||
testWindow = w; | ||
|
||
// Load module instances from brackets.test | ||
CommandManager = testWindow.brackets.test.CommandManager; | ||
Commands = testWindow.brackets.test.Commands; | ||
EditorManager = testWindow.brackets.test.EditorManager; | ||
|
||
SpecRunnerUtils.loadProjectInTestWindow(testPath); | ||
}); | ||
} | ||
|
||
runs(function () { | ||
promise = CommandManager.execute(Commands.FILE_ADD_TO_WORKING_SET, {fullPath: testPath + "/test.html"}); | ||
waitsForDone(promise, "Open into working set"); | ||
}); | ||
|
||
runs(function () { | ||
// Open inline editor onto test.css's ".testClass" rule | ||
promise = SpecRunnerUtils.toggleQuickEditAtOffset(EditorManager.getCurrentFullEditor(), {line: 8, ch: 11}); | ||
waitsForDone(promise, "Open inline editor"); | ||
}); | ||
|
||
runs(function () { | ||
editor = EditorManager.getCurrentFullEditor().getInlineWidgets()[0].editors[0]; | ||
}); | ||
}); | ||
|
||
afterEach(function () { | ||
runs(function () { | ||
var promise = CommandManager.execute(Commands.FILE_CLOSE_ALL); | ||
waitsForDone(promise, "Close all open files in working set"); | ||
|
||
// Close the save dialog without saving the changes | ||
var $dlg = testWindow.$(".modal.instance"); | ||
if ($dlg.length) { | ||
SpecRunnerUtils.clickDialogButton("dontsave"); | ||
} | ||
}); | ||
}); | ||
|
||
|
||
it("should not move the first line of the inline editor up", function () { | ||
editor.setCursorPos({line: 0, ch: 5}); | ||
CommandManager.execute(Commands.EDIT_LINE_UP, editor); | ||
|
||
expect(editor.document.getText()).toEqual(moveContent); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We could also check |
||
expect(editor._codeMirror.doc.historySize().undo).toBe(0); | ||
expect(editor.getFirstVisibleLine()).toBe(0); | ||
expect(editor.getLastVisibleLine()).toBe(2); | ||
}); | ||
|
||
it("should not move the last line of the inline editor down", function () { | ||
editor.setCursorPos({line: 2, ch: 5}); | ||
CommandManager.execute(Commands.EDIT_LINE_DOWN, editor); | ||
|
||
expect(editor.document.getText()).toEqual(moveContent); | ||
expect(editor._codeMirror.doc.historySize().undo).toBe(0); | ||
expect(editor.getFirstVisibleLine()).toBe(0); | ||
expect(editor.getLastVisibleLine()).toBe(2); | ||
}); | ||
|
||
it("should be able to move the second to last line of the inline editor down", function () { | ||
editor.setCursorPos({line: 1, ch: 5}); | ||
CommandManager.execute(Commands.EDIT_LINE_DOWN, editor); | ||
|
||
var lines = moveContent.split("\n"); | ||
var temp = lines[1]; | ||
lines[1] = lines[2]; | ||
lines[2] = temp; | ||
var expectedText = lines.join("\n"); | ||
|
||
expect(editor.document.getText()).toEqual(expectedText); | ||
expect(editor.getFirstVisibleLine()).toBe(0); | ||
expect(editor.getLastVisibleLine()).toBe(2); | ||
}); | ||
|
||
it("should be able to move the last line of the inline editor up", function () { | ||
editor.setCursorPos({line: 2, ch: 0}); | ||
CommandManager.execute(Commands.EDIT_LINE_UP, editor); | ||
|
||
var lines = moveContent.split("\n"); | ||
var temp = lines[1]; | ||
lines[1] = lines[2]; | ||
lines[2] = temp; | ||
var expectedText = lines.join("\n"); | ||
|
||
expect(editor.document.getText()).toEqual(expectedText); | ||
expect(editor.getFirstVisibleLine()).toBe(0); | ||
expect(editor.getLastVisibleLine()).toBe(2); | ||
|
||
// This must be in the last spec in the suite. | ||
runs(function () { | ||
this.after(function () { | ||
SpecRunnerUtils.closeTestWindow(); | ||
}); | ||
}); | ||
}); | ||
}); | ||
|
||
|
||
describe("Delete Line", function () { | ||
beforeEach(setupFullEditor); | ||
|
||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add
this.category = "integration";
to this suite so that it runs in the integration suite instead of the unit test suite. It's our hack to keep the unit test suite running fast. All of our tests that open a Brackets window are marked as integration.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Will do. I knew about this, but didn't knew it could be added to internal describes or if it would be needed, since the tests are still fast, and the Extension Dialog tests uses windows and are unit tests.