Skip to content
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

Display leading and trailing whitespaces in search-in-workspace results #5989

Merged
merged 1 commit into from
Aug 20, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -649,7 +649,7 @@ export class SearchInWorkspaceResultTreeWidget extends TreeWidget {
const replaceTerm = this._replaceTerm !== '' && this._showReplaceButtons ? <span className='replace-term'>{this._replaceTerm}</span> : '';
const className = `match${this._showReplaceButtons ? ' strike-through' : ''}`;
return <React.Fragment>
<span className={className}> {node.lineText.substr(node.character - 1, node.length)}</span>
<span className={className}>{node.lineText.substr(node.character - 1, node.length)}</span>
vince-fugnitto marked this conversation as resolved.
Show resolved Hide resolved
{replaceTerm}
</React.Fragment>;
}
Expand Down
1 change: 1 addition & 0 deletions packages/search-in-workspace/src/browser/styles/index.css
Original file line number Diff line number Diff line change
Expand Up @@ -255,6 +255,7 @@
background: var(--theia-word-highlight-match-color1);
display: inline-block;
line-height: normal;
white-space: pre;
vince-fugnitto marked this conversation as resolved.
Show resolved Hide resolved
}

.t-siw-search-container .resultLine .match.strike-through {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ const getRootPathFromName = (name: string) => {
const names: { [file: string]: string } = {
carrots: rootDirA,
potatoes: rootDirA,
pastas: rootDirA,
regexes: rootDirA,
small: `${rootDirA}/small`,
'file:with:some:colons': rootDirA,
Expand Down Expand Up @@ -111,6 +112,8 @@ Potatoes, unlike carrots, are generally not orange. But sweet potatoes are,
it's very confusing.
`);

createTestFile('pastas', 'pasta pasta');

createTestFile('regexes', `\
aaa hello. x h3lo y hell0h3lllo
hello1
Expand Down Expand Up @@ -231,6 +234,34 @@ function compareSearchResults(expected: SearchInWorkspaceResult[], actual: Searc
describe('ripgrep-search-in-workspace-server', function (): void {
this.timeout(10000);

it('should return 1 result when searching for " pasta", respecting the leading whitespace', done => {
const pattern = ' pasta';

const client = new ResultAccumulator(() => {
const expected: SearchInWorkspaceResult[] = [
{ root: rootDirAUri, fileUri: 'pastas', line: 1, character: 6, length: pattern.length, lineText: '' },
];
compareSearchResults(expected, client.results);
done();
});
ripgrepServer.setClient(client);
ripgrepServer.search(pattern, [rootDirAUri]);
});

it('should return 1 result when searching for "pasta", respecting the trailing whitespace', done => {
const pattern = 'pasta ';

const client = new ResultAccumulator(() => {
const expected: SearchInWorkspaceResult[] = [
{ root: rootDirAUri, fileUri: 'pastas', line: 1, character: 1, length: pattern.length, lineText: '' },
];
compareSearchResults(expected, client.results);
done();
});
ripgrepServer.setClient(client);
ripgrepServer.search(pattern, [rootDirAUri]);
});

// Try some simple patterns with different case.
it('should return 7 results when searching for "carrot"', done => {
const pattern = 'carrot';
Expand Down