Skip to content

Using import completion results in import removing prefixed whitespace #783

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
blakeembrey opened this issue Dec 16, 2015 · 5 comments
Closed

Comments

@blakeembrey
Copy link
Member

Sometimes you want/need whitespace - E.g. writing an ambient module definition manually.

@basarat
Copy link
Member

basarat commented Dec 18, 2015

Guidance

This code :

onDidInsertSuggestion: (options) => {
if (options.suggestion.atomTS_IsReference
|| options.suggestion.atomTS_IsImport
|| options.suggestion.atomTS_IsES6Import) {
// '' implies we will preserve their quote character
var quote = (/["']/.exec(atomConfig.preferredQuoteCharacter) || [''])[0];
if (options.suggestion.atomTS_IsReference) {
options.editor.moveToBeginningOfLine();
options.editor.selectToEndOfLine();
options.editor.replaceSelectedText(null, function() { return '/// <reference path="' + options.suggestion.atomTS_IsReference.relativePath + '.ts"/>'; });
}
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];
// 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});`; });
}
if (options.suggestion.atomTS_IsES6Import) {
var {row} = options.editor.getCursorBufferPosition();
var originalText = (<any>options.editor).lineTextForBufferRow(row);
var groups = /(.*)from\s*(["'])/.exec(originalText);
var beforeFrom = groups[1];
// Use the option if they have a preferred. Otherwise preserve
quote = quote || groups[2];
var newTextAfterFrom = `from ${quote}${options.suggestion.atomTS_IsES6Import.relativePath}${quote};`;
options.editor.setTextInBufferRange([[row, beforeFrom.length], [row, originalText.length]], newTextAfterFrom)
}
options.editor.moveToEndOfLine();
}
}
should preserve whitespace 🌹

@blakeembrey Label as up for grabs if want it open for someone else 🌹

@austingreendev
Copy link
Contributor

@blakeembrey I would be willing to take a stab at this one if you want to assignee the issue to me. I've been using this tool for quite a while so I'm looking to give back!

@blakeembrey
Copy link
Member Author

@Austin94 We can't assign issues to people outside the organisation (I know, it'd be cool for GitHub to maybe allow this) but it's all yours if you're willing to work on it! Thank you 👍

@austingreendev
Copy link
Contributor

@blakeembrey Just made pull request #805. Let me know what you think.

@basarat
Copy link
Member

basarat commented Jan 5, 2016

@basarat basarat closed this as completed Jan 5, 2016
@TypeStrong TypeStrong locked and limited conversation to collaborators Jan 20, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

3 participants