diff --git a/demo/client.ts b/demo/client.ts
index 099aab14..5c477ae7 100644
--- a/demo/client.ts
+++ b/demo/client.ts
@@ -103,7 +103,7 @@ function createTerminal(): void {
const searchOptions = {
regex: (document.getElementById('regex') as HTMLInputElement).checked,
wholeWord: false,
- caseSensitive: false
+ caseSensitive: (document.getElementById('case-sensitive') as HTMLInputElement).checked
};
term.findNext(actionElements.findNext.value, searchOptions);
}
@@ -114,7 +114,7 @@ function createTerminal(): void {
const searchOptions = {
regex: (document.getElementById('regex') as HTMLInputElement).checked,
wholeWord: false,
- caseSensitive: false
+ caseSensitive: (document.getElementById('case-sensitive') as HTMLInputElement).checked
};
term.findPrevious(actionElements.findPrevious.value, searchOptions);
}
diff --git a/demo/index.html b/demo/index.html
index ae29d135..553b9a8b 100644
--- a/demo/index.html
+++ b/demo/index.html
@@ -17,6 +17,7 @@
+
diff --git a/src/addons/search/SearchHelper.ts b/src/addons/search/SearchHelper.ts
index 4cc13e63..f89eb77e 100644
--- a/src/addons/search/SearchHelper.ts
+++ b/src/addons/search/SearchHelper.ts
@@ -113,18 +113,21 @@ export class SearchHelper implements ISearchHelper {
if (this._terminal._core.buffer.lines.get(y).isWrapped) {
return;
}
- const lowerStringLine = this.translateBufferLineToStringWithWrap(y, true).toLowerCase();
- const lowerTerm = term.toLowerCase();
+
+ const stringLine = this.translateBufferLineToStringWithWrap(y, true);
+ const searchStringLine = searchOptions.caseSensitive ? stringLine : stringLine.toLowerCase();
+ const searchTerm = searchOptions.caseSensitive ? term : term.toLowerCase();
let searchIndex = -1;
+
if (searchOptions.regex) {
- const searchRegex = RegExp(lowerTerm, 'g');
- const foundTerm = searchRegex.exec(lowerStringLine);
+ const searchRegex = RegExp(searchTerm, 'g');
+ const foundTerm = searchRegex.exec(searchStringLine);
if (foundTerm && foundTerm[0].length > 0) {
searchIndex = searchRegex.lastIndex - foundTerm[0].length;
term = foundTerm[0];
}
} else {
- searchIndex = lowerStringLine.indexOf(lowerTerm);
+ searchIndex = searchStringLine.indexOf(searchTerm);
}
if (searchIndex >= 0) {
@@ -170,10 +173,10 @@ export class SearchHelper implements ISearchHelper {
let lineWrapsToNext: boolean;
do {
- lineString += this._terminal._core.buffer.translateBufferLineToString(lineIndex, true);
+ const nextLine = this._terminal._core.buffer.lines.get(lineIndex + 1);
+ lineWrapsToNext = nextLine ? nextLine.isWrapped : false;
+ lineString += this._terminal._core.buffer.translateBufferLineToString(lineIndex, !lineWrapsToNext && trimRight);
lineIndex++;
- const nextLine = this._terminal._core.buffer.lines.get(lineIndex);
- lineWrapsToNext = nextLine ? this._terminal._core.buffer.lines.get(lineIndex).isWrapped : false;
} while (lineWrapsToNext);
return lineString;
diff --git a/src/addons/search/search.test.ts b/src/addons/search/search.test.ts
index 014b01d8..38a04df5 100644
--- a/src/addons/search/search.test.ts
+++ b/src/addons/search/search.test.ts
@@ -59,14 +59,15 @@ describe('search addon', () => {
search.apply(
MockTerminal);
const term = new MockTerminal({cols: 10, rows: 5});
term.core.write('texttextHellotext\r\n');
- term.core.write('texttexttextHellotext');
+ term.core.write('texttexttextHellotext goodbye');
term.pushWriteData();
/*
texttextHe
llotext
texttextte
xtHellotex
- t
+ t (these spaces included intentionally)
+ goodbye
*/
const hello0 = (term.searchHelper as any)._findInLine('Hello', 0);
@@ -74,11 +75,13 @@ describe('search addon', () => {
const hello2 = (term.searchHelper as any)._findInLine('Hello', 2);
const hello3 = (term.searchHelper as any)._findInLine('Hello', 3);
const llo = (term.searchHelper as any)._findInLine('llo', 1);
+ const goodbye = (term.searchHelper as any)._findInLine('goodbye', 2);
expect(hello0).eql({col: 8, row: 0, term: 'Hello'});
expect(hello1).eql(undefined);
expect(hello2).eql({col: 2, row: 3, term: 'Hello'});
expect(hello3).eql(undefined);
expect(llo).eql(undefined);
+ expect(goodbye).eql({col: 0, row: 5, term: 'goodbye'});
});
it('should respect search regex', () => {
search.apply(MockTerminal);
@@ -117,5 +120,47 @@ describe('search addon', () => {
const line = term.searchHelper.findInLine('^.*$', 0, { regex: true });
expect(line).eql(undefined);
});
+ it('should respect case sensitive', function(): void {
+ search.apply(MockTerminal);
+ const term = new MockTerminal({cols: 20, rows: 4});
+ term.core.write('Hello World\r\n123....hello\r\nmoreTestHello');
+ term.pushWriteData();
+ const searchOptions = {
+ regex: false,
+ wholeWord: false,
+ caseSensitive: true
+ };
+ const hello0 = (term.searchHelper as any)._findInLine('Hello', 0, searchOptions);
+ const hello1 = (term.searchHelper as any)._findInLine('Hello', 1, searchOptions);
+ const hello2 = (term.searchHelper as any)._findInLine('Hello', 2, searchOptions);
+ expect(hello0).eql({col: 0, row: 0, term: 'Hello'});
+ expect(hello1).eql(undefined);
+ expect(hello2).eql({col: 8, row: 2, term: 'Hello'});
+ });
+ it('should respect case sensitive + regex', function(): void {
+ search.apply(MockTerminal);
+ const term = new MockTerminal({cols: 20, rows: 4});
+ term.core.write('hellohello\r\nHelloHello');
+ term.pushWriteData();
+
+ /**
+ * hellohello
+ * HelloHello
+ */
+
+ const searchOptions = {
+ regex: true,
+ wholeWord: false,
+ caseSensitive: true
+ };
+ const hello0 = (term.searchHelper as any)._findInLine('Hello', 0, searchOptions);
+ const hello1 = (term.searchHelper as any)._findInLine('Hello$', 0, searchOptions);
+ const hello2 = (term.searchHelper as any)._findInLine('Hello', 1, searchOptions);
+ const hello3 = (term.searchHelper as any)._findInLine('Hello$', 1, searchOptions);
+ expect(hello0).eql(undefined);
+ expect(hello1).eql(undefined);
+ expect(hello2).eql({col: 0, row: 1, term: 'Hello'});
+ expect(hello3).eql({col: 5, row: 1, term: 'Hello'});
+ });
});
});