This repository has been 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
Add feature. Open line above/below the current line. #2729
Merged
Merged
Changes from 1 commit
Commits
Show all changes
19 commits
Select commit
Hold shift + click to select a range
c52fb15
Add feature. Open line above/below the current line (Ctrl-Enter / Ctr…
zeis c4ae5c5
Add unit tests for Open Line feature
zeis 056f84a
Improve Open Line feature. Add additional unit tests.
zeis 8d54428
Invert OpenLine shortcuts
zeis 3b87017
Merge branch 'master' of https://github.com/adobe/brackets into openline
zeis 56f678e
Fix OpenLine problem with inline editors.
zeis 3eea8da
Fix OpenLine undo history
zeis a118ef1
Add few improvements in OpenLine
zeis 6cf215c
Merge upstream updates
zeis 42cd57a
Merge master
zeis f8832d4
Merge branch 'master' of https://github.com/adobe/brackets into openline
zeis 190d58a
Include TomMalbran's suggestions
zeis ebd85e2
Merge branch 'master' of https://github.com/adobe/brackets into openline
zeis 9ebbe08
Add special case for last line in inline editor
zeis 6c0ff04
Merge branch 'master' of https://github.com/adobe/brackets into openline
zeis dd7537a
Include changes to OpenLinecode and new tests
zeis 4de987a
Merge branch 'master' of https://github.com/adobe/brackets into openline
zeis 27321f8
Remove Italian strings for OpenLine. Add little changes to tests.
zeis 5e2d29e
Few cleanups for OpenLine's tests
zeis 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
Improve Open Line feature. Add additional unit tests.
- Loading branch information
commit 056f84a26699769517b4aee95b18c0c5a6f17112
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
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 |
---|---|---|
|
@@ -1030,6 +1030,16 @@ define(function (require, exports, module) { | |
}); | ||
|
||
describe("Open Line Above and Below", function () { | ||
var indentUnit = Editor.getIndentUnit(); | ||
var indentation = (function () { | ||
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. You could actually just do 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. It raises the JSLint literal notation error. 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. Woops, I just noticed that @dangoor made the same suggestion. Lets leave it like that then. |
||
// generate indent string once | ||
var spaces = []; | ||
while (spaces.length < indentUnit) { | ||
spaces.push(" "); | ||
} | ||
return spaces.join(""); | ||
}()); | ||
|
||
beforeEach(setupFullEditor); | ||
|
||
it("should insert new line above if no selection", function () { | ||
|
@@ -1039,23 +1049,43 @@ define(function (require, exports, module) { | |
CommandManager.execute(Commands.EDIT_OPEN_LINE_ABOVE, myEditor); | ||
|
||
var lines = defaultContent.split("\n"); | ||
|
||
var indentUnit = Editor.getIndentUnit(); | ||
var spaces = []; | ||
while (spaces.length < indentUnit) { | ||
spaces.push(" "); | ||
} | ||
var indentation = spaces.join(""); | ||
lines.splice(1, 0, indentation); | ||
var expectedText = lines.join("\n"); | ||
|
||
expect(myDocument.getText()).toEqual(expectedText); | ||
expectCursorAt({line: 1, ch: indentUnit}); | ||
}); | ||
|
||
it("should insert new line above the first line if no selection", function () { | ||
// place cursor in the first line | ||
myEditor.setCursorPos(0, 0); | ||
|
||
CommandManager.execute(Commands.EDIT_OPEN_LINE_ABOVE, myEditor); | ||
|
||
var lines = defaultContent.split("\n"); | ||
lines.splice(0, 0, ""); | ||
var expectedText = lines.join("\n"); | ||
|
||
expect(myDocument.getText()).toEqual(expectedText); | ||
expectCursorAt({line: 0, ch: 0}); | ||
}); | ||
|
||
it("should insert new line above the last line if no selection", function () { | ||
// place cursor in the last line | ||
myEditor.setCursorPos(7, 0); | ||
|
||
CommandManager.execute(Commands.EDIT_OPEN_LINE_ABOVE, myEditor); | ||
|
||
var lines = defaultContent.split("\n"); | ||
lines.splice(7, 0, indentation); | ||
var expectedText = lines.join("\n"); | ||
|
||
expect(myDocument.getText()).toEqual(expectedText); | ||
expectCursorAt({line: 1, ch: 4}); | ||
expectCursorAt({line: 7, ch: indentUnit}); | ||
}); | ||
|
||
it("should insert new line above with no indentation if no selection", function () { | ||
// place cursor in line 0 | ||
// place cursor in the middle of line 0 | ||
myEditor.setCursorPos(0, 10); | ||
|
||
CommandManager.execute(Commands.EDIT_OPEN_LINE_ABOVE, myEditor); | ||
|
@@ -1075,19 +1105,11 @@ define(function (require, exports, module) { | |
CommandManager.execute(Commands.EDIT_OPEN_LINE_ABOVE, myEditor); | ||
|
||
var lines = defaultContent.split("\n"); | ||
|
||
var indentUnit = Editor.getIndentUnit(); | ||
var spaces = []; | ||
while (spaces.length < indentUnit) { | ||
spaces.push(" "); | ||
} | ||
var indentation = spaces.join(""); | ||
lines.splice(1, 0, indentation); | ||
|
||
var expectedText = lines.join("\n"); | ||
|
||
expect(myDocument.getText()).toEqual(expectedText); | ||
expectCursorAt({line: 1, ch: 4}); | ||
expectCursorAt({line: 1, ch: indentUnit}); | ||
}); | ||
|
||
it("should insert new line above when linewise selection", function () { | ||
|
@@ -1097,19 +1119,11 @@ define(function (require, exports, module) { | |
CommandManager.execute(Commands.EDIT_OPEN_LINE_ABOVE, myEditor); | ||
|
||
var lines = defaultContent.split("\n"); | ||
|
||
var indentUnit = Editor.getIndentUnit(); | ||
var spaces = []; | ||
while (spaces.length < indentUnit) { | ||
spaces.push(" "); | ||
} | ||
var indentation = spaces.join(""); | ||
lines.splice(1, 0, indentation); | ||
|
||
var expectedText = lines.join("\n"); | ||
|
||
expect(myDocument.getText()).toEqual(expectedText); | ||
expectCursorAt({line: 1, ch: 4}); | ||
expectCursorAt({line: 1, ch: indentUnit}); | ||
}); | ||
|
||
it("should insert new line above when multiple line selection", function () { | ||
|
@@ -1119,20 +1133,11 @@ define(function (require, exports, module) { | |
CommandManager.execute(Commands.EDIT_OPEN_LINE_ABOVE, myEditor); | ||
|
||
var lines = defaultContent.split("\n"); | ||
|
||
var indentUnit = Editor.getIndentUnit(); | ||
indentUnit *= 2; | ||
var spaces = []; | ||
while (spaces.length < indentUnit) { | ||
spaces.push(" "); | ||
} | ||
var indentation = spaces.join(""); | ||
lines.splice(2, 0, indentation); | ||
|
||
lines.splice(2, 0, " " + indentation); | ||
var expectedText = lines.join("\n"); | ||
|
||
expect(myDocument.getText()).toEqual(expectedText); | ||
expectCursorAt({line: 2, ch: 8}); | ||
expectCursorAt({line: 2, ch: 4 + indentUnit}); | ||
}); | ||
|
||
it("should insert new line below when no selection", function () { | ||
|
@@ -1142,24 +1147,44 @@ define(function (require, exports, module) { | |
CommandManager.execute(Commands.EDIT_OPEN_LINE_BELOW, myEditor); | ||
|
||
var lines = defaultContent.split("\n"); | ||
lines.splice(1, 0, indentation); | ||
var expectedText = lines.join("\n"); | ||
|
||
var indentUnit = Editor.getIndentUnit(); | ||
var spaces = []; | ||
while (spaces.length < indentUnit) { | ||
spaces.push(" "); | ||
} | ||
var indentation = spaces.join(""); | ||
expect(myDocument.getText()).toEqual(expectedText); | ||
expectCursorAt({line: 1, ch: indentUnit}); | ||
}); | ||
|
||
it("should insert new line below the first line if no selection", function () { | ||
// place cursor in the first line | ||
myEditor.setCursorPos(0, 0); | ||
|
||
CommandManager.execute(Commands.EDIT_OPEN_LINE_BELOW, myEditor); | ||
|
||
var lines = defaultContent.split("\n"); | ||
lines.splice(1, 0, indentation); | ||
var expectedText = lines.join("\n"); | ||
|
||
expect(myDocument.getText()).toEqual(expectedText); | ||
expectCursorAt({line: 1, ch: indentUnit}); | ||
}); | ||
|
||
it("should insert new line below the last line if no selection", function () { | ||
// place cursor in the last line | ||
myEditor.setCursorPos(7, 0); | ||
|
||
CommandManager.execute(Commands.EDIT_OPEN_LINE_BELOW, myEditor); | ||
|
||
var lines = defaultContent.split("\n"); | ||
lines.splice(8, 0, ""); | ||
var expectedText = lines.join("\n"); | ||
|
||
expect(myDocument.getText()).toEqual(expectedText); | ||
expectCursorAt({line: 1, ch: 4}); | ||
expectCursorAt({line: 8, ch: 0}); | ||
}); | ||
|
||
it("should insert new line below with no indentation if no selection", function () { | ||
// place cursor in line 7 | ||
myEditor.setCursorPos(7, 0); | ||
// place cursor in line 7 character 1 | ||
myEditor.setCursorPos(7, 1); | ||
|
||
CommandManager.execute(Commands.EDIT_OPEN_LINE_BELOW, myEditor); | ||
|
||
|
@@ -1178,19 +1203,11 @@ define(function (require, exports, module) { | |
CommandManager.execute(Commands.EDIT_OPEN_LINE_BELOW, myEditor); | ||
|
||
var lines = defaultContent.split("\n"); | ||
|
||
var indentUnit = Editor.getIndentUnit(); | ||
var spaces = []; | ||
while (spaces.length < indentUnit) { | ||
spaces.push(" "); | ||
} | ||
var indentation = spaces.join(""); | ||
lines.splice(1, 0, indentation); | ||
|
||
var expectedText = lines.join("\n"); | ||
|
||
expect(myDocument.getText()).toEqual(expectedText); | ||
expectCursorAt({line: 1, ch: 4}); | ||
expectCursorAt({line: 1, ch: indentUnit}); | ||
}); | ||
|
||
it("should insert new line below when linewise selection", function () { | ||
|
@@ -1200,20 +1217,11 @@ define(function (require, exports, module) { | |
CommandManager.execute(Commands.EDIT_OPEN_LINE_BELOW, myEditor); | ||
|
||
var lines = defaultContent.split("\n"); | ||
|
||
var indentUnit = Editor.getIndentUnit(); | ||
indentUnit *= 2; | ||
var spaces = []; | ||
while (spaces.length < indentUnit) { | ||
spaces.push(" "); | ||
} | ||
var indentation = spaces.join(""); | ||
lines.splice(3, 0, indentation); | ||
|
||
lines.splice(3, 0, " " + indentation); | ||
var expectedText = lines.join("\n"); | ||
|
||
expect(myDocument.getText()).toEqual(expectedText); | ||
expectCursorAt({line: 3, ch: 8}); | ||
expectCursorAt({line: 3, ch: 4 + indentUnit}); | ||
}); | ||
|
||
it("should insert new line below when multiple line selection", function () { | ||
|
@@ -1222,22 +1230,63 @@ define(function (require, exports, module) { | |
|
||
CommandManager.execute(Commands.EDIT_OPEN_LINE_BELOW, myEditor); | ||
|
||
var lines = defaultContent.split("\n"); | ||
lines.splice(5, 0, " " + indentation); | ||
var expectedText = lines.join("\n"); | ||
|
||
expect(myDocument.getText()).toEqual(expectedText); | ||
expectCursorAt({line: 5, ch: 4 + indentUnit}); | ||
}); | ||
}); | ||
|
||
describe("Open Line Above and Below - editor with visible range", function () { | ||
|
||
it("should insert new line above the top line of the visible range", function () { | ||
makeEditorWithRange({startLine: 0, endLine: 4}); | ||
myEditor.setSelection({line: 0, ch: 4}, {line: 0, ch: 6}); | ||
CommandManager.execute(Commands.EDIT_OPEN_LINE_ABOVE, myEditor); | ||
|
||
var lines = defaultContent.split("\n"); | ||
lines.splice(0, 0, ""); | ||
expect(myDocument.getText()).toEqual(lines.join("\n")); | ||
expect(myEditor._visibleRange.startLine).toBe(0); | ||
expect(myEditor._visibleRange.endLine).toBe(5); | ||
}); | ||
|
||
it("should insert new line above the last line of the visible range", function () { | ||
makeEditorWithRange({startLine: 0, endLine: 0}); | ||
myEditor.setSelection({line: 0, ch: 4}, {line: 0, ch: 6}); | ||
CommandManager.execute(Commands.EDIT_OPEN_LINE_ABOVE, myEditor); | ||
|
||
var indentUnit = Editor.getIndentUnit(); | ||
indentUnit *= 2; | ||
var spaces = []; | ||
while (spaces.length < indentUnit) { | ||
spaces.push(" "); | ||
} | ||
var indentation = spaces.join(""); | ||
lines.splice(5, 0, indentation); | ||
var lines = defaultContent.split("\n"); | ||
lines.splice(0, 0, ""); | ||
expect(myDocument.getText()).toEqual(lines.join("\n")); | ||
expect(myEditor._visibleRange.startLine).toBe(0); | ||
expect(myEditor._visibleRange.endLine).toBe(1); | ||
}); | ||
|
||
it("should insert new line below the first line of the visible range", function () { | ||
makeEditorWithRange({startLine: 7, endLine: 7}); | ||
myEditor.setSelection({line: 7, ch: 0}, {line: 7, ch: 1}); | ||
CommandManager.execute(Commands.EDIT_OPEN_LINE_BELOW, myEditor); | ||
|
||
var expectedText = lines.join("\n"); | ||
var lines = defaultContent.split("\n"); | ||
lines.splice(8, 0, ""); | ||
expect(myDocument.getText()).toEqual(lines.join("\n")); | ||
expect(myEditor._visibleRange.startLine).toBe(7); | ||
expect(myEditor._visibleRange.endLine).toBe(8); | ||
}); | ||
|
||
it("should insert new line below the last line of the visible range", function () { | ||
makeEditorWithRange({startLine: 6, endLine: 7}); | ||
myEditor.setSelection({line: 7, ch: 0}, {line: 7, ch: 1}); | ||
CommandManager.execute(Commands.EDIT_OPEN_LINE_BELOW, myEditor); | ||
|
||
expect(myDocument.getText()).toEqual(expectedText); | ||
expectCursorAt({line: 5, ch: 8}); | ||
var lines = defaultContent.split("\n"); | ||
lines.splice(8, 0, ""); | ||
expect(myDocument.getText()).toEqual(lines.join("\n")); | ||
expect(myEditor._visibleRange.startLine).toBe(6); | ||
expect(myEditor._visibleRange.endLine).toBe(8); | ||
}); | ||
}); | ||
}); | ||
|
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.
This API was changed in the last sprint to
Editor.getSpaceUnits()
.