react-terminal-viewer-cicd 2.0.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +181 -0
- package/dist/esm/Addon/EventEmiter.d.ts +18 -0
- package/dist/esm/Addon/EventEmiter.js +64 -0
- package/dist/esm/Addon/HighlightAddon.d.ts +26 -0
- package/dist/esm/Addon/HighlightAddon.js +188 -0
- package/dist/esm/Addon/SearchAddon.d.ts +140 -0
- package/dist/esm/Addon/SearchAddon.js +797 -0
- package/dist/esm/Addon/WorkerLog/GlobalContext.d.ts +10 -0
- package/dist/esm/Addon/WorkerLog/GlobalContext.js +37 -0
- package/dist/esm/Addon/WorkerLog/LimitMap.d.ts +14 -0
- package/dist/esm/Addon/WorkerLog/LimitMap.js +54 -0
- package/dist/esm/Addon/WorkerLog/LogWorker.d.ts +2 -0
- package/dist/esm/Addon/WorkerLog/LogWorker.js +13 -0
- package/dist/esm/Addon/WorkerLog/Logs.d.ts +21 -0
- package/dist/esm/Addon/WorkerLog/Logs.js +60 -0
- package/dist/esm/Addon/WorkerLog/Mark.d.ts +36 -0
- package/dist/esm/Addon/WorkerLog/Mark.js +155 -0
- package/dist/esm/Addon/WorkerLog/Searcher.d.ts +16 -0
- package/dist/esm/Addon/WorkerLog/Searcher.js +88 -0
- package/dist/esm/Addon/WorkerLog/WebWokerServer.d.ts +10 -0
- package/dist/esm/Addon/WorkerLog/WebWokerServer.js +57 -0
- package/dist/esm/Addon/WorkerLog/WebWorkerClient.d.ts +13 -0
- package/dist/esm/Addon/WorkerLog/WebWorkerClient.js +83 -0
- package/dist/esm/Addon/WorkerLog/log.worker.d.ts +1 -0
- package/dist/esm/Addon/WorkerLog/log.worker.js +63 -0
- package/dist/esm/Addon/WorkerLog/types.d.ts +18 -0
- package/dist/esm/Addon/WorkerLog/types.js +1 -0
- package/dist/esm/Addon/useAddon.d.ts +9 -0
- package/dist/esm/Addon/useAddon.js +33 -0
- package/dist/esm/Hooks/useBatchProcess.d.ts +2 -0
- package/dist/esm/Hooks/useBatchProcess.js +47 -0
- package/dist/esm/Hooks/useCache.d.ts +31 -0
- package/dist/esm/Hooks/useCache.js +206 -0
- package/dist/esm/Hooks/useDebounceInput.d.ts +3 -0
- package/dist/esm/Hooks/useDebounceInput.js +26 -0
- package/dist/esm/Hooks/useLocalStore.d.ts +2 -0
- package/dist/esm/Hooks/useLocalStore.js +9 -0
- package/dist/esm/Hooks/useRemote.d.ts +30 -0
- package/dist/esm/Hooks/useRemote.js +398 -0
- package/dist/esm/Hooks/useThrottle.d.ts +2 -0
- package/dist/esm/Hooks/useThrottle.js +13 -0
- package/dist/esm/Hooks/useWorkerLogs.d.ts +9 -0
- package/dist/esm/Hooks/useWorkerLogs.js +162 -0
- package/dist/esm/TerminalViewer/index.d.ts +185 -0
- package/dist/esm/TerminalViewer/index.js +292 -0
- package/dist/esm/TerminalViewer/index.less +17 -0
- package/dist/esm/TerminalViewerBody/index.d.ts +87 -0
- package/dist/esm/TerminalViewerBody/index.js +248 -0
- package/dist/esm/TerminalViewerBody/index.less +51 -0
- package/dist/esm/TerminalViewerHeader/index.d.ts +88 -0
- package/dist/esm/TerminalViewerHeader/index.js +129 -0
- package/dist/esm/TerminalViewerHeader/index.less +143 -0
- package/dist/esm/TerminalViewerToolBar/index.d.ts +46 -0
- package/dist/esm/TerminalViewerToolBar/index.js +28 -0
- package/dist/esm/TerminalViewerToolBar/index.less +32 -0
- package/dist/esm/TerminalViewerVirtualDom/index.d.ts +71 -0
- package/dist/esm/TerminalViewerVirtualDom/index.js +309 -0
- package/dist/esm/TerminalViewerVirtualDom/index.less +68 -0
- package/dist/esm/index.d.ts +9 -0
- package/dist/esm/index.js +9 -0
- package/dist/esm/mock/index.d.ts +12 -0
- package/dist/esm/mock/index.js +98 -0
- package/dist/esm/types.d.ts +30 -0
- package/dist/esm/types.js +1 -0
- package/dist/worker/Addon/EventEmiter.d.ts +18 -0
- package/dist/worker/Addon/HighlightAddon.d.ts +26 -0
- package/dist/worker/Addon/SearchAddon.d.ts +140 -0
- package/dist/worker/Addon/WorkerLog/GlobalContext.d.ts +10 -0
- package/dist/worker/Addon/WorkerLog/LimitMap.d.ts +14 -0
- package/dist/worker/Addon/WorkerLog/LogWorker.d.ts +2 -0
- package/dist/worker/Addon/WorkerLog/Logs.d.ts +21 -0
- package/dist/worker/Addon/WorkerLog/Mark.d.ts +36 -0
- package/dist/worker/Addon/WorkerLog/Searcher.d.ts +16 -0
- package/dist/worker/Addon/WorkerLog/WebWokerServer.d.ts +10 -0
- package/dist/worker/Addon/WorkerLog/WebWorkerClient.d.ts +13 -0
- package/dist/worker/Addon/WorkerLog/log.worker.d.ts +1 -0
- package/dist/worker/Addon/WorkerLog/types.d.ts +18 -0
- package/dist/worker/Addon/useAddon.d.ts +9 -0
- package/dist/worker/Hooks/useBatchProcess.d.ts +2 -0
- package/dist/worker/Hooks/useCache.d.ts +31 -0
- package/dist/worker/Hooks/useDebounceInput.d.ts +3 -0
- package/dist/worker/Hooks/useLocalStore.d.ts +2 -0
- package/dist/worker/Hooks/useRemote.d.ts +30 -0
- package/dist/worker/Hooks/useRemote.test.d.ts +1 -0
- package/dist/worker/Hooks/useThrottle.d.ts +2 -0
- package/dist/worker/Hooks/useWorkerLogs.d.ts +9 -0
- package/dist/worker/TerminalViewer/index.d.ts +185 -0
- package/dist/worker/TerminalViewer/index.test.d.ts +1 -0
- package/dist/worker/TerminalViewerBody/index.d.ts +87 -0
- package/dist/worker/TerminalViewerBody/index.test.d.ts +1 -0
- package/dist/worker/TerminalViewerHeader/index.d.ts +88 -0
- package/dist/worker/TerminalViewerToolBar/index.d.ts +46 -0
- package/dist/worker/TerminalViewerVirtualDom/index.d.ts +71 -0
- package/dist/worker/index.d.ts +9 -0
- package/dist/worker/log.worker.js +2 -0
- package/dist/worker/log.worker.js.map +1 -0
- package/dist/worker/mock/index.d.ts +12 -0
- package/dist/worker/types.d.ts +30 -0
- package/package.json +97 -0
|
@@ -0,0 +1,797 @@
|
|
|
1
|
+
function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
|
|
2
|
+
function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
|
|
3
|
+
function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
|
|
4
|
+
function _iterableToArrayLimit(r, l) { var t = null == r ? null : "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (null != t) { var e, n, i, u, a = [], f = !0, o = !1; try { if (i = (t = t.call(r)).next, 0 === l) { if (Object(t) !== t) return; f = !1; } else for (; !(f = (e = i.call(t)).done) && (a.push(e.value), a.length !== l); f = !0); } catch (r) { o = !0, n = r; } finally { try { if (!f && null != t.return && (u = t.return(), Object(u) !== u)) return; } finally { if (o) throw n; } } return a; } }
|
|
5
|
+
function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
|
|
6
|
+
function _createForOfIteratorHelper(o, allowArrayLike) { var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"]; if (!it) { if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") { if (it) o = it; var i = 0; var F = function F() {}; return { s: F, n: function n() { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }, e: function e(_e) { throw _e; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var normalCompletion = true, didErr = false, err; return { s: function s() { it = it.call(o); }, n: function n() { var step = it.next(); normalCompletion = step.done; return step; }, e: function e(_e2) { didErr = true; err = _e2; }, f: function f() { try { if (!normalCompletion && it.return != null) it.return(); } finally { if (didErr) throw err; } } }; }
|
|
7
|
+
function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
|
|
8
|
+
function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; }
|
|
9
|
+
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
|
|
10
|
+
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
|
|
11
|
+
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
|
12
|
+
function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, _toPropertyKey(descriptor.key), descriptor); } }
|
|
13
|
+
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
|
|
14
|
+
function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
|
15
|
+
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : String(i); }
|
|
16
|
+
function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
|
|
17
|
+
/* eslint-disable no-restricted-syntax */
|
|
18
|
+
/* eslint-disable prefer-destructuring */
|
|
19
|
+
/* eslint-disable no-cond-assign */
|
|
20
|
+
/* eslint-disable consistent-return */
|
|
21
|
+
/* eslint-disable no-plusplus */
|
|
22
|
+
/* eslint-disable max-len */
|
|
23
|
+
/* eslint-disable no-param-reassign */
|
|
24
|
+
/* eslint-disable class-methods-use-this */
|
|
25
|
+
/* eslint-disable @typescript-eslint/no-non-null-assertion */
|
|
26
|
+
/* eslint-disable no-underscore-dangle */
|
|
27
|
+
/**
|
|
28
|
+
* 从 https://github.com/xtermjs/xterm.js/blob/master/addons/xterm-addon-search/src/SearchAddon.ts 复制以解决部分问题
|
|
29
|
+
*/
|
|
30
|
+
|
|
31
|
+
import EventEmitter from "./EventEmiter";
|
|
32
|
+
var NON_WORD_CHARACTERS = ' ~!@#$%^&*()+`-=[]{}|\\;:"\',./<>?';
|
|
33
|
+
var LINES_CACHE_TIME_TO_LIVE = 15 * 1000; // 15 secs
|
|
34
|
+
|
|
35
|
+
export var SearchAddon = /*#__PURE__*/function () {
|
|
36
|
+
function SearchAddon() {
|
|
37
|
+
_classCallCheck(this, SearchAddon);
|
|
38
|
+
_defineProperty(this, "_terminal", void 0);
|
|
39
|
+
_defineProperty(this, "_cachedSearchTerm", void 0);
|
|
40
|
+
_defineProperty(this, "_selectedDecoration", void 0);
|
|
41
|
+
_defineProperty(this, "_resultDecorations", void 0);
|
|
42
|
+
_defineProperty(this, "_searchResults", void 0);
|
|
43
|
+
_defineProperty(this, "_onDataDisposable", void 0);
|
|
44
|
+
_defineProperty(this, "_onResizeDisposable", void 0);
|
|
45
|
+
_defineProperty(this, "_lastSearchOptions", void 0);
|
|
46
|
+
_defineProperty(this, "_highlightTimeout", void 0);
|
|
47
|
+
/**
|
|
48
|
+
* translateBufferLineToStringWithWrap is a fairly expensive call.
|
|
49
|
+
* We memoize the calls into an array that has a time based ttl.
|
|
50
|
+
* _linesCache is also invalidated when the terminal cursor moves.
|
|
51
|
+
*/
|
|
52
|
+
_defineProperty(this, "_linesCache", void 0);
|
|
53
|
+
_defineProperty(this, "_linesCacheTimeoutId", 0);
|
|
54
|
+
_defineProperty(this, "_cursorMoveListener", void 0);
|
|
55
|
+
_defineProperty(this, "_resizeListener", void 0);
|
|
56
|
+
_defineProperty(this, "_resultIndex", void 0);
|
|
57
|
+
_defineProperty(this, "_onDidChangeResults", new EventEmitter());
|
|
58
|
+
_defineProperty(this, "onDidChangeResults", this._onDidChangeResults.event);
|
|
59
|
+
}
|
|
60
|
+
_createClass(SearchAddon, [{
|
|
61
|
+
key: "activate",
|
|
62
|
+
value: function activate(terminal) {
|
|
63
|
+
var _this = this;
|
|
64
|
+
this._terminal = terminal;
|
|
65
|
+
this._onDataDisposable = this._terminal.onWriteParsed(function () {
|
|
66
|
+
return _this._updateMatches();
|
|
67
|
+
});
|
|
68
|
+
this._onResizeDisposable = this._terminal.onResize(function () {
|
|
69
|
+
return _this._updateMatches();
|
|
70
|
+
});
|
|
71
|
+
}
|
|
72
|
+
}, {
|
|
73
|
+
key: "_updateMatches",
|
|
74
|
+
value: function _updateMatches() {
|
|
75
|
+
var _this$_lastSearchOpti,
|
|
76
|
+
_this2 = this;
|
|
77
|
+
if (this._highlightTimeout) {
|
|
78
|
+
window.clearTimeout(this._highlightTimeout);
|
|
79
|
+
}
|
|
80
|
+
if (this._cachedSearchTerm && (_this$_lastSearchOpti = this._lastSearchOptions) !== null && _this$_lastSearchOpti !== void 0 && _this$_lastSearchOpti.decorations) {
|
|
81
|
+
this._highlightTimeout = setTimeout(function () {
|
|
82
|
+
var _this2$_searchResults, _this2$_searchResults2;
|
|
83
|
+
_this2.findPrevious(_this2._cachedSearchTerm, _objectSpread(_objectSpread({}, _this2._lastSearchOptions), {}, {
|
|
84
|
+
incremental: true,
|
|
85
|
+
noScroll: true
|
|
86
|
+
}));
|
|
87
|
+
_this2._resultIndex = _this2._searchResults ? _this2._searchResults.size - 1 : -1;
|
|
88
|
+
_this2._onDidChangeResults.fire({
|
|
89
|
+
resultIndex: _this2._resultIndex,
|
|
90
|
+
resultCount: (_this2$_searchResults = (_this2$_searchResults2 = _this2._searchResults) === null || _this2$_searchResults2 === void 0 ? void 0 : _this2$_searchResults2.size) !== null && _this2$_searchResults !== void 0 ? _this2$_searchResults : -1
|
|
91
|
+
});
|
|
92
|
+
}, 200);
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
}, {
|
|
96
|
+
key: "dispose",
|
|
97
|
+
value: function dispose() {
|
|
98
|
+
var _this$_onDataDisposab, _this$_onResizeDispos;
|
|
99
|
+
this.clearDecorations();
|
|
100
|
+
(_this$_onDataDisposab = this._onDataDisposable) === null || _this$_onDataDisposab === void 0 || _this$_onDataDisposab.dispose();
|
|
101
|
+
(_this$_onResizeDispos = this._onResizeDisposable) === null || _this$_onResizeDispos === void 0 || _this$_onResizeDispos.dispose();
|
|
102
|
+
}
|
|
103
|
+
}, {
|
|
104
|
+
key: "clearDecorations",
|
|
105
|
+
value: function clearDecorations(retainCachedSearchTerm) {
|
|
106
|
+
var _this$_selectedDecora, _this$_searchResults, _this$_resultDecorati, _this$_resultDecorati2;
|
|
107
|
+
(_this$_selectedDecora = this._selectedDecoration) === null || _this$_selectedDecora === void 0 || _this$_selectedDecora.dispose();
|
|
108
|
+
(_this$_searchResults = this._searchResults) === null || _this$_searchResults === void 0 || _this$_searchResults.clear();
|
|
109
|
+
(_this$_resultDecorati = this._resultDecorations) === null || _this$_resultDecorati === void 0 || _this$_resultDecorati.forEach(function (decorations) {
|
|
110
|
+
var _iterator = _createForOfIteratorHelper(decorations),
|
|
111
|
+
_step;
|
|
112
|
+
try {
|
|
113
|
+
for (_iterator.s(); !(_step = _iterator.n()).done;) {
|
|
114
|
+
var d = _step.value;
|
|
115
|
+
d.dispose();
|
|
116
|
+
}
|
|
117
|
+
} catch (err) {
|
|
118
|
+
_iterator.e(err);
|
|
119
|
+
} finally {
|
|
120
|
+
_iterator.f();
|
|
121
|
+
}
|
|
122
|
+
});
|
|
123
|
+
(_this$_resultDecorati2 = this._resultDecorations) === null || _this$_resultDecorati2 === void 0 || _this$_resultDecorati2.clear();
|
|
124
|
+
this._searchResults = undefined;
|
|
125
|
+
this._resultDecorations = undefined;
|
|
126
|
+
if (!retainCachedSearchTerm) {
|
|
127
|
+
this._cachedSearchTerm = undefined;
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
}, {
|
|
131
|
+
key: "clearActiveDecoration",
|
|
132
|
+
value: function clearActiveDecoration() {
|
|
133
|
+
var _this$_selectedDecora2;
|
|
134
|
+
(_this$_selectedDecora2 = this._selectedDecoration) === null || _this$_selectedDecora2 === void 0 || _this$_selectedDecora2.dispose();
|
|
135
|
+
this._selectedDecoration = undefined;
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
/**
|
|
139
|
+
* Find the next instance of the term, then scroll to and select it. If it
|
|
140
|
+
* doesn't exist, do nothing.
|
|
141
|
+
* @param term The search term.
|
|
142
|
+
* @param searchOptions Search options.
|
|
143
|
+
* @return Whether a result was found.
|
|
144
|
+
*/
|
|
145
|
+
}, {
|
|
146
|
+
key: "findNext",
|
|
147
|
+
value: function findNext(term, searchOptions) {
|
|
148
|
+
if (!this._terminal) {
|
|
149
|
+
throw new Error('Cannot use addon until it has been loaded');
|
|
150
|
+
}
|
|
151
|
+
this._lastSearchOptions = searchOptions;
|
|
152
|
+
if (searchOptions !== null && searchOptions !== void 0 && searchOptions.decorations) {
|
|
153
|
+
if (this._resultIndex !== undefined || this._cachedSearchTerm === undefined || term !== this._cachedSearchTerm) {
|
|
154
|
+
this._highlightAllMatches(term, searchOptions);
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
return this._fireResults(term, this._findNextAndSelect(term, searchOptions), searchOptions);
|
|
158
|
+
}
|
|
159
|
+
}, {
|
|
160
|
+
key: "_highlightAllMatches",
|
|
161
|
+
value: function _highlightAllMatches(term, searchOptions) {
|
|
162
|
+
var _this3 = this;
|
|
163
|
+
if (!this._terminal) {
|
|
164
|
+
throw new Error('Cannot use addon until it has been loaded');
|
|
165
|
+
}
|
|
166
|
+
if (!term || term.length === 0) {
|
|
167
|
+
this.clearDecorations();
|
|
168
|
+
return;
|
|
169
|
+
}
|
|
170
|
+
searchOptions = searchOptions || {};
|
|
171
|
+
|
|
172
|
+
// new search, clear out the old decorations
|
|
173
|
+
this.clearDecorations(true);
|
|
174
|
+
this._searchResults = new Map();
|
|
175
|
+
this._resultDecorations = new Map();
|
|
176
|
+
var resultDecorations = this._resultDecorations;
|
|
177
|
+
var result = this._find(term, 0, 0, searchOptions);
|
|
178
|
+
while (result && !this._searchResults.get("".concat(result.row, "-").concat(result.col))) {
|
|
179
|
+
this._searchResults.set("".concat(result.row, "-").concat(result.col), result);
|
|
180
|
+
result = this._find(term, result.col + result.term.length >= this._terminal.cols ? result.row + 1 : result.row, result.col + result.term.length >= this._terminal.cols ? 0 : result.col + 1, searchOptions);
|
|
181
|
+
if (this._searchResults.size >= 1000) {
|
|
182
|
+
// this.clearDecorations();
|
|
183
|
+
// this._resultIndex = undefined;
|
|
184
|
+
return;
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
this._searchResults.forEach(function (r) {
|
|
188
|
+
var resultDecoration = _this3._createResultDecoration(r, searchOptions.decorations);
|
|
189
|
+
if (resultDecoration) {
|
|
190
|
+
var decorationsForLine = resultDecorations.get(resultDecoration.marker.line) || [];
|
|
191
|
+
decorationsForLine.push(resultDecoration);
|
|
192
|
+
resultDecorations.set(resultDecoration.marker.line, decorationsForLine);
|
|
193
|
+
}
|
|
194
|
+
});
|
|
195
|
+
}
|
|
196
|
+
}, {
|
|
197
|
+
key: "_find",
|
|
198
|
+
value: function _find(term, startRow, startCol, searchOptions) {
|
|
199
|
+
if (!this._terminal || !term || term.length === 0) {
|
|
200
|
+
var _this$_terminal;
|
|
201
|
+
(_this$_terminal = this._terminal) === null || _this$_terminal === void 0 || _this$_terminal.clearSelection();
|
|
202
|
+
this.clearDecorations();
|
|
203
|
+
return undefined;
|
|
204
|
+
}
|
|
205
|
+
if (startCol > this._terminal.cols) {
|
|
206
|
+
throw new Error("Invalid col: ".concat(startCol, " to search in terminal of ").concat(this._terminal.cols, " cols"));
|
|
207
|
+
}
|
|
208
|
+
var result;
|
|
209
|
+
this._initLinesCache();
|
|
210
|
+
var searchPosition = {
|
|
211
|
+
startRow: startRow,
|
|
212
|
+
startCol: startCol
|
|
213
|
+
};
|
|
214
|
+
|
|
215
|
+
// Search startRow
|
|
216
|
+
result = this._findInLine(term, searchPosition, searchOptions);
|
|
217
|
+
// Search from startRow + 1 to end
|
|
218
|
+
if (!result) {
|
|
219
|
+
for (var y = startRow + 1; y < this._terminal.buffer.active.baseY + this._terminal.rows; y++) {
|
|
220
|
+
searchPosition.startRow = y;
|
|
221
|
+
searchPosition.startCol = 0;
|
|
222
|
+
// If the current line is wrapped line, increase index of column to ignore the previous scan
|
|
223
|
+
// Otherwise, reset beginning column index to zero with set new unwrapped line index
|
|
224
|
+
result = this._findInLine(term, searchPosition, searchOptions);
|
|
225
|
+
if (result) {
|
|
226
|
+
break;
|
|
227
|
+
}
|
|
228
|
+
}
|
|
229
|
+
}
|
|
230
|
+
return result;
|
|
231
|
+
}
|
|
232
|
+
}, {
|
|
233
|
+
key: "_findNextAndSelect",
|
|
234
|
+
value: function _findNextAndSelect(term, searchOptions) {
|
|
235
|
+
if (!this._terminal || !term || term.length === 0) {
|
|
236
|
+
var _this$_terminal2;
|
|
237
|
+
(_this$_terminal2 = this._terminal) === null || _this$_terminal2 === void 0 || _this$_terminal2.clearSelection();
|
|
238
|
+
this.clearDecorations();
|
|
239
|
+
this._cachedSearchTerm = undefined;
|
|
240
|
+
this._resultIndex = -1;
|
|
241
|
+
return false;
|
|
242
|
+
}
|
|
243
|
+
if (this._cachedSearchTerm !== term) {
|
|
244
|
+
this._resultIndex = undefined;
|
|
245
|
+
this._terminal.clearSelection();
|
|
246
|
+
}
|
|
247
|
+
var startCol = 0;
|
|
248
|
+
var startRow = 0;
|
|
249
|
+
var currentSelection;
|
|
250
|
+
if (this._terminal.hasSelection()) {
|
|
251
|
+
var incremental = searchOptions ? searchOptions.incremental : false;
|
|
252
|
+
// Start from the selection end if there is a selection
|
|
253
|
+
// For incremental search, use existing row
|
|
254
|
+
currentSelection = this._terminal.getSelectionPosition();
|
|
255
|
+
startRow = incremental ? currentSelection.start.y : currentSelection.end.y;
|
|
256
|
+
startCol = incremental ? currentSelection.start.x : currentSelection.end.x;
|
|
257
|
+
}
|
|
258
|
+
this._initLinesCache();
|
|
259
|
+
var searchPosition = {
|
|
260
|
+
startRow: startRow,
|
|
261
|
+
startCol: startCol
|
|
262
|
+
};
|
|
263
|
+
|
|
264
|
+
// Search startRow
|
|
265
|
+
var result = this._findInLine(term, searchPosition, searchOptions);
|
|
266
|
+
// Search from startRow + 1 to end
|
|
267
|
+
if (!result) {
|
|
268
|
+
for (var y = startRow + 1; y < this._terminal.buffer.active.baseY + this._terminal.rows; y++) {
|
|
269
|
+
searchPosition.startRow = y;
|
|
270
|
+
searchPosition.startCol = 0;
|
|
271
|
+
// If the current line is wrapped line, increase index of column to ignore the previous scan
|
|
272
|
+
// Otherwise, reset beginning column index to zero with set new unwrapped line index
|
|
273
|
+
result = this._findInLine(term, searchPosition, searchOptions);
|
|
274
|
+
if (result) {
|
|
275
|
+
break;
|
|
276
|
+
}
|
|
277
|
+
}
|
|
278
|
+
}
|
|
279
|
+
// If we hit the bottom and didn't search from the very top wrap back up
|
|
280
|
+
if (!result && startRow !== 0) {
|
|
281
|
+
for (var _y = 0; _y < startRow; _y++) {
|
|
282
|
+
searchPosition.startRow = _y;
|
|
283
|
+
searchPosition.startCol = 0;
|
|
284
|
+
result = this._findInLine(term, searchPosition, searchOptions);
|
|
285
|
+
if (result) {
|
|
286
|
+
break;
|
|
287
|
+
}
|
|
288
|
+
}
|
|
289
|
+
}
|
|
290
|
+
|
|
291
|
+
// If there is only one result, wrap back and return selection if it exists.
|
|
292
|
+
if (!result && currentSelection) {
|
|
293
|
+
searchPosition.startRow = currentSelection.start.y;
|
|
294
|
+
searchPosition.startCol = 0;
|
|
295
|
+
result = this._findInLine(term, searchPosition, searchOptions);
|
|
296
|
+
}
|
|
297
|
+
if (this._searchResults) {
|
|
298
|
+
if (this._searchResults.size === 0) {
|
|
299
|
+
this._resultIndex = -1;
|
|
300
|
+
} else if (this._resultIndex === undefined) {
|
|
301
|
+
this._resultIndex = 0;
|
|
302
|
+
} else {
|
|
303
|
+
this._resultIndex++;
|
|
304
|
+
if (this._resultIndex >= this._searchResults.size) {
|
|
305
|
+
this._resultIndex = 0;
|
|
306
|
+
}
|
|
307
|
+
}
|
|
308
|
+
}
|
|
309
|
+
// Set selection and scroll if a result was found
|
|
310
|
+
return this._selectResult(result, searchOptions === null || searchOptions === void 0 ? void 0 : searchOptions.decorations, searchOptions === null || searchOptions === void 0 ? void 0 : searchOptions.noScroll);
|
|
311
|
+
}
|
|
312
|
+
|
|
313
|
+
/**
|
|
314
|
+
* Find the previous instance of the term, then scroll to and select it. If it
|
|
315
|
+
* doesn't exist, do nothing.
|
|
316
|
+
* @param term The search term.
|
|
317
|
+
* @param searchOptions Search options.
|
|
318
|
+
* @return Whether a result was found.
|
|
319
|
+
*/
|
|
320
|
+
}, {
|
|
321
|
+
key: "findPrevious",
|
|
322
|
+
value: function findPrevious(term, searchOptions) {
|
|
323
|
+
if (!this._terminal) {
|
|
324
|
+
throw new Error('Cannot use addon until it has been loaded');
|
|
325
|
+
}
|
|
326
|
+
this._lastSearchOptions = searchOptions;
|
|
327
|
+
if (searchOptions !== null && searchOptions !== void 0 && searchOptions.decorations) {
|
|
328
|
+
if (this._resultIndex !== undefined || this._cachedSearchTerm === undefined || term !== this._cachedSearchTerm) {
|
|
329
|
+
this._highlightAllMatches(term, searchOptions);
|
|
330
|
+
}
|
|
331
|
+
}
|
|
332
|
+
return this._fireResults(term, this._findPreviousAndSelect(term, searchOptions), searchOptions);
|
|
333
|
+
}
|
|
334
|
+
}, {
|
|
335
|
+
key: "_fireResults",
|
|
336
|
+
value: function _fireResults(term, found, searchOptions) {
|
|
337
|
+
if (searchOptions !== null && searchOptions !== void 0 && searchOptions.decorations) {
|
|
338
|
+
var _this$_searchResults2;
|
|
339
|
+
if (this._resultIndex !== undefined && ((_this$_searchResults2 = this._searchResults) === null || _this$_searchResults2 === void 0 ? void 0 : _this$_searchResults2.size) !== undefined) {
|
|
340
|
+
this._onDidChangeResults.fire({
|
|
341
|
+
resultIndex: this._resultIndex,
|
|
342
|
+
resultCount: this._searchResults.size
|
|
343
|
+
});
|
|
344
|
+
} else {
|
|
345
|
+
this._onDidChangeResults.fire(undefined);
|
|
346
|
+
}
|
|
347
|
+
}
|
|
348
|
+
this._cachedSearchTerm = term;
|
|
349
|
+
return found;
|
|
350
|
+
}
|
|
351
|
+
}, {
|
|
352
|
+
key: "_findPreviousAndSelect",
|
|
353
|
+
value: function _findPreviousAndSelect(term, searchOptions) {
|
|
354
|
+
if (!this._terminal) {
|
|
355
|
+
throw new Error('Cannot use addon until it has been loaded');
|
|
356
|
+
}
|
|
357
|
+
var result;
|
|
358
|
+
if (!this._terminal || !term || term.length === 0) {
|
|
359
|
+
var _this$_terminal3;
|
|
360
|
+
result = undefined;
|
|
361
|
+
(_this$_terminal3 = this._terminal) === null || _this$_terminal3 === void 0 || _this$_terminal3.clearSelection();
|
|
362
|
+
this.clearDecorations();
|
|
363
|
+
this._resultIndex = -1;
|
|
364
|
+
return false;
|
|
365
|
+
}
|
|
366
|
+
if (this._cachedSearchTerm !== term) {
|
|
367
|
+
this._resultIndex = undefined;
|
|
368
|
+
this._terminal.clearSelection();
|
|
369
|
+
}
|
|
370
|
+
var startRow = this._terminal.buffer.active.baseY + this._terminal.rows;
|
|
371
|
+
var startCol = this._terminal.cols;
|
|
372
|
+
var isReverseSearch = true;
|
|
373
|
+
var incremental = searchOptions ? searchOptions.incremental : false;
|
|
374
|
+
var currentSelection;
|
|
375
|
+
if (this._terminal.hasSelection()) {
|
|
376
|
+
currentSelection = this._terminal.getSelectionPosition();
|
|
377
|
+
// Start from selection start if there is a selection
|
|
378
|
+
startRow = currentSelection.start.y;
|
|
379
|
+
startCol = currentSelection.start.x;
|
|
380
|
+
}
|
|
381
|
+
this._initLinesCache();
|
|
382
|
+
var searchPosition = {
|
|
383
|
+
startRow: startRow,
|
|
384
|
+
startCol: startCol
|
|
385
|
+
};
|
|
386
|
+
if (incremental) {
|
|
387
|
+
// Try to expand selection to right first.
|
|
388
|
+
result = this._findInLine(term, searchPosition, searchOptions, false);
|
|
389
|
+
var isOldResultHighlighted = result && result.row === startRow && result.col === startCol;
|
|
390
|
+
if (!isOldResultHighlighted) {
|
|
391
|
+
// If selection was not able to be expanded to the right, then try reverse search
|
|
392
|
+
if (currentSelection) {
|
|
393
|
+
searchPosition.startRow = currentSelection.end.y;
|
|
394
|
+
searchPosition.startCol = currentSelection.end.x;
|
|
395
|
+
}
|
|
396
|
+
result = this._findInLine(term, searchPosition, searchOptions, true);
|
|
397
|
+
}
|
|
398
|
+
} else {
|
|
399
|
+
result = this._findInLine(term, searchPosition, searchOptions, isReverseSearch);
|
|
400
|
+
}
|
|
401
|
+
|
|
402
|
+
// Search from startRow - 1 to top
|
|
403
|
+
if (!result) {
|
|
404
|
+
searchPosition.startCol = Math.max(searchPosition.startCol, this._terminal.cols);
|
|
405
|
+
for (var y = startRow - 1; y >= 0; y--) {
|
|
406
|
+
searchPosition.startRow = y;
|
|
407
|
+
result = this._findInLine(term, searchPosition, searchOptions, isReverseSearch);
|
|
408
|
+
if (result) {
|
|
409
|
+
break;
|
|
410
|
+
}
|
|
411
|
+
}
|
|
412
|
+
}
|
|
413
|
+
// If we hit the top and didn't search from the very bottom wrap back down
|
|
414
|
+
if (!result && startRow !== this._terminal.buffer.active.baseY + this._terminal.rows) {
|
|
415
|
+
for (var _y2 = this._terminal.buffer.active.baseY + this._terminal.rows; _y2 >= startRow; _y2--) {
|
|
416
|
+
searchPosition.startRow = _y2;
|
|
417
|
+
result = this._findInLine(term, searchPosition, searchOptions, isReverseSearch);
|
|
418
|
+
if (result) {
|
|
419
|
+
break;
|
|
420
|
+
}
|
|
421
|
+
}
|
|
422
|
+
}
|
|
423
|
+
if (this._searchResults) {
|
|
424
|
+
if (this._searchResults.size === 0) {
|
|
425
|
+
this._resultIndex = -1;
|
|
426
|
+
} else if (this._resultIndex === undefined || this._resultIndex < 0) {
|
|
427
|
+
this._resultIndex = this._searchResults.size - 1;
|
|
428
|
+
} else {
|
|
429
|
+
this._resultIndex--;
|
|
430
|
+
if (this._resultIndex === -1) {
|
|
431
|
+
this._resultIndex = this._searchResults.size - 1;
|
|
432
|
+
}
|
|
433
|
+
}
|
|
434
|
+
}
|
|
435
|
+
|
|
436
|
+
// If there is only one result, return true.
|
|
437
|
+
if (!result && currentSelection) return true;
|
|
438
|
+
|
|
439
|
+
// Set selection and scroll if a result was found
|
|
440
|
+
return this._selectResult(result, searchOptions === null || searchOptions === void 0 ? void 0 : searchOptions.decorations, searchOptions === null || searchOptions === void 0 ? void 0 : searchOptions.noScroll);
|
|
441
|
+
}
|
|
442
|
+
|
|
443
|
+
/**
|
|
444
|
+
* Sets up a line cache with a ttl
|
|
445
|
+
*/
|
|
446
|
+
}, {
|
|
447
|
+
key: "_initLinesCache",
|
|
448
|
+
value: function _initLinesCache() {
|
|
449
|
+
var _this4 = this;
|
|
450
|
+
var terminal = this._terminal;
|
|
451
|
+
if (!this._linesCache) {
|
|
452
|
+
this._linesCache = new Array(terminal.buffer.active.length);
|
|
453
|
+
this._cursorMoveListener = terminal.onCursorMove(function () {
|
|
454
|
+
return _this4._destroyLinesCache();
|
|
455
|
+
});
|
|
456
|
+
this._resizeListener = terminal.onResize(function () {
|
|
457
|
+
return _this4._destroyLinesCache();
|
|
458
|
+
});
|
|
459
|
+
}
|
|
460
|
+
window.clearTimeout(this._linesCacheTimeoutId);
|
|
461
|
+
this._linesCacheTimeoutId = window.setTimeout(function () {
|
|
462
|
+
return _this4._destroyLinesCache();
|
|
463
|
+
}, LINES_CACHE_TIME_TO_LIVE);
|
|
464
|
+
}
|
|
465
|
+
}, {
|
|
466
|
+
key: "_destroyLinesCache",
|
|
467
|
+
value: function _destroyLinesCache() {
|
|
468
|
+
this._linesCache = undefined;
|
|
469
|
+
if (this._cursorMoveListener) {
|
|
470
|
+
this._cursorMoveListener.dispose();
|
|
471
|
+
this._cursorMoveListener = undefined;
|
|
472
|
+
}
|
|
473
|
+
if (this._resizeListener) {
|
|
474
|
+
this._resizeListener.dispose();
|
|
475
|
+
this._resizeListener = undefined;
|
|
476
|
+
}
|
|
477
|
+
if (this._linesCacheTimeoutId) {
|
|
478
|
+
window.clearTimeout(this._linesCacheTimeoutId);
|
|
479
|
+
this._linesCacheTimeoutId = 0;
|
|
480
|
+
}
|
|
481
|
+
}
|
|
482
|
+
|
|
483
|
+
/**
|
|
484
|
+
* A found substring is a whole word if it doesn't have an alphanumeric character directly adjacent to it.
|
|
485
|
+
* @param searchIndex starting indext of the potential whole word substring
|
|
486
|
+
* @param line entire string in which the potential whole word was found
|
|
487
|
+
* @param term the substring that starts at searchIndex
|
|
488
|
+
*/
|
|
489
|
+
}, {
|
|
490
|
+
key: "_isWholeWord",
|
|
491
|
+
value: function _isWholeWord(searchIndex, line, term) {
|
|
492
|
+
return (searchIndex === 0 || NON_WORD_CHARACTERS.includes(line[searchIndex - 1])) && (searchIndex + term.length === line.length || NON_WORD_CHARACTERS.includes(line[searchIndex + term.length]));
|
|
493
|
+
}
|
|
494
|
+
|
|
495
|
+
/**
|
|
496
|
+
* Searches a line for a search term. Takes the provided terminal line and searches the text line, which may contain
|
|
497
|
+
* subsequent terminal lines if the text is wrapped. If the provided line number is part of a wrapped text line that
|
|
498
|
+
* started on an earlier line then it is skipped since it will be properly searched when the terminal line that the
|
|
499
|
+
* text starts on is searched.
|
|
500
|
+
* @param term The search term.
|
|
501
|
+
* @param position The position to start the search.
|
|
502
|
+
* @param searchOptions Search options.
|
|
503
|
+
* @param isReverseSearch Whether the search should start from the right side of the terminal and search to the left.
|
|
504
|
+
* @return The search result if it was found.
|
|
505
|
+
*/
|
|
506
|
+
}, {
|
|
507
|
+
key: "_findInLine",
|
|
508
|
+
value: function _findInLine(term, searchPosition) {
|
|
509
|
+
var _this$_linesCache;
|
|
510
|
+
var searchOptions = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
|
|
511
|
+
var isReverseSearch = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : false;
|
|
512
|
+
var terminal = this._terminal;
|
|
513
|
+
var row = searchPosition.startRow;
|
|
514
|
+
var col = searchPosition.startCol;
|
|
515
|
+
|
|
516
|
+
// Ignore wrapped lines, only consider on unwrapped line (first row of command string).
|
|
517
|
+
var firstLine = terminal.buffer.active.getLine(row);
|
|
518
|
+
if (firstLine !== null && firstLine !== void 0 && firstLine.isWrapped) {
|
|
519
|
+
if (isReverseSearch) {
|
|
520
|
+
searchPosition.startCol += terminal.cols;
|
|
521
|
+
return;
|
|
522
|
+
}
|
|
523
|
+
|
|
524
|
+
// This will iterate until we find the line start.
|
|
525
|
+
// When we find it, we will search using the calculated start column.
|
|
526
|
+
searchPosition.startRow--;
|
|
527
|
+
searchPosition.startCol += terminal.cols;
|
|
528
|
+
return this._findInLine(term, searchPosition, searchOptions);
|
|
529
|
+
}
|
|
530
|
+
var cache = (_this$_linesCache = this._linesCache) === null || _this$_linesCache === void 0 ? void 0 : _this$_linesCache[row];
|
|
531
|
+
if (!cache) {
|
|
532
|
+
cache = this._translateBufferLineToStringWithWrap(row, true);
|
|
533
|
+
if (this._linesCache) {
|
|
534
|
+
this._linesCache[row] = cache;
|
|
535
|
+
}
|
|
536
|
+
}
|
|
537
|
+
var _cache = cache,
|
|
538
|
+
_cache2 = _slicedToArray(_cache, 2),
|
|
539
|
+
stringLine = _cache2[0],
|
|
540
|
+
offsets = _cache2[1];
|
|
541
|
+
var offset = this._bufferColsToStringOffset(row, col);
|
|
542
|
+
var searchTerm = searchOptions.caseSensitive ? term : term.toLowerCase();
|
|
543
|
+
var searchStringLine = searchOptions.caseSensitive ? stringLine : stringLine.toLowerCase();
|
|
544
|
+
var resultIndex = -1;
|
|
545
|
+
if (searchOptions.regex) {
|
|
546
|
+
var searchRegex = RegExp(searchTerm, 'g');
|
|
547
|
+
var foundTerm;
|
|
548
|
+
if (isReverseSearch) {
|
|
549
|
+
// This loop will get the resultIndex of the _last_ regex match in the range 0..offset
|
|
550
|
+
while (foundTerm = searchRegex.exec(searchStringLine.slice(0, offset))) {
|
|
551
|
+
resultIndex = searchRegex.lastIndex - foundTerm[0].length;
|
|
552
|
+
term = foundTerm[0];
|
|
553
|
+
searchRegex.lastIndex -= term.length - 1;
|
|
554
|
+
}
|
|
555
|
+
} else {
|
|
556
|
+
foundTerm = searchRegex.exec(searchStringLine.slice(offset));
|
|
557
|
+
if (foundTerm && foundTerm[0].length > 0) {
|
|
558
|
+
resultIndex = offset + (searchRegex.lastIndex - foundTerm[0].length);
|
|
559
|
+
term = foundTerm[0];
|
|
560
|
+
}
|
|
561
|
+
}
|
|
562
|
+
} else if (isReverseSearch) {
|
|
563
|
+
if (offset - searchTerm.length >= 0) {
|
|
564
|
+
resultIndex = searchStringLine.lastIndexOf(searchTerm, offset - searchTerm.length);
|
|
565
|
+
}
|
|
566
|
+
} else {
|
|
567
|
+
resultIndex = searchStringLine.indexOf(searchTerm, offset);
|
|
568
|
+
}
|
|
569
|
+
if (resultIndex >= 0) {
|
|
570
|
+
if (searchOptions.wholeWord && !this._isWholeWord(resultIndex, searchStringLine, term)) {
|
|
571
|
+
return;
|
|
572
|
+
}
|
|
573
|
+
|
|
574
|
+
// Adjust the row number and search index if needed since a "line" of text can span multiple rows
|
|
575
|
+
var startRowOffset = 0;
|
|
576
|
+
while (startRowOffset < offsets.length - 1 && resultIndex >= offsets[startRowOffset + 1]) {
|
|
577
|
+
startRowOffset++;
|
|
578
|
+
}
|
|
579
|
+
var endRowOffset = startRowOffset;
|
|
580
|
+
while (endRowOffset < offsets.length - 1 && resultIndex + term.length >= offsets[endRowOffset + 1]) {
|
|
581
|
+
endRowOffset++;
|
|
582
|
+
}
|
|
583
|
+
var startColOffset = resultIndex - offsets[startRowOffset];
|
|
584
|
+
var endColOffset = resultIndex + term.length - offsets[endRowOffset];
|
|
585
|
+
var startColIndex = this._stringLengthToBufferSize(row + startRowOffset, startColOffset);
|
|
586
|
+
var endColIndex = this._stringLengthToBufferSize(row + endRowOffset, endColOffset);
|
|
587
|
+
var size = endColIndex - startColIndex + terminal.cols * (endRowOffset - startRowOffset);
|
|
588
|
+
return {
|
|
589
|
+
term: term,
|
|
590
|
+
col: startColIndex,
|
|
591
|
+
row: row + startRowOffset,
|
|
592
|
+
size: size
|
|
593
|
+
};
|
|
594
|
+
}
|
|
595
|
+
}
|
|
596
|
+
}, {
|
|
597
|
+
key: "_stringLengthToBufferSize",
|
|
598
|
+
value: function _stringLengthToBufferSize(row, offset) {
|
|
599
|
+
var line = this._terminal.buffer.active.getLine(row);
|
|
600
|
+
if (!line) {
|
|
601
|
+
return 0;
|
|
602
|
+
}
|
|
603
|
+
for (var i = 0; i < offset; i++) {
|
|
604
|
+
var cell = line.getCell(i);
|
|
605
|
+
if (!cell) {
|
|
606
|
+
break;
|
|
607
|
+
}
|
|
608
|
+
// Adjust the searchIndex to normalize emoji into single chars
|
|
609
|
+
var char = cell.getChars();
|
|
610
|
+
if (char.length > 1) {
|
|
611
|
+
offset -= char.length - 1;
|
|
612
|
+
}
|
|
613
|
+
// Adjust the searchIndex for empty characters following wide unicode
|
|
614
|
+
// chars (eg. CJK)
|
|
615
|
+
var nextCell = line.getCell(i + 1);
|
|
616
|
+
if (nextCell && nextCell.getWidth() === 0) {
|
|
617
|
+
offset++;
|
|
618
|
+
}
|
|
619
|
+
}
|
|
620
|
+
return offset;
|
|
621
|
+
}
|
|
622
|
+
}, {
|
|
623
|
+
key: "_bufferColsToStringOffset",
|
|
624
|
+
value: function _bufferColsToStringOffset(startRow, cols) {
|
|
625
|
+
var terminal = this._terminal;
|
|
626
|
+
var lineIndex = startRow;
|
|
627
|
+
var offset = 0;
|
|
628
|
+
var line = terminal.buffer.active.getLine(lineIndex);
|
|
629
|
+
while (cols > 0 && line) {
|
|
630
|
+
for (var i = 0; i < cols && i < terminal.cols; i++) {
|
|
631
|
+
var cell = line.getCell(i);
|
|
632
|
+
if (!cell) {
|
|
633
|
+
break;
|
|
634
|
+
}
|
|
635
|
+
if (cell.getWidth()) {
|
|
636
|
+
// Treat null characters as whitespace to align with the translateToString API
|
|
637
|
+
offset += cell.getCode() === 0 ? 1 : cell.getChars().length;
|
|
638
|
+
}
|
|
639
|
+
}
|
|
640
|
+
lineIndex++;
|
|
641
|
+
line = terminal.buffer.active.getLine(lineIndex);
|
|
642
|
+
if (line && !line.isWrapped) {
|
|
643
|
+
break;
|
|
644
|
+
}
|
|
645
|
+
cols -= terminal.cols;
|
|
646
|
+
}
|
|
647
|
+
return offset;
|
|
648
|
+
}
|
|
649
|
+
|
|
650
|
+
/**
|
|
651
|
+
* Translates a buffer line to a string, including subsequent lines if they are wraps.
|
|
652
|
+
* Wide characters will count as two columns in the resulting string. This
|
|
653
|
+
* function is useful for getting the actual text underneath the raw selection
|
|
654
|
+
* position.
|
|
655
|
+
* @param line The line being translated.
|
|
656
|
+
* @param trimRight Whether to trim whitespace to the right.
|
|
657
|
+
*/
|
|
658
|
+
}, {
|
|
659
|
+
key: "_translateBufferLineToStringWithWrap",
|
|
660
|
+
value: function _translateBufferLineToStringWithWrap(lineIndex, trimRight) {
|
|
661
|
+
var terminal = this._terminal;
|
|
662
|
+
var strings = [];
|
|
663
|
+
var lineOffsets = [0];
|
|
664
|
+
var line = terminal.buffer.active.getLine(lineIndex);
|
|
665
|
+
while (line) {
|
|
666
|
+
var nextLine = terminal.buffer.active.getLine(lineIndex + 1);
|
|
667
|
+
var lineWrapsToNext = nextLine ? nextLine.isWrapped : false;
|
|
668
|
+
var string = line.translateToString(!lineWrapsToNext && trimRight);
|
|
669
|
+
if (lineWrapsToNext && nextLine) {
|
|
670
|
+
var _nextLine$getCell;
|
|
671
|
+
var lastCell = line.getCell(line.length - 1);
|
|
672
|
+
var lastCellIsNull = lastCell && lastCell.getCode() === 0 && lastCell.getWidth() === 1;
|
|
673
|
+
// a wide character wrapped to the next line
|
|
674
|
+
if (lastCellIsNull && ((_nextLine$getCell = nextLine.getCell(0)) === null || _nextLine$getCell === void 0 ? void 0 : _nextLine$getCell.getWidth()) === 2) {
|
|
675
|
+
string = string.slice(0, -1);
|
|
676
|
+
}
|
|
677
|
+
}
|
|
678
|
+
strings.push(string);
|
|
679
|
+
if (lineWrapsToNext) {
|
|
680
|
+
lineOffsets.push(lineOffsets[lineOffsets.length - 1] + string.length);
|
|
681
|
+
} else {
|
|
682
|
+
break;
|
|
683
|
+
}
|
|
684
|
+
lineIndex++;
|
|
685
|
+
line = nextLine;
|
|
686
|
+
}
|
|
687
|
+
return [strings.join(''), lineOffsets];
|
|
688
|
+
}
|
|
689
|
+
|
|
690
|
+
/**
|
|
691
|
+
* Selects and scrolls to a result.
|
|
692
|
+
* @param result The result to select.
|
|
693
|
+
* @return Whether a result was selected.
|
|
694
|
+
*/
|
|
695
|
+
}, {
|
|
696
|
+
key: "_selectResult",
|
|
697
|
+
value: function _selectResult(result, options, noScroll) {
|
|
698
|
+
var terminal = this._terminal;
|
|
699
|
+
this.clearActiveDecoration();
|
|
700
|
+
if (!result) {
|
|
701
|
+
terminal.clearSelection();
|
|
702
|
+
return false;
|
|
703
|
+
}
|
|
704
|
+
terminal.select(result.col, result.row, result.size);
|
|
705
|
+
if (options) {
|
|
706
|
+
var marker = terminal.registerMarker(-terminal.buffer.active.baseY - terminal.buffer.active.cursorY + result.row);
|
|
707
|
+
if (marker) {
|
|
708
|
+
var _this$_selectedDecora3;
|
|
709
|
+
this._selectedDecoration = terminal.registerDecoration({
|
|
710
|
+
marker: marker,
|
|
711
|
+
x: result.col,
|
|
712
|
+
width: result.size,
|
|
713
|
+
backgroundColor: options.activeMatchBackground,
|
|
714
|
+
foregroundColor: options === null || options === void 0 ? void 0 : options.matchForegroundColor,
|
|
715
|
+
layer: 'top',
|
|
716
|
+
overviewRulerOptions: {
|
|
717
|
+
color: options.activeMatchColorOverviewRuler
|
|
718
|
+
}
|
|
719
|
+
});
|
|
720
|
+
// this._selectedDecoration?.onRender((e) => {
|
|
721
|
+
// this._applyStyles(e, options.activeMatchBorder, true);
|
|
722
|
+
// });
|
|
723
|
+
(_this$_selectedDecora3 = this._selectedDecoration) === null || _this$_selectedDecora3 === void 0 || _this$_selectedDecora3.onDispose(function () {
|
|
724
|
+
marker.dispose();
|
|
725
|
+
});
|
|
726
|
+
}
|
|
727
|
+
}
|
|
728
|
+
if (!noScroll) {
|
|
729
|
+
// If it is not in the viewport then we scroll else it just gets selected
|
|
730
|
+
if (result.row >= terminal.buffer.active.viewportY + terminal.rows || result.row < terminal.buffer.active.viewportY) {
|
|
731
|
+
var scroll = result.row - terminal.buffer.active.viewportY;
|
|
732
|
+
scroll -= Math.floor(terminal.rows / 2);
|
|
733
|
+
terminal.scrollLines(scroll);
|
|
734
|
+
}
|
|
735
|
+
}
|
|
736
|
+
return true;
|
|
737
|
+
}
|
|
738
|
+
|
|
739
|
+
/**
|
|
740
|
+
* Applies styles to the decoration when it is rendered
|
|
741
|
+
* @param element the decoration's element
|
|
742
|
+
* @param backgroundColor the background color to apply
|
|
743
|
+
* @param borderColor the border color to apply
|
|
744
|
+
* @returns
|
|
745
|
+
*/
|
|
746
|
+
}, {
|
|
747
|
+
key: "_applyStyles",
|
|
748
|
+
value: function _applyStyles(element, borderColor, isActiveResult) {
|
|
749
|
+
if (element.clientWidth <= 0) {
|
|
750
|
+
return;
|
|
751
|
+
}
|
|
752
|
+
if (!element.classList.contains('xterm-find-result-decoration')) {
|
|
753
|
+
element.classList.add('xterm-find-result-decoration');
|
|
754
|
+
if (borderColor) {
|
|
755
|
+
element.style.outline = "1px solid ".concat(borderColor);
|
|
756
|
+
}
|
|
757
|
+
}
|
|
758
|
+
if (isActiveResult) {
|
|
759
|
+
element.classList.add('xterm-find-active-result-decoration');
|
|
760
|
+
}
|
|
761
|
+
}
|
|
762
|
+
|
|
763
|
+
/**
|
|
764
|
+
* Creates a decoration for the result and applies styles
|
|
765
|
+
* @param result the search result for which to create the decoration
|
|
766
|
+
* @param options the options for the decoration
|
|
767
|
+
* @returns the {@link IDecoration} or undefined if the marker has already been disposed of
|
|
768
|
+
*/
|
|
769
|
+
}, {
|
|
770
|
+
key: "_createResultDecoration",
|
|
771
|
+
value: function _createResultDecoration(result, options) {
|
|
772
|
+
var _this$_resultDecorati3;
|
|
773
|
+
var terminal = this._terminal;
|
|
774
|
+
var marker = terminal.registerMarker(-terminal.buffer.active.baseY - terminal.buffer.active.cursorY + result.row);
|
|
775
|
+
if (!marker) {
|
|
776
|
+
return undefined;
|
|
777
|
+
}
|
|
778
|
+
var findResultDecoration = terminal.registerDecoration({
|
|
779
|
+
marker: marker,
|
|
780
|
+
x: result.col,
|
|
781
|
+
width: result.size,
|
|
782
|
+
foregroundColor: options.matchForegroundColor,
|
|
783
|
+
backgroundColor: options.matchBackground,
|
|
784
|
+
overviewRulerOptions: (_this$_resultDecorati3 = this._resultDecorations) !== null && _this$_resultDecorati3 !== void 0 && _this$_resultDecorati3.get(marker.line) ? undefined : {
|
|
785
|
+
color: options.matchOverviewRuler,
|
|
786
|
+
position: 'center'
|
|
787
|
+
}
|
|
788
|
+
});
|
|
789
|
+
// findResultDecoration?.onRender((e) => this._applyStyles(e, options.matchBorder, false));
|
|
790
|
+
findResultDecoration === null || findResultDecoration === void 0 || findResultDecoration.onDispose(function () {
|
|
791
|
+
return marker.dispose();
|
|
792
|
+
});
|
|
793
|
+
return findResultDecoration;
|
|
794
|
+
}
|
|
795
|
+
}]);
|
|
796
|
+
return SearchAddon;
|
|
797
|
+
}();
|