xterm-addon-search
Advanced tools
Comparing version 0.2.0-beta2 to 0.2.0-beta3
@@ -1,2 +0,2 @@ | ||
!function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t():"function"==typeof define&&define.amd?define([],t):"object"==typeof exports?exports.SearchAddon=t():e.SearchAddon=t()}(window,function(){return function(e){var t={};function i(n){if(t[n])return t[n].exports;var r=t[n]={i:n,l:!1,exports:{}};return e[n].call(r.exports,r,r.exports,i),r.l=!0,r.exports}return i.m=e,i.c=t,i.d=function(e,t,n){i.o(e,t)||Object.defineProperty(e,t,{enumerable:!0,get:n})},i.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},i.t=function(e,t){if(1&t&&(e=i(e)),8&t)return e;if(4&t&&"object"==typeof e&&e&&e.__esModule)return e;var n=Object.create(null);if(i.r(n),Object.defineProperty(n,"default",{enumerable:!0,value:e}),2&t&&"string"!=typeof e)for(var r in e)i.d(n,r,function(t){return e[t]}.bind(null,r));return n},i.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return i.d(t,"a",t),t},i.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},i.p="",i(i.s=0)}([function(e,t,i){"use strict";Object.defineProperty(t,"__esModule",{value:!0});var n=function(){function e(){this._linesCacheTimeoutId=0}return e.prototype.activate=function(e){this._terminal=e},e.prototype.dispose=function(){},e.prototype.findNext=function(e,t){if(!this._terminal)throw new Error("Cannot use addon until it has been loaded");if(!e||0===e.length)return this._terminal.clearSelection(),!1;var i=0,n=this._terminal.buffer.viewportY;if(this._terminal.hasSelection()){var r=!!t&&t.incremental,o=this._terminal.getSelectionPosition();n=r?o.startRow:o.endRow,i=r?o.startColumn:o.endColumn}this._initLinesCache();for(var s=n,a=i,l=this._terminal.buffer.getLine(s);l&&l.isWrapped;)a+=this._terminal.cols,l=this._terminal.buffer.getLine(--s);var f=this._findInLine(e,s,a,t);if(!f)for(var h=n+1;h<this._terminal.buffer.baseY+this._terminal.rows&&!(f=this._findInLine(e,h,0,t));h++);if(!f)for(h=0;h<s&&!(f=this._findInLine(e,h,0,t));h++);return this._selectResult(f)},e.prototype.findPrevious=function(e,t){if(!this._terminal)throw new Error("Cannot use addon until it has been loaded");if(!e||0===e.length)return this._terminal.clearSelection(),!1;var i=this._terminal.buffer.viewportY+this._terminal.rows-1,n=this._terminal.cols;if(this._terminal.hasSelection()){var r=this._terminal.getSelectionPosition();i=r.startRow,n=r.startColumn}this._initLinesCache();var o=this._findInLine(e,i,n,t,!0);if(!o){var s=this._terminal.cols;this._terminal.buffer.getLine(i).isWrapped&&(s+=n);for(var a=i-1;a>=0&&!(o=this._findInLine(e,a,s,t,!0));a--){(f=this._terminal.buffer.getLine(a))&&f.isWrapped?s+=this._terminal.cols:s=this._terminal.cols}}if(!o){var l=this._terminal.buffer.baseY+this._terminal.rows-1;for(s=this._terminal.cols,a=l;a>=i&&!(o=this._findInLine(e,a,s,t,!0));a--){var f;(f=this._terminal.buffer.getLine(a))&&f.isWrapped?s+=this._terminal.cols:s=this._terminal.cols}}return this._selectResult(o)},e.prototype._initLinesCache=function(){var e=this,t=this._terminal;this._linesCache||(this._linesCache=new Array(t.buffer.length),this._cursorMoveListener=t.onCursorMove(function(){return e._destroyLinesCache()}),this._resizeListener=t.onResize(function(){return e._destroyLinesCache()})),window.clearTimeout(this._linesCacheTimeoutId),this._linesCacheTimeoutId=window.setTimeout(function(){return e._destroyLinesCache()},15e3)},e.prototype._destroyLinesCache=function(){this._linesCache=void 0,this._cursorMoveListener&&(this._cursorMoveListener.dispose(),this._cursorMoveListener=void 0),this._resizeListener&&(this._resizeListener.dispose(),this._resizeListener=void 0),this._linesCacheTimeoutId&&(window.clearTimeout(this._linesCacheTimeoutId),this._linesCacheTimeoutId=0)},e.prototype._isWholeWord=function(e,t,i){return!(0!==e&&-1===" ~!@#$%^&*()+`-=[]{}|;:\"',./<>?".indexOf(t[e-1])||e+i.length!==t.length&&-1===" ~!@#$%^&*()+`-=[]{}|;:\"',./<>?".indexOf(t[e+i.length]))},e.prototype._findInLine=function(e,t,i,n,r){void 0===n&&(n={}),void 0===r&&(r=!1);var o=this._terminal,s=o.buffer.getLine(t);if(!s||!s.isWrapped){var a=this._linesCache?this._linesCache[t]:void 0;void 0===a&&(a=this._translateBufferLineToStringWithWrap(t,!0),this._linesCache&&(this._linesCache[t]=a));var l=n.caseSensitive?e:e.toLowerCase(),f=n.caseSensitive?a:a.toLowerCase(),h=-1;if(n.regex){var u=RegExp(l,"g"),c=void 0;if(r)for(;c=u.exec(f.slice(0,i));)h=u.lastIndex-c[0].length,e=c[0],u.lastIndex-=e.length-1;else(c=u.exec(f.slice(i)))&&c[0].length>0&&(h=i+(u.lastIndex-c[0].length),e=c[0])}else r?i-l.length>=0&&(h=f.lastIndexOf(l,i-l.length)):h=f.indexOf(l,i);if(h>=0){if(h>=o.cols&&(t+=Math.floor(h/o.cols),h%=o.cols),n.wholeWord&&!this._isWholeWord(h,f,e))return;var d=o.buffer.getLine(t);if(d)for(var _=0;_<h;_++){var p=d.getCell(_);if(!p)break;var m=p.char;m.length>1&&(h-=m.length-1),0===p.width&&h++}return{term:e,col:h,row:t}}}},e.prototype._translateBufferLineToStringWithWrap=function(e,t){var i,n=this._terminal,r="";do{var o=n.buffer.getLine(e+1);i=!!o&&o.isWrapped;var s=n.buffer.getLine(e);if(!s)break;r+=s.translateToString(!i&&t).substring(0,n.cols),e++}while(i);return r},e.prototype._selectResult=function(e){var t=this._terminal;if(!e)return t.clearSelection(),!1;t.select(e.col,e.row,e.term.length);var i=e.row-t.buffer.viewportY;return i-=Math.floor(t.rows/2),t.scrollLines(i),!0},e}();t.SearchAddon=n}])}); | ||
!function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t():"function"==typeof define&&define.amd?define([],t):"object"==typeof exports?exports.SearchAddon=t():e.SearchAddon=t()}(window,function(){return function(e){var t={};function i(n){if(t[n])return t[n].exports;var r=t[n]={i:n,l:!1,exports:{}};return e[n].call(r.exports,r,r.exports,i),r.l=!0,r.exports}return i.m=e,i.c=t,i.d=function(e,t,n){i.o(e,t)||Object.defineProperty(e,t,{enumerable:!0,get:n})},i.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},i.t=function(e,t){if(1&t&&(e=i(e)),8&t)return e;if(4&t&&"object"==typeof e&&e&&e.__esModule)return e;var n=Object.create(null);if(i.r(n),Object.defineProperty(n,"default",{enumerable:!0,value:e}),2&t&&"string"!=typeof e)for(var r in e)i.d(n,r,function(t){return e[t]}.bind(null,r));return n},i.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return i.d(t,"a",t),t},i.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},i.p="",i(i.s=0)}([function(e,t,i){"use strict";Object.defineProperty(t,"__esModule",{value:!0});var n=function(){function e(){this._linesCacheTimeoutId=0}return e.prototype.activate=function(e){this._terminal=e},e.prototype.dispose=function(){},e.prototype.findNext=function(e,t){if(!this._terminal)throw new Error("Cannot use addon until it has been loaded");if(!e||0===e.length)return this._terminal.clearSelection(),!1;var i=0,n=0;if(this._terminal.hasSelection()){var r=!!t&&t.incremental,o=this._terminal.getSelectionPosition();n=r?o.startRow:o.endRow,i=r?o.startColumn:o.endColumn}this._initLinesCache();var s=this._findInLine(e,n,i,t);if(!s)for(var a=n+1;a<this._terminal.buffer.baseY+this._terminal.rows&&!(s=this._findInLine(e,a,0,t));a++);if(!s&&0!==n)for(a=0;a<n&&!(s=this._findInLine(e,a,0,t));a++);return this._selectResult(s)},e.prototype.findPrevious=function(e,t){if(!this._terminal)throw new Error("Cannot use addon until it has been loaded");if(!e||0===e.length)return this._terminal.clearSelection(),!1;var i=this._terminal.buffer.baseY+this._terminal.rows,n=this._terminal.cols,r=void 0,o=!!t&&t.incremental;if(this._terminal.hasSelection()){var s=this._terminal.getSelectionPosition();i=s.startRow,n=s.startColumn}if(this._initLinesCache(),o&&(r=this._findInLine(e,i,n,t,!1))&&r.row===i&&r.col===n||(r=this._findInLine(e,i,n,t,!0)),!r){n=this._terminal.cols;for(var a=i-1;a>=0&&!(r=this._findInLine(e,a,n,t,!0));a--);}if(!r&&i!==this._terminal.buffer.baseY+this._terminal.rows)for(a=this._terminal.buffer.baseY+this._terminal.rows;a>i&&!(r=this._findInLine(e,a,n,t,!0));a--);return this._selectResult(r)},e.prototype._initLinesCache=function(){var e=this,t=this._terminal;this._linesCache||(this._linesCache=new Array(t.buffer.length),this._cursorMoveListener=t.onCursorMove(function(){return e._destroyLinesCache()}),this._resizeListener=t.onResize(function(){return e._destroyLinesCache()})),window.clearTimeout(this._linesCacheTimeoutId),this._linesCacheTimeoutId=window.setTimeout(function(){return e._destroyLinesCache()},15e3)},e.prototype._destroyLinesCache=function(){this._linesCache=void 0,this._cursorMoveListener&&(this._cursorMoveListener.dispose(),this._cursorMoveListener=void 0),this._resizeListener&&(this._resizeListener.dispose(),this._resizeListener=void 0),this._linesCacheTimeoutId&&(window.clearTimeout(this._linesCacheTimeoutId),this._linesCacheTimeoutId=0)},e.prototype._isWholeWord=function(e,t,i){return!(0!==e&&-1===" ~!@#$%^&*()+`-=[]{}|;:\"',./<>?".indexOf(t[e-1])||e+i.length!==t.length&&-1===" ~!@#$%^&*()+`-=[]{}|;:\"',./<>?".indexOf(t[e+i.length]))},e.prototype._findInLine=function(e,t,i,n,r){void 0===n&&(n={}),void 0===r&&(r=!1);var o=this._terminal,s=o.buffer.getLine(t);if(!s||!s.isWrapped){var a=this._linesCache?this._linesCache[t]:void 0;void 0===a&&(a=this._translateBufferLineToStringWithWrap(t,!0),this._linesCache&&(this._linesCache[t]=a));var l=n.caseSensitive?e:e.toLowerCase(),f=n.caseSensitive?a:a.toLowerCase(),h=-1;if(n.regex){var u=RegExp(l,"g"),c=void 0;if(r)for(;c=u.exec(f.slice(0,i));)h=u.lastIndex-c[0].length,e=c[0],u.lastIndex-=e.length-1;else(c=u.exec(f.slice(i)))&&c[0].length>0&&(h=i+(u.lastIndex-c[0].length),e=c[0])}else r?i-l.length>=0&&(h=f.lastIndexOf(l,i-l.length)):h=f.indexOf(l,i);if(h>=0){if(h>=o.cols&&(t+=Math.floor(h/o.cols),h%=o.cols),n.wholeWord&&!this._isWholeWord(h,f,e))return;var d=o.buffer.getLine(t);if(d)for(var _=0;_<h;_++){var p=d.getCell(_);if(!p)break;var v=p.char;v.length>1&&(h-=v.length-1),0===p.width&&h++}return{term:e,col:h,row:t}}}},e.prototype._translateBufferLineToStringWithWrap=function(e,t){var i,n=this._terminal,r="";do{var o=n.buffer.getLine(e+1);i=!!o&&o.isWrapped;var s=n.buffer.getLine(e);if(!s)break;r+=s.translateToString(!i&&t).substring(0,n.cols),e++}while(i);return r},e.prototype._selectResult=function(e){var t=this._terminal;if(!e)return t.clearSelection(),!1;t.select(e.col,e.row,e.term.length);var i=e.row-t.buffer.viewportY;return i-=Math.floor(t.rows/2),t.scrollLines(i),!0},e}();t.SearchAddon=n}])}); | ||
//# sourceMappingURL=xterm-addon-search.js.map |
@@ -22,3 +22,3 @@ "use strict"; | ||
var startCol = 0; | ||
var startRow = this._terminal.buffer.viewportY; | ||
var startRow = 0; | ||
if (this._terminal.hasSelection()) { | ||
@@ -31,10 +31,3 @@ var incremental = searchOptions ? searchOptions.incremental : false; | ||
this._initLinesCache(); | ||
var findingRow = startRow; | ||
var cumulativeCols = startCol; | ||
var currentLine = this._terminal.buffer.getLine(findingRow); | ||
while (currentLine && currentLine.isWrapped) { | ||
cumulativeCols += this._terminal.cols; | ||
currentLine = this._terminal.buffer.getLine(--findingRow); | ||
} | ||
var result = this._findInLine(term, findingRow, cumulativeCols, searchOptions); | ||
var result = this._findInLine(term, startRow, startCol, searchOptions); | ||
if (!result) { | ||
@@ -48,4 +41,4 @@ for (var y = startRow + 1; y < this._terminal.buffer.baseY + this._terminal.rows; y++) { | ||
} | ||
if (!result) { | ||
for (var y = 0; y < findingRow; y++) { | ||
if (!result && startRow !== 0) { | ||
for (var y = 0; y < startRow; y++) { | ||
result = this._findInLine(term, y, 0, searchOptions); | ||
@@ -68,4 +61,6 @@ if (result) { | ||
var isReverseSearch = true; | ||
var startRow = this._terminal.buffer.viewportY + this._terminal.rows - 1; | ||
var startRow = this._terminal.buffer.baseY + this._terminal.rows; | ||
var startCol = this._terminal.cols; | ||
var result = undefined; | ||
var incremental = searchOptions ? searchOptions.incremental : false; | ||
if (this._terminal.hasSelection()) { | ||
@@ -77,37 +72,26 @@ var currentSelection = this._terminal.getSelectionPosition(); | ||
this._initLinesCache(); | ||
var result = this._findInLine(term, startRow, startCol, searchOptions, isReverseSearch); | ||
if (incremental) { | ||
result = this._findInLine(term, startRow, startCol, searchOptions, false); | ||
if (!(result && result.row === startRow && result.col === startCol)) { | ||
result = this._findInLine(term, startRow, startCol, searchOptions, true); | ||
} | ||
} | ||
else { | ||
result = this._findInLine(term, startRow, startCol, searchOptions, isReverseSearch); | ||
} | ||
if (!result) { | ||
var cumulativeCols = this._terminal.cols; | ||
if (this._terminal.buffer.getLine(startRow).isWrapped) { | ||
cumulativeCols += startCol; | ||
} | ||
startCol = this._terminal.cols; | ||
for (var y = startRow - 1; y >= 0; y--) { | ||
result = this._findInLine(term, y, cumulativeCols, searchOptions, isReverseSearch); | ||
result = this._findInLine(term, y, startCol, searchOptions, isReverseSearch); | ||
if (result) { | ||
break; | ||
} | ||
var line = this._terminal.buffer.getLine(y); | ||
if (line && line.isWrapped) { | ||
cumulativeCols += this._terminal.cols; | ||
} | ||
else { | ||
cumulativeCols = this._terminal.cols; | ||
} | ||
} | ||
} | ||
if (!result) { | ||
var searchFrom = this._terminal.buffer.baseY + this._terminal.rows - 1; | ||
var cumulativeCols = this._terminal.cols; | ||
for (var y = searchFrom; y >= startRow; y--) { | ||
result = this._findInLine(term, y, cumulativeCols, searchOptions, isReverseSearch); | ||
if (!result && startRow !== (this._terminal.buffer.baseY + this._terminal.rows)) { | ||
for (var y = (this._terminal.buffer.baseY + this._terminal.rows); y > startRow; y--) { | ||
result = this._findInLine(term, y, startCol, searchOptions, isReverseSearch); | ||
if (result) { | ||
break; | ||
} | ||
var line = this._terminal.buffer.getLine(y); | ||
if (line && line.isWrapped) { | ||
cumulativeCols += this._terminal.cols; | ||
} | ||
else { | ||
cumulativeCols = this._terminal.cols; | ||
} | ||
} | ||
@@ -114,0 +98,0 @@ } |
{ | ||
"name": "xterm-addon-search", | ||
"version": "0.2.0-beta2", | ||
"version": "0.2.0-beta3", | ||
"author": { | ||
@@ -5,0 +5,0 @@ "name": "The xterm.js authors", |
@@ -60,4 +60,4 @@ /** | ||
let startCol: number = 0; | ||
let startRow = this._terminal.buffer.viewportY; | ||
let startCol = 0; | ||
let startRow = 0; | ||
@@ -75,16 +75,4 @@ if (this._terminal.hasSelection()) { | ||
// A row that has isWrapped = false | ||
let findingRow = startRow; | ||
// index of beginning column that _findInLine need to scan. | ||
let cumulativeCols = startCol; | ||
// If startRow is wrapped row, scan for unwrapped row above. | ||
// So we can start matching on wrapped line from long unwrapped line. | ||
let currentLine = this._terminal.buffer.getLine(findingRow); | ||
while (currentLine && currentLine.isWrapped) { | ||
cumulativeCols += this._terminal.cols; | ||
currentLine = this._terminal.buffer.getLine(--findingRow); | ||
} | ||
// Search startRow | ||
let result = this._findInLine(term, findingRow, cumulativeCols, searchOptions); | ||
let result = this._findInLine(term, startRow, startCol, searchOptions); | ||
@@ -104,7 +92,5 @@ // Search from startRow + 1 to end | ||
} | ||
// Search from the top to the startRow (search the whole startRow again in | ||
// case startCol > 0) | ||
if (!result) { | ||
for (let y = 0; y < findingRow; y++) { | ||
// If we hit the bottom and didn't search from the very top wrap back up | ||
if (!result && startRow !== 0) { | ||
for (let y = 0; y < startRow; y++) { | ||
result = this._findInLine(term, y, 0, searchOptions); | ||
@@ -139,8 +125,9 @@ if (result) { | ||
const isReverseSearch = true; | ||
let startRow = this._terminal.buffer.viewportY + this._terminal.rows - 1; | ||
let startRow = this._terminal.buffer.baseY + this._terminal.rows; | ||
let startCol = this._terminal.cols; | ||
let result: ISearchResult | undefined = undefined; | ||
const incremental = searchOptions ? searchOptions.incremental : false; | ||
if (this._terminal.hasSelection()) { | ||
// Start from the selection start if there is a selection | ||
const currentSelection = this._terminal.getSelectionPosition()!; | ||
// Start from selection start if there is a selection | ||
startRow = currentSelection.startRow; | ||
@@ -152,45 +139,28 @@ startCol = currentSelection.startColumn; | ||
// Search startRow | ||
let result = this._findInLine(term, startRow, startCol, searchOptions, isReverseSearch); | ||
if (incremental) { | ||
result = this._findInLine(term, startRow, startCol, searchOptions, false); | ||
if (!(result && result.row === startRow && result.col === startCol)) { | ||
result = this._findInLine(term, startRow, startCol, searchOptions, true); | ||
} | ||
} else { | ||
result = this._findInLine(term, startRow, startCol, searchOptions, isReverseSearch); | ||
} | ||
// Search from startRow - 1 to top | ||
if (!result) { | ||
// If the line is wrapped line, increase number of columns that is needed to be scanned | ||
// Se we can scan on wrapped line from unwrapped line | ||
let cumulativeCols = this._terminal.cols; | ||
if (this._terminal.buffer.getLine(startRow)!.isWrapped) { | ||
cumulativeCols += startCol; | ||
} | ||
startCol = this._terminal.cols; | ||
for (let y = startRow - 1; y >= 0; y--) { | ||
result = this._findInLine(term, y, cumulativeCols, searchOptions, isReverseSearch); | ||
result = this._findInLine(term, y, startCol, searchOptions, isReverseSearch); | ||
if (result) { | ||
break; | ||
} | ||
// If the current line is wrapped line, increase scanning range, | ||
// preparing for scanning on unwrapped line | ||
const line = this._terminal.buffer.getLine(y); | ||
if (line && line.isWrapped) { | ||
cumulativeCols += this._terminal.cols; | ||
} else { | ||
cumulativeCols = this._terminal.cols; | ||
} | ||
} | ||
} | ||
// Search from the bottom to startRow (search the whole startRow again in | ||
// case startCol > 0) | ||
if (!result) { | ||
const searchFrom = this._terminal.buffer.baseY + this._terminal.rows - 1; | ||
let cumulativeCols = this._terminal.cols; | ||
for (let y = searchFrom; y >= startRow; y--) { | ||
result = this._findInLine(term, y, cumulativeCols, searchOptions, isReverseSearch); | ||
// If we hit the top and didn't search from the very bottom wrap back down | ||
if (!result && startRow !== (this._terminal.buffer.baseY + this._terminal.rows)) { | ||
for (let y = (this._terminal.buffer.baseY + this._terminal.rows); y > startRow; y--) { | ||
result = this._findInLine(term, y, startCol, searchOptions, isReverseSearch); | ||
if (result) { | ||
break; | ||
} | ||
const line = this._terminal.buffer.getLine(y); | ||
if (line && line.isWrapped) { | ||
cumulativeCols += this._terminal.cols; | ||
} else { | ||
cumulativeCols = this._terminal.cols; | ||
} | ||
} | ||
@@ -197,0 +167,0 @@ } |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
68936
9
624