Skip to content

Commit

Permalink
Merge pull request #805 from austin94/master
Browse files Browse the repository at this point in the history
ISSUE-783 Leading white space for import auto complete
  • Loading branch information
basarat committed Jan 5, 2016
2 parents 466aab5 + e81334d commit 55bcc17
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 9 deletions.
9 changes: 5 additions & 4 deletions dist/main/atom/autoCompleteProvider.js
Original file line number Diff line number Diff line change
Expand Up @@ -115,10 +115,11 @@ exports.provider = {
if (options.suggestion.atomTS_IsImport) {
options.editor.moveToBeginningOfLine();
options.editor.selectToEndOfLine();
var groups = /^\s*import\s*(\w*)\s*=\s*require\s*\(\s*(["'])/.exec(options.editor.getSelectedText());
var alias = groups[1];
quote = quote || groups[2];
options.editor.replaceSelectedText(null, function () { return "import " + alias + " = require(" + quote + options.suggestion.atomTS_IsImport.relativePath + quote + ");"; });
var groups = /^(\s*)import\s*(\w*)\s*=\s*require\s*\(\s*(["'])/.exec(options.editor.getSelectedText());
var leadingWhiteSpace = groups[1];
var alias = groups[2];
quote = quote || groups[3];
options.editor.replaceSelectedText(null, function () { return leadingWhiteSpace + "import " + alias + " = require(" + quote + options.suggestion.atomTS_IsImport.relativePath + quote + ");"; });
}
if (options.suggestion.atomTS_IsES6Import) {
var row = options.editor.getCursorBufferPosition().row;
Expand Down
11 changes: 6 additions & 5 deletions lib/main/atom/autoCompleteProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -214,13 +214,14 @@ export var provider: autocompleteplus.Provider = {
if (options.suggestion.atomTS_IsImport) {
options.editor.moveToBeginningOfLine();
options.editor.selectToEndOfLine();
var groups = /^\s*import\s*(\w*)\s*=\s*require\s*\(\s*(["'])/.exec(options.editor.getSelectedText());
var alias = groups[1];
var groups = /^(\s*)import\s*(\w*)\s*=\s*require\s*\(\s*(["'])/.exec(options.editor.getSelectedText());
var leadingWhiteSpace = groups[1];
var alias = groups[2];

// Use the option if they have a preferred. Otherwise preserve
quote = quote || groups[2];

options.editor.replaceSelectedText(null, function() { return `import ${alias} = require(${quote}${options.suggestion.atomTS_IsImport.relativePath}${quote});`; });
quote = quote || groups[3];
options.editor.replaceSelectedText(null, function() { return `${leadingWhiteSpace}import ${alias} = require(${quote}${options.suggestion.atomTS_IsImport.relativePath}${quote});`; });
}
if (options.suggestion.atomTS_IsES6Import) {
var {row} = options.editor.getCursorBufferPosition();
Expand Down

0 comments on commit 55bcc17

Please sign in to comment.